From 7b1ee6468d612131136dc17ffd385d3f5bc47116 Mon Sep 17 00:00:00 2001 From: cutealien Date: Mon, 10 Feb 2020 15:01:11 +0000 Subject: [PATCH] Added 'uint' GLSL uniform support. Thanks @devsh for the patch. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6073 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IMaterialRendererServices.h | 8 ++++ source/Irrlicht/CD3D9Driver.cpp | 27 +++++++++++ source/Irrlicht/CD3D9Driver.h | 6 +++ source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp | 8 ++++ source/Irrlicht/CD3D9HLSLMaterialRenderer.h | 3 ++ source/Irrlicht/CD3D9MaterialRenderer.h | 7 +++ source/Irrlicht/COpenGLDriver.cpp | 16 +++++-- source/Irrlicht/COpenGLDriver.h | 6 +++ source/Irrlicht/COpenGLExtensionHandler.cpp | 5 ++ source/Irrlicht/COpenGLExtensionHandler.h | 48 +++++++++++++++++++ source/Irrlicht/COpenGLSLMaterialRenderer.cpp | 41 ++++++++++++---- source/Irrlicht/COpenGLSLMaterialRenderer.h | 2 + tests/tests-last-passed-at.txt | 8 ++-- 13 files changed, 169 insertions(+), 16 deletions(-) diff --git a/include/IMaterialRendererServices.h b/include/IMaterialRendererServices.h index 0c18535f..3d36ad32 100644 --- a/include/IMaterialRendererServices.h +++ b/include/IMaterialRendererServices.h @@ -71,6 +71,10 @@ public: //! Int interface for the above. virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count) = 0; + //! Uint interface for the above. + /* NOTE: UINT only works with GLSL, not supported for other shaders */ + virtual bool setVertexShaderConstant(s32 index, const u32* ints, int count) = 0; + //! Sets a vertex shader constant. /** Can be used if you created a shader using pixel/vertex shader assembler or ARB_fragment_program or ARB_vertex_program. @@ -95,6 +99,10 @@ public: //! Int interface for the above. virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count) = 0; + //! Uint interface for the above. + /* NOTE: UINT only works with GLSL, not supported for other shaders */ + virtual bool setPixelShaderConstant(s32 index, const u32* ints, int count) = 0; + //! Sets a pixel shader constant. /** Can be used if you created a shader using pixel/vertex shader assembler or ARB_fragment_program or ARB_vertex_program. diff --git a/source/Irrlicht/CD3D9Driver.cpp b/source/Irrlicht/CD3D9Driver.cpp index 7189a7d5..4e8b8c41 100644 --- a/source/Irrlicht/CD3D9Driver.cpp +++ b/source/Irrlicht/CD3D9Driver.cpp @@ -3176,6 +3176,19 @@ bool CD3D9Driver::setVertexShaderConstant(s32 index, const s32* ints, int count) } +//! Uint interface for the above. +bool CD3D9Driver::setVertexShaderConstant(s32 index, const u32* ints, int count) +{ + if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size()) + { + CD3D9MaterialRenderer* r = (CD3D9MaterialRenderer*)MaterialRenderers[Material.MaterialType].Renderer; + return r->setVariable(true, index, ints, count); + } + + return false; +} + + //! Sets a constant for the pixel shader based on an index. bool CD3D9Driver::setPixelShaderConstant(s32 index, const f32* floats, int count) { @@ -3202,6 +3215,20 @@ bool CD3D9Driver::setPixelShaderConstant(s32 index, const s32* ints, int count) } +//! Uint interface for the above. +bool CD3D9Driver::setPixelShaderConstant(s32 index, const u32* ints, int count) +{ + if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size()) + { + CD3D9MaterialRenderer* r = (CD3D9MaterialRenderer*)MaterialRenderers[Material.MaterialType].Renderer; + return r->setVariable(false, index, ints, count); + } + + return false; +} + + + //! Adds a new material renderer to the VideoDriver, using pixel and/or //! vertex shaders to render geometry. s32 CD3D9Driver::addShaderMaterial(const c8* vertexShaderProgram, diff --git a/source/Irrlicht/CD3D9Driver.h b/source/Irrlicht/CD3D9Driver.h index 2ceed2ea..ec6c1f47 100644 --- a/source/Irrlicht/CD3D9Driver.h +++ b/source/Irrlicht/CD3D9Driver.h @@ -252,12 +252,18 @@ namespace video //! Int interface for the above. virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count) _IRR_OVERRIDE_; + //! Uint interface for the above. + virtual bool setVertexShaderConstant(s32 index, const u32* ints, int count) _IRR_OVERRIDE_; + //! Sets a constant for the pixel shader based on an index. virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count) _IRR_OVERRIDE_; //! Int interface for the above. virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count) _IRR_OVERRIDE_; + //! Uint interface for the above. + virtual bool setPixelShaderConstant(s32 index, const u32* ints, int count) _IRR_OVERRIDE_; + //! Returns a pointer to the IVideoDriver interface. (Implementation for //! IMaterialRendererServices) virtual IVideoDriver* getVideoDriver() _IRR_OVERRIDE_; diff --git a/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp b/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp index 3600333a..b7007d63 100644 --- a/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp +++ b/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp @@ -370,6 +370,14 @@ bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, s32 index, } +bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, s32 index, + const u32* ints, int count) +{ + os::Printer::log("Error DirectX 9 does not support unsigned integer constants in shaders.", ELL_ERROR); + return false; +} + + bool CD3D9HLSLMaterialRenderer::OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) { if (VSConstantsTable) diff --git a/source/Irrlicht/CD3D9HLSLMaterialRenderer.h b/source/Irrlicht/CD3D9HLSLMaterialRenderer.h index c485ee6f..f02c8032 100644 --- a/source/Irrlicht/CD3D9HLSLMaterialRenderer.h +++ b/source/Irrlicht/CD3D9HLSLMaterialRenderer.h @@ -56,6 +56,9 @@ public: //! Int interface for the above. virtual bool setVariable(bool vertexShader, s32 index, const s32* ints, int count); + //! Uint interface for the above. + virtual bool setVariable(bool vertexShader, s32 index, const u32* ints, int count); + bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype) _IRR_OVERRIDE_; protected: diff --git a/source/Irrlicht/CD3D9MaterialRenderer.h b/source/Irrlicht/CD3D9MaterialRenderer.h index fb81391d..fca6bed4 100644 --- a/source/Irrlicht/CD3D9MaterialRenderer.h +++ b/source/Irrlicht/CD3D9MaterialRenderer.h @@ -89,6 +89,13 @@ public: return false; } + //! Uint interface for the above. + virtual bool setVariable(bool vertexShader, s32 index, const u32* ints, int count) + { + os::Printer::log("Invalid material to set variable in."); + return false; + } + protected: IDirect3DDevice9* pID3DDevice; diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index 3852b137..e60d1129 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -3664,19 +3664,15 @@ s32 COpenGLDriver::getPixelShaderConstantID(const c8* name) //! Sets a vertex shader constant. void COpenGLDriver::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) { -#ifdef GL_ARB_vertex_program for (s32 i=0; isetPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); + return false; +} + //! Adds a new material renderer to the VideoDriver, using pixel and/or //! vertex shaders to render geometry. diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h index 46a6ebbc..e956aad5 100644 --- a/source/Irrlicht/COpenGLDriver.h +++ b/source/Irrlicht/COpenGLDriver.h @@ -292,12 +292,18 @@ namespace video //! Int interface for the above. virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count) _IRR_OVERRIDE_; + //! Uint interface for the above. + virtual bool setVertexShaderConstant(s32 index, const u32* ints, int count) _IRR_OVERRIDE_; + //! Sets a constant for the pixel shader based on an index. virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count) _IRR_OVERRIDE_; //! Int interface for the above. virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count) _IRR_OVERRIDE_; + //! Uint interface for the above. + virtual bool setPixelShaderConstant(s32 index, const u32* ints, int count) _IRR_OVERRIDE_; + //! disables all textures beginning with the optional fromStage parameter. Otherwise all texture stages are disabled. //! Returns whether disabling was successful or not. bool disableTextures(u32 fromStage=0); diff --git a/source/Irrlicht/COpenGLExtensionHandler.cpp b/source/Irrlicht/COpenGLExtensionHandler.cpp index ee3bf841..227d059b 100644 --- a/source/Irrlicht/COpenGLExtensionHandler.cpp +++ b/source/Irrlicht/COpenGLExtensionHandler.cpp @@ -44,6 +44,7 @@ COpenGLExtensionHandler::COpenGLExtensionHandler() : pGlGetUniformLocationARB(0), pGlGetUniformLocation(0), pGlUniform1fvARB(0), pGlUniform2fvARB(0), pGlUniform3fvARB(0), pGlUniform4fvARB(0), pGlUniform1ivARB(0), pGlUniform2ivARB(0), pGlUniform3ivARB(0), pGlUniform4ivARB(0), + pGlUniform1uiv(0), pGlUniform2uiv(0), pGlUniform3uiv(0), pGlUniform4uiv(0), pGlUniformMatrix2fvARB(0), pGlUniformMatrix2x3fv(0), pGlUniformMatrix2x4fv(0), pGlUniformMatrix3x2fv(0), pGlUniformMatrix3fvARB(0), pGlUniformMatrix3x4fv(0), pGlUniformMatrix4x2fv(0), pGlUniformMatrix4x3fv(0), pGlUniformMatrix4fvARB(0), @@ -466,6 +467,10 @@ void COpenGLExtensionHandler::initExtensions(bool stencilBuffer) pGlUniform2ivARB = (PFNGLUNIFORM2IVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniform2ivARB"); pGlUniform3ivARB = (PFNGLUNIFORM3IVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniform3ivARB"); pGlUniform4ivARB = (PFNGLUNIFORM4IVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniform4ivARB"); + pGlUniform1uiv = (PFNGLUNIFORM1UIVPROC) IRR_OGL_LOAD_EXTENSION("glUniform1uiv"); + pGlUniform2uiv = (PFNGLUNIFORM2UIVPROC) IRR_OGL_LOAD_EXTENSION("glUniform2uiv"); + pGlUniform3uiv = (PFNGLUNIFORM3UIVPROC) IRR_OGL_LOAD_EXTENSION("glUniform3uiv"); + pGlUniform4uiv = (PFNGLUNIFORM4UIVPROC) IRR_OGL_LOAD_EXTENSION("glUniform4uiv"); pGlUniformMatrix2fvARB = (PFNGLUNIFORMMATRIX2FVARBPROC) IRR_OGL_LOAD_EXTENSION("glUniformMatrix2fvARB"); pGlUniformMatrix2x3fv = (PFNGLUNIFORMMATRIX2X3FVPROC) IRR_OGL_LOAD_EXTENSION("glUniformMatrix2x3fv"); pGlUniformMatrix2x4fv = (PFNGLUNIFORMMATRIX2X4FVPROC)IRR_OGL_LOAD_EXTENSION("glUniformMatrix2x4fv"); diff --git a/source/Irrlicht/COpenGLExtensionHandler.h b/source/Irrlicht/COpenGLExtensionHandler.h index 15886ef8..cc932f68 100644 --- a/source/Irrlicht/COpenGLExtensionHandler.h +++ b/source/Irrlicht/COpenGLExtensionHandler.h @@ -1127,6 +1127,10 @@ class COpenGLExtensionHandler void extGlUniform2iv(GLint loc, GLsizei count, const GLint *v); void extGlUniform3iv(GLint loc, GLsizei count, const GLint *v); void extGlUniform4iv(GLint loc, GLsizei count, const GLint *v); + void extGlUniform1uiv(GLint loc, GLsizei count, const GLuint *v); + void extGlUniform2uiv(GLint loc, GLsizei count, const GLuint *v); + void extGlUniform3uiv(GLint loc, GLsizei count, const GLuint *v); + void extGlUniform4uiv(GLint loc, GLsizei count, const GLuint *v); void extGlUniformMatrix2fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); void extGlUniformMatrix2x3fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); void extGlUniformMatrix2x4fv(GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); @@ -1262,6 +1266,10 @@ class COpenGLExtensionHandler PFNGLUNIFORM2IVARBPROC pGlUniform2ivARB; PFNGLUNIFORM3IVARBPROC pGlUniform3ivARB; PFNGLUNIFORM4IVARBPROC pGlUniform4ivARB; + PFNGLUNIFORM1UIVPROC pGlUniform1uiv; + PFNGLUNIFORM2UIVPROC pGlUniform2uiv; + PFNGLUNIFORM3UIVPROC pGlUniform3uiv; + PFNGLUNIFORM4UIVPROC pGlUniform4uiv; PFNGLUNIFORMMATRIX2FVARBPROC pGlUniformMatrix2fvARB; PFNGLUNIFORMMATRIX2X3FVPROC pGlUniformMatrix2x3fv; PFNGLUNIFORMMATRIX2X4FVPROC pGlUniformMatrix2x4fv; @@ -1895,6 +1903,46 @@ inline void COpenGLExtensionHandler::extGlUniform4fv(GLint loc, GLsizei count, c #endif } +inline void COpenGLExtensionHandler::extGlUniform1uiv(GLint loc, GLsizei count, const GLuint *v) +{ +#ifdef _IRR_OPENGL_USE_EXTPOINTER_ + if (pGlUniform1uiv) + pGlUniform1uiv(loc, count, v); +#else + glUniform1uiv(loc, count, v); +#endif +} + +inline void COpenGLExtensionHandler::extGlUniform2uiv(GLint loc, GLsizei count, const GLuint *v) +{ +#ifdef _IRR_OPENGL_USE_EXTPOINTER_ + if (pGlUniform2uiv) + pGlUniform2uiv(loc, count, v); +#else + glUniform2uiv(loc, count, v); +#endif +} + +inline void COpenGLExtensionHandler::extGlUniform3uiv(GLint loc, GLsizei count, const GLuint *v) +{ +#ifdef _IRR_OPENGL_USE_EXTPOINTER_ + if (pGlUniform3uiv) + pGlUniform3uiv(loc, count, v); +#else + glUniform3uiv(loc, count, v); +#endif +} + +inline void COpenGLExtensionHandler::extGlUniform4uiv(GLint loc, GLsizei count, const GLuint *v) +{ +#ifdef _IRR_OPENGL_USE_EXTPOINTER_ + if (pGlUniform4uiv) + pGlUniform4uiv(loc, count, v); +#else + glUniform4uiv(loc, count, v); +#endif +} + inline void COpenGLExtensionHandler::extGlUniform1iv(GLint loc, GLsizei count, const GLint *v) { #ifdef _IRR_OPENGL_USE_EXTPOINTER_ diff --git a/source/Irrlicht/COpenGLSLMaterialRenderer.cpp b/source/Irrlicht/COpenGLSLMaterialRenderer.cpp index 13df6a6e..14a0ecfd 100644 --- a/source/Irrlicht/COpenGLSLMaterialRenderer.cpp +++ b/source/Irrlicht/COpenGLSLMaterialRenderer.cpp @@ -608,9 +608,13 @@ bool COpenGLSLMaterialRenderer::setVertexShaderConstant(s32 index, const s32* in return setPixelShaderConstant(index, ints, count); } +bool COpenGLSLMaterialRenderer::setVertexShaderConstant(s32 index, const u32* ints, int count) +{ + return setPixelShaderConstant(index, ints, count); +} + bool COpenGLSLMaterialRenderer::setPixelShaderConstant(s32 index, const f32* floats, int count) { -#ifdef GL_ARB_shader_objects if(index < 0 || UniformInfo[index].location < 0) return false; @@ -678,14 +682,10 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(s32 index, const f32* flo break; } return status; -#else - return false; -#endif } bool COpenGLSLMaterialRenderer::setPixelShaderConstant(s32 index, const s32* ints, int count) { -#ifdef GL_ARB_shader_objects if(index < 0 || UniformInfo[index].location < 0) return false; @@ -722,9 +722,34 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(s32 index, const s32* int break; } return status; -#else - return false; -#endif +} + +bool COpenGLSLMaterialRenderer::setPixelShaderConstant(s32 index, const u32* ints, int count) +{ + if(index < 0 || UniformInfo[index].location < 0) + return false; + + bool status = true; + + switch (UniformInfo[index].type) + { + case GL_UNSIGNED_INT: + Driver->extGlUniform1uiv(UniformInfo[index].location, count, reinterpret_cast(ints)); + break; + case GL_UNSIGNED_INT_VEC2: + Driver->extGlUniform2uiv(UniformInfo[index].location, count/2, reinterpret_cast(ints)); + break; + case GL_UNSIGNED_INT_VEC3: + Driver->extGlUniform3uiv(UniformInfo[index].location, count/3, reinterpret_cast(ints)); + break; + case GL_UNSIGNED_INT_VEC4: + Driver->extGlUniform4uiv(UniformInfo[index].location, count/4, reinterpret_cast(ints)); + break; + default: + status = false; + break; + } + return status; } IVideoDriver* COpenGLSLMaterialRenderer::getVideoDriver() diff --git a/source/Irrlicht/COpenGLSLMaterialRenderer.h b/source/Irrlicht/COpenGLSLMaterialRenderer.h index e3129eaa..354f1a06 100644 --- a/source/Irrlicht/COpenGLSLMaterialRenderer.h +++ b/source/Irrlicht/COpenGLSLMaterialRenderer.h @@ -79,8 +79,10 @@ public: virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) _IRR_OVERRIDE_; virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count) _IRR_OVERRIDE_; virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count) _IRR_OVERRIDE_; + virtual bool setVertexShaderConstant(s32 index, const u32* ints, int count) _IRR_OVERRIDE_; virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count) _IRR_OVERRIDE_; virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count) _IRR_OVERRIDE_; + virtual bool setPixelShaderConstant(s32 index, const u32* ints, int count) _IRR_OVERRIDE_; virtual IVideoDriver* getVideoDriver() _IRR_OVERRIDE_; protected: diff --git a/tests/tests-last-passed-at.txt b/tests/tests-last-passed-at.txt index 1034815d..673e1c4d 100644 --- a/tests/tests-last-passed-at.txt +++ b/tests/tests-last-passed-at.txt @@ -1,4 +1,4 @@ -Tests finished. 72 tests of 72 passed. -Compiled as DEBUG -Test suite pass at GMT Fri Jan 3 17:05:41 2020 - +Tests finished. 72 tests of 72 passed. +Compiled as DEBUG +Test suite pass at GMT Mon Feb 10 14:59:56 2020 +