From f5a5988967c787f623208de1062b81a62f4fb399 Mon Sep 17 00:00:00 2001 From: vlj Date: Thu, 17 Jul 2014 00:24:09 +0200 Subject: [PATCH] Fix instanced and reenable displace. --- src/graphics/render_geometry.cpp | 4 +- src/graphics/stkanimatedmesh.hpp | 2 +- src/graphics/stkinstancedscenenode.cpp | 66 +++++++++++++------------- src/graphics/stkinstancedscenenode.hpp | 3 +- src/graphics/stkmesh.hpp | 24 ---------- 5 files changed, 36 insertions(+), 63 deletions(-) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 25dc09b5f..69c06d9c8 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -306,7 +306,7 @@ void IrrDriver::renderTransparent() glStencilFunc(GL_ALWAYS, 1, 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); -/* glBindVertexArray(getVAO(EVT_2TCOORDS)); + glBindVertexArray(getVAO(EVT_2TCOORDS)); // Generate displace mask // Use RTT_TMP4 as displace mask irr_driver->getFBO(FBO_TMP1_WITH_DS).Bind(); @@ -360,7 +360,7 @@ void IrrDriver::renderTransparent() irr_driver->getFBO(FBO_COLORS).Bind(); glStencilFunc(GL_EQUAL, 1, 0xFF); m_post_processing->renderPassThrough(m_rtts->getRenderTarget(RTT_DISPLACE)); - glDisable(GL_STENCIL_TEST);*/ + glDisable(GL_STENCIL_TEST); } diff --git a/src/graphics/stkanimatedmesh.hpp b/src/graphics/stkanimatedmesh.hpp index 745554c15..c5c113da0 100644 --- a/src/graphics/stkanimatedmesh.hpp +++ b/src/graphics/stkanimatedmesh.hpp @@ -11,7 +11,7 @@ class STKAnimatedMesh : public irr::scene::CAnimatedMeshSceneNode { protected: bool firstTime; - PtrVector MeshSolidMaterial[FPSM_COUNT]; + PtrVector MeshSolidMaterial[MAT_COUNT]; PtrVector TransparentMesh[TM_COUNT]; std::vector GLmeshes; core::matrix4 ModelViewProjectionMatrix; diff --git a/src/graphics/stkinstancedscenenode.cpp b/src/graphics/stkinstancedscenenode.cpp index 7a9dc9501..27ae172df 100644 --- a/src/graphics/stkinstancedscenenode.cpp +++ b/src/graphics/stkinstancedscenenode.cpp @@ -99,11 +99,9 @@ void STKInstancedSceneNode::setFirstTimeMaterial() video::E_MATERIAL_TYPE type = mb->getMaterial().MaterialType; GLMesh &mesh = GLmeshes[i]; - GeometricMaterial GeometricType;// = MaterialTypeToGeometricMaterial(type, mb->getVertexType()); - ShadedMaterial ShadedType;// = MaterialTypeToShadedMaterial(type, mesh.textures, mb->getVertexType()); + MeshMaterial MatType = MaterialTypeToMeshMaterial(type, mb->getVertexType()); initinstancedvaostate(mesh); - GeometricMesh[GeometricType].push_back(&mesh); - ShadedMesh[ShadedType].push_back(&mesh); + MeshSolidMaterial[MatType].push_back(&mesh); } isMaterialInitialized = true; } @@ -224,7 +222,7 @@ static void drawFSPMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t i glDrawElementsInstanced(ptype, count, itype, 0, instance_count); } -static void drawSMDefault(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count) +static void drawSMDefault(GLMesh &mesh, size_t instance_count) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; @@ -249,7 +247,7 @@ static void drawSMDefault(GLMesh &mesh, const core::matrix4 &ModelViewProjection glDrawElementsInstanced(ptype, count, itype, 0, instance_count); } -static void drawSMAlphaRefTexture(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count) +static void drawSMAlphaRefTexture(GLMesh &mesh, size_t instance_count) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; @@ -275,7 +273,7 @@ static void drawSMAlphaRefTexture(GLMesh &mesh, const core::matrix4 &ModelViewPr glDrawElementsInstanced(ptype, count, itype, 0, instance_count); } -static void drawSMGrass(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDir, size_t instance_count) +static void drawSMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t instance_count) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; @@ -318,59 +316,59 @@ void STKInstancedSceneNode::render() ModelViewProjectionMatrix = irr_driver->getProjMatrix(); ModelViewProjectionMatrix *= irr_driver->getViewMatrix(); - if (!GeometricMesh[FPSM_DEFAULT_STANDARD].empty()) + if (!MeshSolidMaterial[MAT_DEFAULT].empty()) glUseProgram(MeshShader::InstancedObjectPass1ShaderInstance->Program); - for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT_STANDARD].size(); i++) - drawFSPMDefault(*GeometricMesh[FPSM_DEFAULT_STANDARD][i], instance_pos.size() / 9); + for (unsigned i = 0; i < MeshSolidMaterial[MAT_DEFAULT].size(); i++) + drawFSPMDefault(*MeshSolidMaterial[MAT_DEFAULT][i], instance_pos.size() / 9); - if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty()) + if (!MeshSolidMaterial[MAT_ALPHA_REF].empty()) glUseProgram(MeshShader::InstancedObjectRefPass1ShaderInstance->Program); - for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++) - drawFSPMAlphaRefTexture(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], instance_pos.size() / 9); + for (unsigned i = 0; i < MeshSolidMaterial[MAT_ALPHA_REF].size(); i++) + drawFSPMAlphaRefTexture(*MeshSolidMaterial[MAT_ALPHA_REF][i], instance_pos.size() / 9); windDir = getWind(); - if (!GeometricMesh[FPSM_GRASS].empty()) + if (!MeshSolidMaterial[MAT_GRASS].empty()) glUseProgram(MeshShader::InstancedGrassPass1ShaderInstance->Program); - for (unsigned i = 0; i < GeometricMesh[FPSM_GRASS].size(); i++) - drawFSPMGrass(*GeometricMesh[FPSM_GRASS][i], windDir, instance_pos.size() / 9); + for (unsigned i = 0; i < MeshSolidMaterial[MAT_GRASS].size(); i++) + drawFSPMGrass(*MeshSolidMaterial[MAT_GRASS][i], windDir, instance_pos.size() / 9); return; } if (irr_driver->getPhase() == SOLID_LIT_PASS) { - if (!ShadedMesh[SM_DEFAULT_STANDARD].empty()) + if (!MeshSolidMaterial[MAT_DEFAULT].empty()) glUseProgram(MeshShader::InstancedObjectPass2ShaderInstance->Program); - for (unsigned i = 0; i < ShadedMesh[SM_DEFAULT_STANDARD].size(); i++) - drawSMDefault(*ShadedMesh[SM_DEFAULT_STANDARD][i], ModelViewProjectionMatrix, instance_pos.size() / 9); + for (unsigned i = 0; i < MeshSolidMaterial[MAT_DEFAULT].size(); i++) + drawSMDefault(*MeshSolidMaterial[MAT_DEFAULT][i], instance_pos.size() / 9); - if (!ShadedMesh[SM_ALPHA_REF_TEXTURE].empty()) + if (!MeshSolidMaterial[MAT_ALPHA_REF].empty()) glUseProgram(MeshShader::InstancedObjectRefPass2ShaderInstance->Program); - for (unsigned i = 0; i < ShadedMesh[SM_ALPHA_REF_TEXTURE].size(); i++) - drawSMAlphaRefTexture(*ShadedMesh[SM_ALPHA_REF_TEXTURE][i], ModelViewProjectionMatrix, instance_pos.size() / 9); + for (unsigned i = 0; i < MeshSolidMaterial[MAT_ALPHA_REF].size(); i++) + drawSMAlphaRefTexture(*MeshSolidMaterial[MAT_ALPHA_REF][i], instance_pos.size() / 9); - if (!ShadedMesh[SM_GRASS].empty()) + if (!MeshSolidMaterial[MAT_GRASS].empty()) glUseProgram(MeshShader::InstancedGrassPass2ShaderInstance->Program); - for (unsigned i = 0; i < ShadedMesh[SM_GRASS].size(); i++) - drawSMGrass(*ShadedMesh[SM_GRASS][i], ModelViewProjectionMatrix, windDir, instance_pos.size() / 9); + for (unsigned i = 0; i < MeshSolidMaterial[MAT_GRASS].size(); i++) + drawSMGrass(*MeshSolidMaterial[MAT_GRASS][i], windDir, instance_pos.size() / 9); return; } if (irr_driver->getPhase() == SHADOW_PASS) { - if (!GeometricMesh[FPSM_DEFAULT_STANDARD].empty()) + if (!MeshSolidMaterial[MAT_DEFAULT].empty()) glUseProgram(MeshShader::InstancedShadowShaderInstance->Program); - for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT_STANDARD].size(); i++) - drawShadowDefault(*GeometricMesh[FPSM_DEFAULT_STANDARD][i], instance_pos.size() / 9); + for (unsigned i = 0; i < MeshSolidMaterial[MAT_DEFAULT].size(); i++) + drawShadowDefault(*MeshSolidMaterial[MAT_DEFAULT][i], instance_pos.size() / 9); - if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty()) + if (!MeshSolidMaterial[MAT_ALPHA_REF].empty()) glUseProgram(MeshShader::InstancedRefShadowShaderInstance->Program); - for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++) - drawShadowAlphaRefTexture(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], instance_pos.size() / 9); + for (unsigned i = 0; i < MeshSolidMaterial[MAT_ALPHA_REF].size(); i++) + drawShadowAlphaRefTexture(*MeshSolidMaterial[MAT_ALPHA_REF][i], instance_pos.size() / 9); - if (!GeometricMesh[FPSM_GRASS].empty()) + if (!MeshSolidMaterial[MAT_GRASS].empty()) glUseProgram(MeshShader::InstancedGrassShadowShaderInstance->Program); - for (unsigned i = 0; i < GeometricMesh[FPSM_GRASS].size(); i++) - drawShadowGrass(*GeometricMesh[FPSM_GRASS][i], windDir, instance_pos.size() / 9); + for (unsigned i = 0; i < MeshSolidMaterial[MAT_GRASS].size(); i++) + drawShadowGrass(*MeshSolidMaterial[MAT_GRASS][i], windDir, instance_pos.size() / 9); return; } } diff --git a/src/graphics/stkinstancedscenenode.hpp b/src/graphics/stkinstancedscenenode.hpp index c626415de..5d9bbb784 100644 --- a/src/graphics/stkinstancedscenenode.hpp +++ b/src/graphics/stkinstancedscenenode.hpp @@ -8,8 +8,7 @@ class STKInstancedSceneNode : public irr::scene::CMeshSceneNode { protected: int m_ref_count; - std::vector GeometricMesh[FPSM_COUNT]; - std::vector ShadedMesh[SM_COUNT]; + std::vector MeshSolidMaterial[MAT_COUNT]; std::vector GLmeshes; std::vector instance_pos; core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView; diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 2e87d65ed..5d8774851 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -11,30 +11,6 @@ #include #include -enum GeometricMaterial - -{ - FPSM_DEFAULT_STANDARD, - FPSM_DEFAULT_2TCOORD, - FPSM_ALPHA_REF_TEXTURE, - FPSM_NORMAL_MAP, - FPSM_GRASS, - FPSM_COUNT -}; - -enum ShadedMaterial -{ - SM_DEFAULT_STANDARD, - SM_DEFAULT_TANGENT, - SM_ALPHA_REF_TEXTURE, - SM_SPHEREMAP, - SM_SPLATTING, - SM_GRASS, - SM_UNLIT, - SM_DETAILS, - SM_COUNT -}; - enum MeshMaterial { MAT_DEFAULT,