From e1675c83cea875684cdca8116b8175192fad78e0 Mon Sep 17 00:00:00 2001 From: nadro Date: Mon, 8 Jul 2013 14:56:16 +0000 Subject: [PATCH] - Moved setBasicRenderStates methods calls in shader based material renderers to the same place as in standard fixed pipeline material renderers (first lines of OnSetMaterial method). - Fixed bug with texture states in OpenGL. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4561 dfc29bdd-3216-0410-991c-e03cc46cb475 --- .../Irrlicht/CD3D8ShaderMaterialRenderer.cpp | 11 +++--- source/Irrlicht/CD3D9CgMaterialRenderer.cpp | 13 +++---- .../Irrlicht/CD3D9ShaderMaterialRenderer.cpp | 11 +++--- source/Irrlicht/COpenGLCgMaterialRenderer.cpp | 4 +- source/Irrlicht/COpenGLDriver.cpp | 39 +++++++++++-------- source/Irrlicht/COpenGLDriver.h | 10 +---- source/Irrlicht/COpenGLSLMaterialRenderer.cpp | 4 +- .../COpenGLShaderMaterialRenderer.cpp | 4 +- 8 files changed, 45 insertions(+), 51 deletions(-) diff --git a/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp b/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp index f46d5837..d65d291b 100644 --- a/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp +++ b/source/Irrlicht/CD3D8ShaderMaterialRenderer.cpp @@ -112,6 +112,8 @@ bool CD3D8ShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E void CD3D8ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial, bool resetAllRenderstates, video::IMaterialRendererServices* services) { + services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { if (VertexShader) @@ -135,13 +137,10 @@ void CD3D8ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material if (BaseMaterial) BaseMaterial->OnSetMaterial(material, material, true, services); + + if (CallBack) + CallBack->OnSetMaterial(material); } - - //let callback know used material - if (CallBack) - CallBack->OnSetMaterial(material); - - services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); } void CD3D8ShaderMaterialRenderer::OnUnsetMaterial() diff --git a/source/Irrlicht/CD3D9CgMaterialRenderer.cpp b/source/Irrlicht/CD3D9CgMaterialRenderer.cpp index 60596404..87ff05e9 100644 --- a/source/Irrlicht/CD3D9CgMaterialRenderer.cpp +++ b/source/Irrlicht/CD3D9CgMaterialRenderer.cpp @@ -75,6 +75,8 @@ bool CD3D9CgMaterialRenderer::isTransparent() const void CD3D9CgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates, IMaterialRendererServices* services) { + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + Material = material; if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) @@ -85,17 +87,12 @@ void CD3D9CgMaterialRenderer::OnSetMaterial(const SMaterial& material, const SMa if (FragmentProgram) cgD3D9BindProgram(FragmentProgram); - /*if (GeometryProgram) - cgD3D9BindProgram(GeometryProgram);*/ - if (BaseMaterial) BaseMaterial->OnSetMaterial(material, material, true, this); + + if (CallBack) + CallBack->OnSetMaterial(material); } - - if (CallBack) - CallBack->OnSetMaterial(material); - - Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); } bool CD3D9CgMaterialRenderer::OnRender(IMaterialRendererServices* services, E_VERTEX_TYPE vtxtype) diff --git a/source/Irrlicht/CD3D9ShaderMaterialRenderer.cpp b/source/Irrlicht/CD3D9ShaderMaterialRenderer.cpp index 7d2f76e6..a58b0edb 100644 --- a/source/Irrlicht/CD3D9ShaderMaterialRenderer.cpp +++ b/source/Irrlicht/CD3D9ShaderMaterialRenderer.cpp @@ -112,6 +112,8 @@ bool CD3D9ShaderMaterialRenderer::OnRender(IMaterialRendererServices* service, E void CD3D9ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material, const video::SMaterial& lastMaterial, bool resetAllRenderstates, video::IMaterialRendererServices* services) { + services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { if (VertexShader) @@ -133,13 +135,10 @@ void CD3D9ShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& material if (BaseMaterial) BaseMaterial->OnSetMaterial(material, material, true, services); + + if (CallBack) + CallBack->OnSetMaterial(material); } - - //let callback know used material - if (CallBack) - CallBack->OnSetMaterial(material); - - services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); } diff --git a/source/Irrlicht/COpenGLCgMaterialRenderer.cpp b/source/Irrlicht/COpenGLCgMaterialRenderer.cpp index 96ed4bcd..61c7cc78 100644 --- a/source/Irrlicht/COpenGLCgMaterialRenderer.cpp +++ b/source/Irrlicht/COpenGLCgMaterialRenderer.cpp @@ -93,6 +93,8 @@ void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const S else Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE); + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + Material = material; if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) @@ -121,8 +123,6 @@ void COpenGLCgMaterialRenderer::OnSetMaterial(const SMaterial& material, const S if (CallBack) CallBack->OnSetMaterial(material); } - - Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); } bool COpenGLCgMaterialRenderer::OnRender(IMaterialRendererServices* services, E_VERTEX_TYPE vtxtype) diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index 2ccc713e..1ce57eb3 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -2834,16 +2834,18 @@ GLint COpenGLDriver::getTextureWrapMode(const u8 clamp) } -//! OpenGL version of setBasicRenderStates method. -void COpenGLDriver::setOpenGLBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, +//! Can be called by an IMaterialRenderer to make its work easier. +void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, bool resetAllRenderStates) { // Fixed pipeline isn't important for shader based materials - if (resetAllRenderStates || FixedPipelineState == EOFPS_ENABLE || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE) + E_OPENGL_FIXED_PIPELINE_STATE tempState = FixedPipelineState; + + if (resetAllRenderStates || tempState == EOFPS_ENABLE || tempState == EOFPS_DISABLE_TO_ENABLE) { // material colors - if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE || + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || lastmaterial.ColorMaterial != material.ColorMaterial) { switch (material.ColorMaterial) @@ -2871,7 +2873,7 @@ void COpenGLDriver::setOpenGLBasicRenderStates(const SMaterial& material, const glEnable(GL_COLOR_MATERIAL); } - if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE || + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || lastmaterial.AmbientColor != material.AmbientColor || lastmaterial.DiffuseColor != material.DiffuseColor || lastmaterial.EmissiveColor != material.EmissiveColor || @@ -2911,7 +2913,7 @@ void COpenGLDriver::setOpenGLBasicRenderStates(const SMaterial& material, const } } - if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE || + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || lastmaterial.SpecularColor != material.SpecularColor || lastmaterial.Shininess != material.Shininess || lastmaterial.ColorMaterial != material.ColorMaterial) @@ -2941,7 +2943,7 @@ void COpenGLDriver::setOpenGLBasicRenderStates(const SMaterial& material, const } // shademode - if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE || + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || lastmaterial.GouraudShading != material.GouraudShading) { if (material.GouraudShading) @@ -2951,7 +2953,7 @@ void COpenGLDriver::setOpenGLBasicRenderStates(const SMaterial& material, const } // lighting - if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE || + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || lastmaterial.Lighting != material.Lighting) { if (material.Lighting) @@ -2961,7 +2963,7 @@ void COpenGLDriver::setOpenGLBasicRenderStates(const SMaterial& material, const } // fog - if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE || + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || lastmaterial.FogEnable != material.FogEnable) { if (material.FogEnable) @@ -2971,7 +2973,7 @@ void COpenGLDriver::setOpenGLBasicRenderStates(const SMaterial& material, const } // normalization - if (resetAllRenderStates || FixedPipelineState == EOFPS_DISABLE_TO_ENABLE || + if (resetAllRenderStates || tempState == EOFPS_DISABLE_TO_ENABLE || lastmaterial.NormalizeNormals != material.NormalizeNormals) { if (material.NormalizeNormals) @@ -2981,9 +2983,9 @@ void COpenGLDriver::setOpenGLBasicRenderStates(const SMaterial& material, const } // Set fixed pipeline as active. - FixedPipelineState = EOFPS_ENABLE; + tempState = EOFPS_ENABLE; } - else if (FixedPipelineState == EOFPS_ENABLE_TO_DISABLE) + else if (tempState == EOFPS_ENABLE_TO_DISABLE) { glDisable(GL_COLOR_MATERIAL); glDisable(GL_LIGHTING); @@ -2991,10 +2993,10 @@ void COpenGLDriver::setOpenGLBasicRenderStates(const SMaterial& material, const glDisable(GL_NORMALIZE); // Set programmable pipeline as active. - FixedPipelineState = EOFPS_DISABLE; + tempState = EOFPS_DISABLE; } - // FixedPipelineState == EOFPS_DISABLE - driver doesn't calls functions related to fixed pipeline. + // tempState == EOFPS_DISABLE - driver doesn't calls functions related to fixed pipeline. // fillmode - fixed pipeline call, but it emulate GL_LINES behaviour in rendering, so it stay here. if (resetAllRenderStates || (lastmaterial.Wireframe != material.Wireframe) || (lastmaterial.PointCloud != material.PointCloud)) @@ -3270,8 +3272,10 @@ void COpenGLDriver::setOpenGLBasicRenderStates(const SMaterial& material, const } } - // be sure to leave in texture stage 0 - BridgeCalls->setActiveTexture(GL_TEXTURE0_ARB); + setTextureRenderStates(material, resetAllRenderStates); + + // set current fixed pipeline state + FixedPipelineState = tempState; } //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. @@ -3417,6 +3421,9 @@ void COpenGLDriver::setTextureRenderStates(const SMaterial& material, bool reset tmpTexture->getStatesCache().IsCached = true; } + + // be sure to leave in texture stage 0 + BridgeCalls->setActiveTexture(GL_TEXTURE0_ARB); } diff --git a/source/Irrlicht/COpenGLDriver.h b/source/Irrlicht/COpenGLDriver.h index b313e213..0252f5b6 100644 --- a/source/Irrlicht/COpenGLDriver.h +++ b/source/Irrlicht/COpenGLDriver.h @@ -286,15 +286,7 @@ namespace video //! Can be called by an IMaterialRenderer to make its work easier. virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, - bool resetAllRenderstates) _IRR_OVERRIDE_ - { - setOpenGLBasicRenderStates(material, lastmaterial, resetAllRenderstates); - setTextureRenderStates(material, resetAllRenderstates); - } - - //! OpenGL version of setBasicRenderStates method. - void setOpenGLBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, - bool resetAllRenderstates); + bool resetAllRenderstates) _IRR_OVERRIDE_; //! Compare in SMaterial doesn't check texture parameters, so we should call this on each OnRender call. virtual void setTextureRenderStates(const SMaterial& material, bool resetAllRenderstates); diff --git a/source/Irrlicht/COpenGLSLMaterialRenderer.cpp b/source/Irrlicht/COpenGLSLMaterialRenderer.cpp index 85bb8098..fda4de37 100644 --- a/source/Irrlicht/COpenGLSLMaterialRenderer.cpp +++ b/source/Irrlicht/COpenGLSLMaterialRenderer.cpp @@ -221,6 +221,8 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material, else Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE); + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { if (Program2) @@ -234,8 +236,6 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material, if (CallBack) CallBack->OnSetMaterial(material); } - - Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); } diff --git a/source/Irrlicht/COpenGLShaderMaterialRenderer.cpp b/source/Irrlicht/COpenGLShaderMaterialRenderer.cpp index 8cda7f89..edbd4bb9 100644 --- a/source/Irrlicht/COpenGLShaderMaterialRenderer.cpp +++ b/source/Irrlicht/COpenGLShaderMaterialRenderer.cpp @@ -138,6 +138,8 @@ void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& materi else Driver->setFixedPipelineState(COpenGLDriver::EOFPS_DISABLE); + Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); + if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates) { if (VertexShader) @@ -184,8 +186,6 @@ void COpenGLShaderMaterialRenderer::OnSetMaterial(const video::SMaterial& materi if (CallBack) CallBack->OnSetMaterial(material); } - - Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates); }