diff --git a/include/IMaterialRendererServices.h b/include/IMaterialRendererServices.h index ca500184..c82a86ba 100644 --- a/include/IMaterialRendererServices.h +++ b/include/IMaterialRendererServices.h @@ -65,6 +65,9 @@ public: */ virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count) = 0; + //! Bool interface for the above. + virtual bool setVertexShaderConstant(const c8* name, const bool* bools, int count) = 0; + //! Int interface for the above. virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count) = 0; @@ -86,6 +89,9 @@ public: \return True if successful. */ virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count) = 0; + //! Bool interface for the above. + virtual bool setPixelShaderConstant(const c8* name, const bool* bools, int count) = 0; + //! Int interface for the above. virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count) = 0; diff --git a/source/Irrlicht/CD3D8Driver.cpp b/source/Irrlicht/CD3D8Driver.cpp index 89981ab9..71b7ce98 100644 --- a/source/Irrlicht/CD3D8Driver.cpp +++ b/source/Irrlicht/CD3D8Driver.cpp @@ -2186,6 +2186,14 @@ bool CD3D8Driver::setVertexShaderConstant(const c8* name, const f32* floats, int } +//! Bool interface for the above. +bool CD3D8Driver::setVertexShaderConstant(const c8* name, const bool* bools, int count) +{ + os::Printer::log("Cannot set constant, no HLSL supported in D3D8"); + return false; +} + + //! Int interface for the above. bool CD3D8Driver::setVertexShaderConstant(const c8* name, const s32* ints, int count) { @@ -2202,6 +2210,14 @@ bool CD3D8Driver::setPixelShaderConstant(const c8* name, const f32* floats, int } +//! Bool interface for the above. +bool CD3D8Driver::setPixelShaderConstant(const c8* name, const bool* bools, int count) +{ + os::Printer::log("Cannot set constant, no HLSL supported in D3D8"); + return false; +} + + //! Int interface for the above. bool CD3D8Driver::setPixelShaderConstant(const c8* name, const s32* ints, int count) { diff --git a/source/Irrlicht/CD3D8Driver.h b/source/Irrlicht/CD3D8Driver.h index 5657ff7a..4c596348 100644 --- a/source/Irrlicht/CD3D8Driver.h +++ b/source/Irrlicht/CD3D8Driver.h @@ -182,12 +182,18 @@ namespace video //! Sets a constant for the vertex shader based on a name. virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count); + //! Bool interface for the above. + virtual bool setVertexShaderConstant(const c8* name, const bool* bools, int count); + //! Int interface for the above. virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count); //! Sets a constant for the pixel shader based on a name. virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count); + //! Bool interface for the above. + virtual bool setPixelShaderConstant(const c8* name, const bool* bools, int count); + //! Int interface for the above. virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count); diff --git a/source/Irrlicht/CD3D9Driver.cpp b/source/Irrlicht/CD3D9Driver.cpp index 74bee5e2..48b6f81b 100644 --- a/source/Irrlicht/CD3D9Driver.cpp +++ b/source/Irrlicht/CD3D9Driver.cpp @@ -3090,6 +3090,19 @@ bool CD3D9Driver::setVertexShaderConstant(const c8* name, const f32* floats, int } +//! Bool interface for the above. +bool CD3D9Driver::setVertexShaderConstant(const c8* name, const bool* bools, int count) +{ + if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size()) + { + CD3D9MaterialRenderer* r = (CD3D9MaterialRenderer*)MaterialRenderers[Material.MaterialType].Renderer; + return r->setVariable(true, name, bools, count); + } + + return false; +} + + //! Int interface for the above. bool CD3D9Driver::setVertexShaderConstant(const c8* name, const s32* ints, int count) { @@ -3116,6 +3129,19 @@ bool CD3D9Driver::setPixelShaderConstant(const c8* name, const f32* floats, int } +//! Bool interface for the above. +bool CD3D9Driver::setPixelShaderConstant(const c8* name, const bool* bools, int count) +{ + if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size()) + { + CD3D9MaterialRenderer* r = (CD3D9MaterialRenderer*)MaterialRenderers[Material.MaterialType].Renderer; + return r->setVariable(false, name, bools, count); + } + + return false; +} + + //! Int interface for the above. bool CD3D9Driver::setPixelShaderConstant(const c8* name, const s32* ints, int count) { diff --git a/source/Irrlicht/CD3D9Driver.h b/source/Irrlicht/CD3D9Driver.h index fcb18940..9fea356e 100644 --- a/source/Irrlicht/CD3D9Driver.h +++ b/source/Irrlicht/CD3D9Driver.h @@ -268,12 +268,18 @@ namespace video //! Sets a constant for the vertex shader based on a name. virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count); + //! Bool interface for the above. + virtual bool setVertexShaderConstant(const c8* name, const bool* bools, int count); + //! Int interface for the above. virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count); //! Sets a constant for the pixel shader based on a name. virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count); + //! Bool interface for the above. + virtual bool setPixelShaderConstant(const c8* name, const bool* bools, int count); + //! Int interface for the above. virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count); diff --git a/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp b/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp index 9cc0c07b..dc7d4c62 100644 --- a/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp +++ b/source/Irrlicht/CD3D9HLSLMaterialRenderer.cpp @@ -304,6 +304,45 @@ bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, } +bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, + const bool* bools, int count) +{ + LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable; + if (!tbl) + return false; + + // currently we only support top level parameters. + // Should be enough for the beginning. (TODO) + + D3DXHANDLE hndl = tbl->GetConstantByName(NULL, name); + if (!hndl) + { + core::stringc s = "HLSL Variable to set not found: '"; + s += name; + s += "'. Available variables are:"; + os::Printer::log(s.c_str(), ELL_WARNING); + printHLSLVariables(tbl); + return false; + } + + D3DXCONSTANT_DESC Description; + UINT ucount = 1; + tbl->GetConstantDesc(hndl, &Description, &ucount); + + if(Description.RegisterSet != D3DXRS_SAMPLER) + { + HRESULT hr = tbl->SetBoolArray(pID3DDevice, hndl, (BOOL*)bools, count); + if (FAILED(hr)) + { + os::Printer::log("Error setting bool array for HLSL variable", ELL_WARNING); + return false; + } + } + + return true; +} + + bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, const s32* ints, int count) { diff --git a/source/Irrlicht/CD3D9HLSLMaterialRenderer.h b/source/Irrlicht/CD3D9HLSLMaterialRenderer.h index 7bea2300..8c6d1168 100644 --- a/source/Irrlicht/CD3D9HLSLMaterialRenderer.h +++ b/source/Irrlicht/CD3D9HLSLMaterialRenderer.h @@ -51,6 +51,9 @@ public: //! \param count: Amount of floats in array. virtual bool setVariable(bool vertexShader, const c8* name, const f32* floats, int count); + //! Bool interface for the above. + virtual bool setVariable(bool vertexShader, const c8* name, const bool* bools, int count); + //! Int interface for the above. virtual bool setVariable(bool vertexShader, const c8* name, const s32* ints, int count); diff --git a/source/Irrlicht/CD3D9MaterialRenderer.h b/source/Irrlicht/CD3D9MaterialRenderer.h index 27c19f17..7edde1cf 100644 --- a/source/Irrlicht/CD3D9MaterialRenderer.h +++ b/source/Irrlicht/CD3D9MaterialRenderer.h @@ -79,6 +79,13 @@ public: return false; } + //! Bool interface for the above. + virtual bool setVariable(bool vertexShader, const c8* name, const bool* bools, int count) + { + os::Printer::log("Invalid material to set variable in."); + return false; + } + //! Int interface for the above. virtual bool setVariable(bool vertexShader, const c8* name, const s32* ints, int count) { diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index 5bf96328..941811b7 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -3876,15 +3876,27 @@ bool COpenGLDriver::setVertexShaderConstant(const c8* name, const f32* floats, i return setPixelShaderConstant(name, floats, count); } +//! Bool interface for the above. +bool COpenGLDriver::setVertexShaderConstant(const c8* name, const bool* bools, int count) +{ + return setPixelShaderConstant(name, bools, count); +} + //! Int interface for the above. bool COpenGLDriver::setVertexShaderConstant(const c8* name, const s32* ints, int count) +{ + return setPixelShaderConstant(name, ints, count); +} + +//! Sets a constant for the pixel shader based on a name. +bool COpenGLDriver::setPixelShaderConstant(const c8* name, const f32* floats, int count) { os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); return false; } -//! Sets a constant for the pixel shader based on a name. -bool COpenGLDriver::setPixelShaderConstant(const c8* name, const f32* floats, int count) +//! Bool interface for the above. +bool COpenGLDriver::setPixelShaderConstant(const c8* name, const bool* bools, int count) { os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant()."); return false; diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h index 635b058e..e27744ef 100644 --- a/source/Irrlicht/COpenGLDriver.h +++ b/source/Irrlicht/COpenGLDriver.h @@ -286,12 +286,18 @@ namespace video //! Sets a constant for the vertex shader based on a name. virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count); + //! Bool interface for the above. + virtual bool setVertexShaderConstant(const c8* name, const bool* bools, int count); + //! Int interface for the above. virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count); //! Sets a constant for the pixel shader based on a name. virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count); + //! Bool interface for the above. + virtual bool setPixelShaderConstant(const c8* name, const bool* bools, int count); + //! Int interface for the above. virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count); diff --git a/source/Irrlicht/COpenGLExtensionHandler.h b/source/Irrlicht/COpenGLExtensionHandler.h index dda1530b..9ca7a31d 100644 --- a/source/Irrlicht/COpenGLExtensionHandler.h +++ b/source/Irrlicht/COpenGLExtensionHandler.h @@ -1041,6 +1041,10 @@ class COpenGLExtensionHandler void extGlUniform2fv(GLint loc, GLsizei count, const GLfloat *v); void extGlUniform3fv(GLint loc, GLsizei count, const GLfloat *v); void extGlUniform4fv(GLint loc, GLsizei count, const GLfloat *v); + void extGlUniform1bv(GLint loc, GLsizei count, const bool *v); + void extGlUniform2bv(GLint loc, GLsizei count, const bool *v); + void extGlUniform3bv(GLint loc, GLsizei count, const bool *v); + void extGlUniform4bv(GLint loc, GLsizei count, const bool *v); void extGlUniform1iv(GLint loc, GLsizei count, const GLint *v); void extGlUniform2iv(GLint loc, GLsizei count, const GLint *v); void extGlUniform3iv(GLint loc, GLsizei count, const GLint *v); diff --git a/source/Irrlicht/COpenGLSLMaterialRenderer.cpp b/source/Irrlicht/COpenGLSLMaterialRenderer.cpp index 95f338be..280be96b 100644 --- a/source/Irrlicht/COpenGLSLMaterialRenderer.cpp +++ b/source/Irrlicht/COpenGLSLMaterialRenderer.cpp @@ -496,6 +496,11 @@ bool COpenGLSLMaterialRenderer::setVertexShaderConstant(const c8* name, const f3 return setPixelShaderConstant(name, floats, count); } +bool COpenGLSLMaterialRenderer::setVertexShaderConstant(const c8* name, const bool* bools, int count) +{ + return setPixelShaderConstant(name, bools, count); +} + bool COpenGLSLMaterialRenderer::setVertexShaderConstant(const c8* name, const s32* ints, int count) { return setPixelShaderConstant(name, ints, count); @@ -527,27 +532,29 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const f32 else Location=Driver->extGlGetUniformLocationARB(Program,name); + bool status = true; + switch (UniformInfo[i].type) { case GL_FLOAT: Driver->extGlUniform1fv(Location, count, floats); break; - case GL_FLOAT_VEC2_ARB: + case GL_FLOAT_VEC2: Driver->extGlUniform2fv(Location, count/2, floats); break; - case GL_FLOAT_VEC3_ARB: + case GL_FLOAT_VEC3: Driver->extGlUniform3fv(Location, count/3, floats); break; - case GL_FLOAT_VEC4_ARB: + case GL_FLOAT_VEC4: Driver->extGlUniform4fv(Location, count/4, floats); break; - case GL_FLOAT_MAT2_ARB: + case GL_FLOAT_MAT2: Driver->extGlUniformMatrix2fv(Location, count/4, false, floats); break; - case GL_FLOAT_MAT3_ARB: + case GL_FLOAT_MAT3: Driver->extGlUniformMatrix3fv(Location, count/9, false, floats); break; - case GL_FLOAT_MAT4_ARB: + case GL_FLOAT_MAT4: Driver->extGlUniformMatrix4fv(Location, count/16, false, floats); break; case GL_SAMPLER_1D: @@ -562,9 +569,57 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const f32 } break; default: + status = false; break; } - return true; + return status; +#else + return false; +#endif +} + +bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const bool* bools, int count) +{ + u32 i; + const u32 num = UniformInfo.size(); + + for (i=0; i < num; ++i) + { + if (UniformInfo[i].name == name) + break; + } + + if (i == num) + return false; + +#if defined(GL_VERSION_2_0)||defined(GL_ARB_shader_objects) + GLint Location=0; + if (Program2) + Location=Driver->extGlGetUniformLocation(Program2,name); + else + Location=Driver->extGlGetUniformLocationARB(Program,name); + + bool status = true; + + switch (UniformInfo[i].type) + { + case GL_BOOL: + Driver->extGlUniform1iv(Location, count, (GLint*)bools); + break; + case GL_BOOL_VEC2: + Driver->extGlUniform2iv(Location, count/2, (GLint*)bools); + break; + case GL_BOOL_VEC3: + Driver->extGlUniform3iv(Location, count/3, (GLint*)bools); + break; + case GL_BOOL_VEC4: + Driver->extGlUniform4iv(Location, count/4, (GLint*)bools); + break; + default: + status = false; + break; + } + return status; #else return false; #endif @@ -591,18 +646,22 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const s32 else Location=Driver->extGlGetUniformLocationARB(Program,name); + bool status = true; + switch (UniformInfo[i].type) { - case GL_INT_VEC2_ARB: + case GL_INT: + Driver->extGlUniform1iv(Location, count, ints); + break; + case GL_INT_VEC2: Driver->extGlUniform2iv(Location, count/2, ints); break; - case GL_INT_VEC3_ARB: + case GL_INT_VEC3: Driver->extGlUniform3iv(Location, count/3, ints); break; - case GL_INT_VEC4_ARB: + case GL_INT_VEC4: Driver->extGlUniform4iv(Location, count/4, ints); break; - case GL_INT: case GL_SAMPLER_1D: case GL_SAMPLER_2D: case GL_SAMPLER_3D: @@ -612,9 +671,10 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const s32 Driver->extGlUniform1iv(Location, 1, ints); break; default: + status = false; break; } - return true; + return status; #else return false; #endif diff --git a/source/Irrlicht/COpenGLSLMaterialRenderer.h b/source/Irrlicht/COpenGLSLMaterialRenderer.h index 6045de26..6e38c1b2 100644 --- a/source/Irrlicht/COpenGLSLMaterialRenderer.h +++ b/source/Irrlicht/COpenGLSLMaterialRenderer.h @@ -86,9 +86,11 @@ public: // implementations for the render services virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates); virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count); + virtual bool setVertexShaderConstant(const c8* name, const bool* bools, int count); virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count); virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1); virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count); + virtual bool setPixelShaderConstant(const c8* name, const bool* bools, int count); virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count); virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1); virtual IVideoDriver* getVideoDriver();