Permalink
Browse files

Factorize transparent mesh rendering.

  • Loading branch information...
1 parent eaded3b commit 4c9d1888f89fc84baa2059640cb538b7413a5ce0 Vincent Lejeune committed Jun 20, 2014
Showing with 61 additions and 43 deletions.
  1. +23 −0 src/graphics/render.cpp
  2. +7 −21 src/graphics/stkanimatedmesh.cpp
  3. +19 −0 src/graphics/stkmesh.hpp
  4. +12 −22 src/graphics/stkmeshscenenode.cpp
View
@@ -648,7 +648,30 @@ void IrrDriver::renderTransparent()
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glDisable(GL_CULL_FACE);
+ TransparentMeshes<TM_DEFAULT>::reset();
+ TransparentMeshes<TM_ADDITIVE>::reset();
m_scene_manager->drawAll(scene::ESNRP_TRANSPARENT);
+
+ if (World::getWorld() && World::getWorld()->isFogEnabled())
+ {
+ glUseProgram(MeshShader::TransparentFogShader::Program);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ for (unsigned i = 0; i < TransparentMeshes<TM_DEFAULT>::MeshSet.size(); i++)
+ drawTransparentFogObject(*TransparentMeshes<TM_DEFAULT>::MeshSet[i], TransparentMeshes<TM_DEFAULT>::MVPSet[i], TransparentMeshes<TM_DEFAULT>::MeshSet[i]->TextureMatrix);
+ glBlendFunc(GL_ONE, GL_ONE);
+ for (unsigned i = 0; i < TransparentMeshes<TM_ADDITIVE>::MeshSet.size(); i++)
+ drawTransparentFogObject(*TransparentMeshes<TM_ADDITIVE>::MeshSet[i], TransparentMeshes<TM_ADDITIVE>::MVPSet[i], TransparentMeshes<TM_ADDITIVE>::MeshSet[i]->TextureMatrix);
+ }
+ else
+ {
+ glUseProgram(MeshShader::TransparentShader::Program);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ for (unsigned i = 0; i < TransparentMeshes<TM_DEFAULT>::MeshSet.size(); i++)
+ drawTransparentObject(*TransparentMeshes<TM_DEFAULT>::MeshSet[i], TransparentMeshes<TM_DEFAULT>::MVPSet[i], TransparentMeshes<TM_DEFAULT>::MeshSet[i]->TextureMatrix);
+ glBlendFunc(GL_ONE, GL_ONE);
+ for (unsigned i = 0; i < TransparentMeshes<TM_ADDITIVE>::MeshSet.size(); i++)
+ drawTransparentObject(*TransparentMeshes<TM_ADDITIVE>::MeshSet[i], TransparentMeshes<TM_ADDITIVE>::MVPSet[i], TransparentMeshes<TM_ADDITIVE>::MeshSet[i]->TextureMatrix);
+ }
}
void IrrDriver::renderParticles()
@@ -227,30 +227,16 @@ void STKAnimatedMesh::render()
glUseProgram(MeshShader::BubbleShader::Program);
GLMesh* mesh;
- for_in(mesh, TransparentMesh[TM_BUBBLE])
- drawBubble(*mesh, ModelViewProjectionMatrix);
-
- if (World::getWorld() != NULL && World::getWorld()->isFogEnabled())
+ for_in(mesh, TransparentMesh[TM_DEFAULT])
{
- if (!TransparentMesh[TM_DEFAULT].empty() || !TransparentMesh[TM_ADDITIVE].empty())
- glUseProgram(MeshShader::TransparentFogShader::Program);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- for_in(mesh, TransparentMesh[TM_DEFAULT])
- drawTransparentFogObject(*mesh, ModelViewProjectionMatrix, mesh->TextureMatrix);
- glBlendFunc(GL_ONE, GL_ONE);
- for_in(mesh, TransparentMesh[TM_ADDITIVE])
- drawTransparentFogObject(*mesh, ModelViewProjectionMatrix, mesh->TextureMatrix);
+ TransparentMeshes<TM_DEFAULT>::MeshSet.push_back(mesh);
+ TransparentMeshes<TM_DEFAULT>::MVPSet.push_back(ModelViewProjectionMatrix);
}
- else
+
+ for_in(mesh, TransparentMesh[TM_ADDITIVE])
{
- if (!TransparentMesh[TM_DEFAULT].empty() || !TransparentMesh[TM_ADDITIVE].empty())
- glUseProgram(MeshShader::TransparentShader::Program);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- for_in(mesh, TransparentMesh[TM_DEFAULT])
- drawTransparentObject(*mesh, ModelViewProjectionMatrix, mesh->TextureMatrix);
- glBlendFunc(GL_ONE, GL_ONE);
- for_in(mesh, TransparentMesh[TM_ADDITIVE])
- drawTransparentObject(*mesh, ModelViewProjectionMatrix, mesh->TextureMatrix);
+ TransparentMeshes<TM_ADDITIVE>::MeshSet.push_back(mesh);
+ TransparentMeshes<TM_ADDITIVE>::MVPSet.push_back(ModelViewProjectionMatrix);
}
return;
}
View
@@ -147,6 +147,25 @@ void drawObjectUnlit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectio
void drawShadowRef(const GLMesh &mesh, const core::matrix4 &ModelMatrix);
void drawShadow(const GLMesh &mesh, const core::matrix4 &ModelMatrix);
+template<enum TransparentMaterial T>
+class TransparentMeshes
+{
+public:
+ static std::vector<GLMesh *> MeshSet;
+ static std::vector<core::matrix4> MVPSet;
+
+ static void reset()
+ {
+ MeshSet.clear();
+ MVPSet.clear();
+ }
+};
+
+template<enum TransparentMaterial T>
+std::vector<GLMesh *> TransparentMeshes<T>::MeshSet;
+template<enum TransparentMaterial T>
+std::vector<core::matrix4> TransparentMeshes<T>::MVPSet;
+
// Forward pass (for transparents meshes)
void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
@@ -440,33 +440,23 @@ void STKMeshSceneNode::render()
ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation);
GLMesh* mesh;
- if (!TransparentMesh[TM_BUBBLE].empty())
- glUseProgram(MeshShader::BubbleShader::Program);
- for_in(mesh, TransparentMesh[TM_BUBBLE])
- drawBubble(*mesh, ModelViewProjectionMatrix);
- if (World::getWorld() ->isFogEnabled())
+ for_in(mesh, TransparentMesh[TM_DEFAULT])
{
- if (!TransparentMesh[TM_DEFAULT].empty() || !TransparentMesh[TM_ADDITIVE].empty())
- glUseProgram(MeshShader::TransparentFogShader::Program);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- for_in(mesh, TransparentMesh[TM_DEFAULT])
- drawTransparentFogObject(*mesh, ModelViewProjectionMatrix, (*mesh).TextureMatrix);
- glBlendFunc(GL_ONE, GL_ONE);
- for_in(mesh, TransparentMesh[TM_ADDITIVE])
- drawTransparentFogObject(*mesh, ModelViewProjectionMatrix, (*mesh).TextureMatrix);
+ TransparentMeshes<TM_DEFAULT>::MeshSet.push_back(mesh);
+ TransparentMeshes<TM_DEFAULT>::MVPSet.push_back(ModelViewProjectionMatrix);
}
- else
+
+ for_in(mesh, TransparentMesh[TM_ADDITIVE])
{
- if (!TransparentMesh[TM_DEFAULT].empty() || !TransparentMesh[TM_ADDITIVE].empty())
- glUseProgram(MeshShader::TransparentShader::Program);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- for_in(mesh, TransparentMesh[TM_DEFAULT])
- drawTransparentObject(*mesh, ModelViewProjectionMatrix, (*mesh).TextureMatrix);
- glBlendFunc(GL_ONE, GL_ONE);
- for_in(mesh, TransparentMesh[TM_ADDITIVE])
- drawTransparentObject(*mesh, ModelViewProjectionMatrix, (*mesh).TextureMatrix);
+ TransparentMeshes<TM_ADDITIVE>::MeshSet.push_back(mesh);
+ TransparentMeshes<TM_ADDITIVE>::MVPSet.push_back(ModelViewProjectionMatrix);
}
+
+ if (!TransparentMesh[TM_BUBBLE].empty())
+ glUseProgram(MeshShader::BubbleShader::Program);
+ for_in(mesh, TransparentMesh[TM_BUBBLE])
+ drawBubble(*mesh, ModelViewProjectionMatrix);
return;
}

0 comments on commit 4c9d188

Please sign in to comment.