diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index f86d4d76f..fe4a88cf0 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -494,17 +494,44 @@ void IrrDriver::renderSolidFirstPass() glUseProgram(MeshShader::ObjectPass1Shader::Program); for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i) { - drawObjectPass1(*GroupedFPSM::MeshSet[i], GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i]); + const GLMesh &mesh = *GroupedFPSM::MeshSet[i]; + if (mesh.textures[0]) + { + compressTexture(mesh.textures[0], true); + setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + } + else + { + setTexture(0, 0, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, false); + GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + } + draw(mesh, mesh.vao_first_pass, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], 0); + if (!mesh.textures[0]) + { + GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + } } + glUseProgram(MeshShader::ObjectRefPass1Shader::Program); for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i) { - drawObjectRefPass1(*GroupedFPSM::MeshSet[i], GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], GroupedFPSM::MeshSet[i]->TextureMatrix); + const GLMesh &mesh = *GroupedFPSM::MeshSet[i]; + compressTexture(mesh.textures[0], true); + setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + draw(mesh, mesh.vao_first_pass, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], GroupedFPSM::MeshSet[i]->TextureMatrix, 0); } glUseProgram(MeshShader::NormalMapShader::Program); for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i) { - drawNormalPass(*GroupedFPSM::MeshSet[i], GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i]); + const GLMesh &mesh = *GroupedFPSM::MeshSet[i]; + assert(mesh.textures[1]); + compressTexture(mesh.textures[1], false); + setTexture(0, getTextureGLuint(mesh.textures[1]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + compressTexture(mesh.textures[0], true); + setTexture(1, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + draw(mesh, mesh.vao_first_pass, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], 0, 1); } } } diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 639871c50..e8a227d43 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -213,56 +213,6 @@ core::vector3df getWind() return m_speed * vector3df(1., 0., 0.) * cos(time); } - - -void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView) -{ - irr_driver->IncreaseObjectCount(); - GLenum ptype = mesh.PrimitiveType; - GLenum itype = mesh.IndexType; - size_t count = mesh.IndexCount; - - if (mesh.textures[0]) - { - compressTexture(mesh.textures[0], true); - setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - } - else - { - setTexture(0, 0, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, false); - GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE }; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); - } - MeshShader::ObjectPass1Shader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, 0); - - assert(mesh.vao_first_pass); - glBindVertexArray(mesh.vao_first_pass); - glDrawElements(ptype, count, itype, 0); - - if (!mesh.textures[0]) - { - GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA }; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); - } -} - -void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix) -{ - irr_driver->IncreaseObjectCount(); - GLenum ptype = mesh.PrimitiveType; - GLenum itype = mesh.IndexType; - size_t count = mesh.IndexCount; - - compressTexture(mesh.textures[0], true); - setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - - MeshShader::ObjectRefPass1Shader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, TextureMatrix, 0); - - assert(mesh.vao_first_pass); - glBindVertexArray(mesh.vao_first_pass); - glDrawElements(ptype, count, itype, 0); -} - void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, core::vector3df windDir) { irr_driver->IncreaseObjectCount(); @@ -280,26 +230,6 @@ void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio glDrawElements(ptype, count, itype, 0); } -void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelMatrix, const core::matrix4 &InverseModelMatrix) -{ - irr_driver->IncreaseObjectCount(); - GLenum ptype = mesh.PrimitiveType; - GLenum itype = mesh.IndexType; - size_t count = mesh.IndexCount; - - assert(mesh.textures[1]); - compressTexture(mesh.textures[1], false); - setTexture(0, getTextureGLuint(mesh.textures[1]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - compressTexture(mesh.textures[0], true); - setTexture(1, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - - MeshShader::NormalMapShader::setUniforms(ModelMatrix, InverseModelMatrix, 0, 1); - - assert(mesh.vao_first_pass); - glBindVertexArray(mesh.vao_first_pass); - glDrawElements(ptype, count, itype, 0); -} - void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix) { irr_driver->IncreaseObjectCount(); diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 553efd0b5..b30ac6260 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -89,9 +89,22 @@ std::vector GroupedFPSM::MVPSet; template std::vector GroupedFPSM::TIMVSet; -void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView); -void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelMatrix, const core::matrix4 &InverseModelMatrix); -void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix); + +template +void draw(const GLMesh &mesh, GLuint vao, uniforms... Args) +{ + irr_driver->IncreaseObjectCount(); + GLenum ptype = mesh.PrimitiveType; + GLenum itype = mesh.IndexType; + size_t count = mesh.IndexCount; + + Shader::setUniforms(Args...); + + assert(vao); + glBindVertexArray(vao); + glDrawElements(ptype, count, itype, 0); +} + void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, core::vector3df windDir); // Pass 2 shader (ie shaders that outputs final color) diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index 015b8da58..c3215b2ce 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -197,18 +197,9 @@ void STKMeshSceneNode::drawSolidPass1(const GLMesh &mesh, GeometricMaterial type windDir = getWind(); switch (type) { - case FPSM_NORMAL_MAP: - drawNormalPass(mesh, ModelViewProjectionMatrix, TransposeInverseModelView); - break; - case FPSM_ALPHA_REF_TEXTURE: - drawObjectRefPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, mesh.TextureMatrix); - break; case FPSM_GRASS: drawGrassPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, windDir); break; - case FPSM_DEFAULT: - drawObjectPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView); - break; default: assert(0 && "wrong geometric material"); }