From f30ea823e5e096f2f112bc7046c4e6a993ae4333 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 20 Sep 2014 19:43:15 +0200 Subject: [PATCH] Factorise non instanced 2nd pass too. --- src/graphics/render_geometry.cpp | 69 ++++++++++++++------------------ 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 041608e8d..db8e9ee35 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -82,6 +82,7 @@ struct DefaultMaterial typedef MeshShader::InstancedObjectPass2Shader InstancedSecondPassShader; typedef ListInstancedMatDefault InstancedList; typedef MeshShader::ObjectPass1Shader FirstPassShader; + typedef MeshShader::ObjectPass2Shader SecondPassShader; typedef ListMatDefault List; static const enum E_VERTEX_TYPE VertexType = video::EVT_STANDARD; static const enum MeshMaterial MaterialType = MAT_DEFAULT; @@ -99,6 +100,7 @@ struct AlphaRef typedef MeshShader::InstancedObjectRefPass2Shader InstancedSecondPassShader; typedef ListInstancedMatAlphaRef InstancedList; typedef MeshShader::ObjectRefPass1Shader FirstPassShader; + typedef MeshShader::ObjectRefPass2Shader SecondPassShader; typedef ListMatAlphaRef List; static const enum E_VERTEX_TYPE VertexType = video::EVT_STANDARD; static const enum MeshMaterial MaterialType = MAT_ALPHA_REF; @@ -116,6 +118,7 @@ struct SphereMap typedef MeshShader::InstancedSphereMapShader InstancedSecondPassShader; typedef ListInstancedMatSphereMap InstancedList; typedef MeshShader::ObjectPass1Shader FirstPassShader; + typedef MeshShader::SphereMapShader SecondPassShader; typedef ListMatSphereMap List; static const enum E_VERTEX_TYPE VertexType = video::EVT_STANDARD; static const enum MeshMaterial MaterialType = MAT_SPHEREMAP; @@ -133,6 +136,7 @@ struct UnlitMat typedef MeshShader::InstancedObjectUnlitShader InstancedSecondPassShader; typedef ListInstancedMatUnlit InstancedList; typedef MeshShader::ObjectRefPass1Shader FirstPassShader; + typedef MeshShader::ObjectUnlitShader SecondPassShader; typedef ListMatUnlit List; static const enum E_VERTEX_TYPE VertexType = video::EVT_STANDARD; static const enum MeshMaterial MaterialType = MAT_UNLIT; @@ -150,6 +154,7 @@ struct GrassMat typedef MeshShader::InstancedGrassPass2Shader InstancedSecondPassShader; typedef ListInstancedMatGrass InstancedList; typedef MeshShader::GrassPass1Shader FirstPassShader; + typedef MeshShader::GrassPass2Shader SecondPassShader; typedef ListMatGrass List; static const enum E_VERTEX_TYPE VertexType = video::EVT_STANDARD; static const enum MeshMaterial MaterialType = MAT_GRASS; @@ -167,6 +172,7 @@ struct NormalMat typedef MeshShader::InstancedObjectPass2Shader InstancedSecondPassShader; typedef ListInstancedMatNormalMap InstancedList; typedef MeshShader::NormalMapShader FirstPassShader; + typedef MeshShader::ObjectPass2Shader SecondPassShader; typedef ListMatNormalMap List; static const enum E_VERTEX_TYPE VertexType = video::EVT_TANGENTS; static const enum MeshMaterial MaterialType = MAT_NORMAL_MAP; @@ -184,6 +190,7 @@ struct DetailMat typedef MeshShader::InstancedDetailledObjectPass2Shader InstancedSecondPassShader; typedef ListInstancedMatDetails InstancedList; typedef MeshShader::ObjectPass1Shader FirstPassShader; + typedef MeshShader::DetailledObjectPass2Shader SecondPassShader; typedef ListMatDetails List; static const enum E_VERTEX_TYPE VertexType = video::EVT_2TCOORDS; static const enum MeshMaterial MaterialType = MAT_DETAIL; @@ -198,6 +205,7 @@ const std::vector DetailMat::SecondPassTextures = { 0, 2 }; struct SplattingMat { typedef MeshShader::ObjectPass1Shader FirstPassShader; + typedef MeshShader::SplattingShader SecondPassShader; typedef ListMatSplatting List; static const enum E_VERTEX_TYPE VertexType = video::EVT_2TCOORDS; static const std::vector FirstPassTextures; @@ -205,6 +213,7 @@ struct SplattingMat }; const std::vector SplattingMat::FirstPassTextures = { 1 }; +const std::vector SplattingMat::SecondPassTextures = { 1, 2, 3, 4, 0 }; namespace RenderGeometry { @@ -416,13 +425,15 @@ void IrrDriver::renderSolidFirstPass() } } -template -void renderMeshes2ndPass(const std::vector &TexUnits, std::vector > &meshes, const std::vector &Prefilled_Handle, +template +void renderMeshes2ndPass( const std::vector &Prefilled_Handle, const std::vector &Prefilled_Tex) { - glUseProgram(Shader::getInstance()->Program); + const std::vector &TexUnits = T::SecondPassTextures; + auto &meshes = T::List::getInstance()->SolidPass; + glUseProgram(T::SecondPassShader::getInstance()->Program); if (irr_driver->hasARB_base_instance()) - glBindVertexArray(VAOManager::getInstance()->getVAO(VertexType)); + glBindVertexArray(VAOManager::getInstance()->getVAO(T::VertexType)); for (unsigned i = 0; i < meshes.size(); i++) { std::vector Handles(Prefilled_Handle); @@ -433,12 +444,12 @@ void renderMeshes2ndPass(const std::vector &TexUnits, std::vectorgetName().getPath().c_str()); @@ -447,10 +458,10 @@ void renderMeshes2ndPass(const std::vector &TexUnits, std::vectorSetTextureHandles(Handles); + T::SecondPassShader::getInstance()->SetTextureHandles(Handles); else - Shader::getInstance()->SetTextureUnits(Textures); - custom_unroll_args::template exec(Shader::getInstance(), meshes.at(i)); + T::SecondPassShader::getInstance()->SetTextureUnits(Textures); + custom_unroll_args::template exec(T::SecondPassShader::getInstance(), meshes.at(i)); } } @@ -526,36 +537,14 @@ void IrrDriver::renderSolidSecondPass() std::vector DiffSpecSSAOTex = createVector(m_rtts->getRenderTarget(RTT_DIFFUSE), m_rtts->getRenderTarget(RTT_SPECULAR), m_rtts->getRenderTarget(RTT_HALF1_R)); - renderMeshes2ndPass(TexUnits( - TexUnit(0, true) - ), ListMatDefault::getInstance()->SolidPass, - createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); - renderMeshes2ndPass(TexUnits( - TexUnit(0, true) - ), ListMatAlphaRef::getInstance()->SolidPass, createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); - renderMeshes2ndPass(TexUnits( - TexUnit(0, true) - ), ListMatUnlit::getInstance()->SolidPass, createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); - renderMeshes2ndPass(TexUnits( - TexUnit(1, false), - TexUnit(2, true), - TexUnit(3, true), - TexUnit(4, true), - TexUnit(0, true) - ), ListMatSplatting::getInstance()->SolidPass, createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); - renderMeshes2ndPass(TexUnits( - TexUnit(0, true) - ), ListMatSphereMap::getInstance()->SolidPass, createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); - renderMeshes2ndPass(TexUnits( - TexUnit(0, true), - TexUnit(1, true) - ), ListMatDetails::getInstance()->SolidPass, createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); - renderMeshes2ndPass(TexUnits( - TexUnit(0, true) - ), ListMatGrass::getInstance()->SolidPass, createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); - renderMeshes2ndPass(TexUnits( - TexUnit(0, true) - ), ListMatNormalMap::getInstance()->SolidPass, createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); + renderMeshes2ndPass(createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); + renderMeshes2ndPass(createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); + renderMeshes2ndPass(createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); + renderMeshes2ndPass(createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); + renderMeshes2ndPass(createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); + renderMeshes2ndPass(createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); + renderMeshes2ndPass(createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); + renderMeshes2ndPass(createVector(DiffuseHandle, SpecularHandle, SSAOHandle), DiffSpecSSAOTex); if (UserConfigParams::m_azdo) {