From 2da28b22b7938b95d63fcd620d3c44497accc5de Mon Sep 17 00:00:00 2001 From: Elderme Date: Fri, 1 Jul 2016 23:15:08 +0200 Subject: [PATCH] Do not create CommandBuffers when Indirect Instancing Rendering is not available. --- src/graphics/draw_calls.cpp | 194 ++++++++++++++++++--------------- src/graphics/draw_calls.hpp | 11 +- src/graphics/draw_policies.cpp | 34 +++--- 3 files changed, 132 insertions(+), 107 deletions(-) diff --git a/src/graphics/draw_calls.cpp b/src/graphics/draw_calls.cpp index 5009a146a..0c0e8ddee 100644 --- a/src/graphics/draw_calls.cpp +++ b/src/graphics/draw_calls.cpp @@ -455,6 +455,28 @@ void DrawCalls::parseSceneManager(core::list &List, } } +// ---------------------------------------------------------------------------- +DrawCalls::DrawCalls() +{ + if(CVS->supportsIndirectInstancingRendering()) + { + m_solid_cmd_buffer = new SolidCommandBuffer(); + m_shadow_cmd_buffer = new ShadowCommandBuffer(); + m_reflective_shadow_map_cmd_buffer = new ReflectiveShadowMapCommandBuffer(); + m_glow_cmd_buffer = new GlowCommandBuffer(); + } +} //DrawCalls + +DrawCalls::~DrawCalls() +{ + delete m_solid_cmd_buffer; + delete m_shadow_cmd_buffer; + delete m_reflective_shadow_map_cmd_buffer; + delete m_glow_cmd_buffer; +} //~DrawCalls + + + // ---------------------------------------------------------------------------- /** Prepare draw calls before scene rendering * \param[out] solid_poly_count Total number of polygons in objects @@ -549,26 +571,26 @@ void DrawCalls::prepareDrawCalls( ShadowMatrices& shadow_matrices, { #pragma omp section { - m_solid_cmd_buffer.fill(m_solid_pass_mesh); + m_solid_cmd_buffer->fill(m_solid_pass_mesh); } #pragma omp section { - m_glow_cmd_buffer.fill(&m_glow_pass_mesh); + m_glow_cmd_buffer->fill(&m_glow_pass_mesh); } #pragma omp section { irr_driver->setPhase(SHADOW_PASS); - m_shadow_cmd_buffer.fill(m_shadow_pass_mesh); + m_shadow_cmd_buffer->fill(m_shadow_pass_mesh); } #pragma omp section if (!shadow_matrices.isRSMMapAvail()) { - m_reflective_shadow_map_cmd_buffer.fill(m_reflective_shadow_map_mesh); + m_reflective_shadow_map_cmd_buffer->fill(m_reflective_shadow_map_mesh); } } PROFILER_POP_CPU_MARKER(); - solid_poly_count = m_solid_cmd_buffer.getPolyCount(); - shadow_poly_count = m_shadow_cmd_buffer.getPolyCount(); + solid_poly_count = m_solid_cmd_buffer->getPolyCount(); + shadow_poly_count = m_shadow_cmd_buffer->getPolyCount(); if (CVS->supportsAsyncInstanceUpload()) glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT); @@ -605,14 +627,14 @@ void DrawCalls::renderParticlesList() const */ void DrawCalls::drawIndirectSolidFirstPass() const { - m_solid_cmd_buffer.bind(); - m_solid_cmd_buffer.drawIndirectFirstPass(); - m_solid_cmd_buffer.drawIndirectFirstPass(); - m_solid_cmd_buffer.drawIndirectFirstPass(); - m_solid_cmd_buffer.drawIndirectFirstPass(); - m_solid_cmd_buffer.drawIndirectFirstPass(m_wind_dir); - m_solid_cmd_buffer.drawIndirectFirstPass(); - m_solid_cmd_buffer.drawIndirectFirstPass(); + m_solid_cmd_buffer->bind(); + m_solid_cmd_buffer->drawIndirectFirstPass(); + m_solid_cmd_buffer->drawIndirectFirstPass(); + m_solid_cmd_buffer->drawIndirectFirstPass(); + m_solid_cmd_buffer->drawIndirectFirstPass(); + m_solid_cmd_buffer->drawIndirectFirstPass(m_wind_dir); + m_solid_cmd_buffer->drawIndirectFirstPass(); + m_solid_cmd_buffer->drawIndirectFirstPass(); } // ---------------------------------------------------------------------------- @@ -621,14 +643,14 @@ void DrawCalls::drawIndirectSolidFirstPass() const */ void DrawCalls::multidrawSolidFirstPass() const { - m_solid_cmd_buffer.bind(); - m_solid_cmd_buffer.multidrawFirstPass(); - m_solid_cmd_buffer.multidrawFirstPass(); - m_solid_cmd_buffer.multidrawFirstPass(); - m_solid_cmd_buffer.multidrawFirstPass(); - m_solid_cmd_buffer.multidrawFirstPass(m_wind_dir); - m_solid_cmd_buffer.multidrawFirstPass(); - m_solid_cmd_buffer.multidrawFirstPass(); + m_solid_cmd_buffer->bind(); + m_solid_cmd_buffer->multidrawFirstPass(); + m_solid_cmd_buffer->multidrawFirstPass(); + m_solid_cmd_buffer->multidrawFirstPass(); + m_solid_cmd_buffer->multidrawFirstPass(); + m_solid_cmd_buffer->multidrawFirstPass(m_wind_dir); + m_solid_cmd_buffer->multidrawFirstPass(); + m_solid_cmd_buffer->multidrawFirstPass(); } // ---------------------------------------------------------------------------- @@ -640,14 +662,14 @@ void DrawCalls::multidrawSolidFirstPass() const */ void DrawCalls::drawIndirectSolidSecondPass(const std::vector &prefilled_tex) const { - m_solid_cmd_buffer.bind(); - m_solid_cmd_buffer.drawIndirectSecondPass(prefilled_tex); - m_solid_cmd_buffer.drawIndirectSecondPass(prefilled_tex); - m_solid_cmd_buffer.drawIndirectSecondPass(prefilled_tex); - m_solid_cmd_buffer.drawIndirectSecondPass(prefilled_tex); - m_solid_cmd_buffer.drawIndirectSecondPass(prefilled_tex, m_wind_dir); - m_solid_cmd_buffer.drawIndirectSecondPass(prefilled_tex); - m_solid_cmd_buffer.drawIndirectSecondPass(prefilled_tex); + m_solid_cmd_buffer->bind(); + m_solid_cmd_buffer->drawIndirectSecondPass(prefilled_tex); + m_solid_cmd_buffer->drawIndirectSecondPass(prefilled_tex); + m_solid_cmd_buffer->drawIndirectSecondPass(prefilled_tex); + m_solid_cmd_buffer->drawIndirectSecondPass(prefilled_tex); + m_solid_cmd_buffer->drawIndirectSecondPass(prefilled_tex, m_wind_dir); + m_solid_cmd_buffer->drawIndirectSecondPass(prefilled_tex); + m_solid_cmd_buffer->drawIndirectSecondPass(prefilled_tex); } // ---------------------------------------------------------------------------- @@ -658,14 +680,14 @@ void DrawCalls::drawIndirectSolidSecondPass(const std::vector &prefilled */ void DrawCalls::multidrawSolidSecondPass(const std::vector &handles) const { - m_solid_cmd_buffer.bind(); - m_solid_cmd_buffer.multidraw2ndPass(handles); - m_solid_cmd_buffer.multidraw2ndPass(handles); - m_solid_cmd_buffer.multidraw2ndPass(handles); - m_solid_cmd_buffer.multidraw2ndPass(handles); - m_solid_cmd_buffer.multidraw2ndPass(handles); - m_solid_cmd_buffer.multidraw2ndPass(handles); - m_solid_cmd_buffer.multidraw2ndPass(handles, m_wind_dir); + m_solid_cmd_buffer->bind(); + m_solid_cmd_buffer->multidraw2ndPass(handles); + m_solid_cmd_buffer->multidraw2ndPass(handles); + m_solid_cmd_buffer->multidraw2ndPass(handles); + m_solid_cmd_buffer->multidraw2ndPass(handles); + m_solid_cmd_buffer->multidraw2ndPass(handles); + m_solid_cmd_buffer->multidraw2ndPass(handles); + m_solid_cmd_buffer->multidraw2ndPass(handles, m_wind_dir); } // ---------------------------------------------------------------------------- @@ -675,13 +697,13 @@ void DrawCalls::multidrawSolidSecondPass(const std::vector &handles) c */ void DrawCalls::drawIndirectNormals() const { - m_solid_cmd_buffer.bind(); - m_solid_cmd_buffer.drawIndirectNormals(); - m_solid_cmd_buffer.drawIndirectNormals(); - m_solid_cmd_buffer.drawIndirectNormals(); - m_solid_cmd_buffer.drawIndirectNormals(); - m_solid_cmd_buffer.drawIndirectNormals(); - m_solid_cmd_buffer.drawIndirectNormals(); + m_solid_cmd_buffer->bind(); + m_solid_cmd_buffer->drawIndirectNormals(); + m_solid_cmd_buffer->drawIndirectNormals(); + m_solid_cmd_buffer->drawIndirectNormals(); + m_solid_cmd_buffer->drawIndirectNormals(); + m_solid_cmd_buffer->drawIndirectNormals(); + m_solid_cmd_buffer->drawIndirectNormals(); } // ---------------------------------------------------------------------------- @@ -690,13 +712,13 @@ void DrawCalls::drawIndirectNormals() const */ void DrawCalls::multidrawNormals() const { - m_solid_cmd_buffer.bind(); - m_solid_cmd_buffer.multidrawNormals(); - m_solid_cmd_buffer.multidrawNormals(); - m_solid_cmd_buffer.multidrawNormals(); - m_solid_cmd_buffer.multidrawNormals(); - m_solid_cmd_buffer.multidrawNormals(); - m_solid_cmd_buffer.multidrawNormals(); + m_solid_cmd_buffer->bind(); + m_solid_cmd_buffer->multidrawNormals(); + m_solid_cmd_buffer->multidrawNormals(); + m_solid_cmd_buffer->multidrawNormals(); + m_solid_cmd_buffer->multidrawNormals(); + m_solid_cmd_buffer->multidrawNormals(); + m_solid_cmd_buffer->multidrawNormals(); } // ---------------------------------------------------------------------------- @@ -707,15 +729,15 @@ void DrawCalls::multidrawNormals() const */ void DrawCalls::drawIndirectShadows(unsigned cascade) const { - m_shadow_cmd_buffer.bind(); - m_shadow_cmd_buffer.drawIndirect(cascade); - m_shadow_cmd_buffer.drawIndirect(cascade); - m_shadow_cmd_buffer.drawIndirect(cascade); - m_shadow_cmd_buffer.drawIndirect(cascade); - m_shadow_cmd_buffer.drawIndirect(cascade, m_wind_dir); - m_shadow_cmd_buffer.drawIndirect(cascade); - m_shadow_cmd_buffer.drawIndirect(cascade); - m_shadow_cmd_buffer.drawIndirect(cascade); + m_shadow_cmd_buffer->bind(); + m_shadow_cmd_buffer->drawIndirect(cascade); + m_shadow_cmd_buffer->drawIndirect(cascade); + m_shadow_cmd_buffer->drawIndirect(cascade); + m_shadow_cmd_buffer->drawIndirect(cascade); + m_shadow_cmd_buffer->drawIndirect(cascade, m_wind_dir); + m_shadow_cmd_buffer->drawIndirect(cascade); + m_shadow_cmd_buffer->drawIndirect(cascade); + m_shadow_cmd_buffer->drawIndirect(cascade); } // ---------------------------------------------------------------------------- @@ -725,15 +747,15 @@ void DrawCalls::drawIndirectShadows(unsigned cascade) const */ void DrawCalls::multidrawShadows(unsigned cascade) const { - m_shadow_cmd_buffer.bind(); - m_shadow_cmd_buffer.multidrawShadow(cascade); - m_shadow_cmd_buffer.multidrawShadow(cascade); - m_shadow_cmd_buffer.multidrawShadow(cascade); - m_shadow_cmd_buffer.multidrawShadow(cascade); - m_shadow_cmd_buffer.multidrawShadow(cascade); - m_shadow_cmd_buffer.multidrawShadow(cascade, m_wind_dir); - m_shadow_cmd_buffer.multidrawShadow(cascade); - m_shadow_cmd_buffer.multidrawShadow(cascade); + m_shadow_cmd_buffer->bind(); + m_shadow_cmd_buffer->multidrawShadow(cascade); + m_shadow_cmd_buffer->multidrawShadow(cascade); + m_shadow_cmd_buffer->multidrawShadow(cascade); + m_shadow_cmd_buffer->multidrawShadow(cascade); + m_shadow_cmd_buffer->multidrawShadow(cascade); + m_shadow_cmd_buffer->multidrawShadow(cascade, m_wind_dir); + m_shadow_cmd_buffer->multidrawShadow(cascade); + m_shadow_cmd_buffer->multidrawShadow(cascade); } // ---------------------------------------------------------------------------- @@ -744,12 +766,12 @@ void DrawCalls::multidrawShadows(unsigned cascade) const */ void DrawCalls::drawIndirectReflectiveShadowMaps(const core::matrix4 &rsm_matrix) const { - m_reflective_shadow_map_cmd_buffer.bind(); - m_reflective_shadow_map_cmd_buffer.drawIndirect(rsm_matrix); - m_reflective_shadow_map_cmd_buffer.drawIndirect(rsm_matrix); - m_reflective_shadow_map_cmd_buffer.drawIndirect(rsm_matrix); - m_reflective_shadow_map_cmd_buffer.drawIndirect(rsm_matrix); - m_reflective_shadow_map_cmd_buffer.drawIndirect(rsm_matrix); + m_reflective_shadow_map_cmd_buffer->bind(); + m_reflective_shadow_map_cmd_buffer->drawIndirect(rsm_matrix); + m_reflective_shadow_map_cmd_buffer->drawIndirect(rsm_matrix); + m_reflective_shadow_map_cmd_buffer->drawIndirect(rsm_matrix); + m_reflective_shadow_map_cmd_buffer->drawIndirect(rsm_matrix); + m_reflective_shadow_map_cmd_buffer->drawIndirect(rsm_matrix); } // ---------------------------------------------------------------------------- @@ -759,12 +781,12 @@ void DrawCalls::drawIndirectReflectiveShadowMaps(const core::matrix4 &rsm_matrix */ void DrawCalls::multidrawReflectiveShadowMaps(const core::matrix4 &rsm_matrix) const { - m_reflective_shadow_map_cmd_buffer.bind(); - m_reflective_shadow_map_cmd_buffer.multidraw(rsm_matrix); - m_reflective_shadow_map_cmd_buffer.multidraw(rsm_matrix); - m_reflective_shadow_map_cmd_buffer.multidraw(rsm_matrix); - m_reflective_shadow_map_cmd_buffer.multidraw(rsm_matrix); - m_reflective_shadow_map_cmd_buffer.multidraw(rsm_matrix); + m_reflective_shadow_map_cmd_buffer->bind(); + m_reflective_shadow_map_cmd_buffer->multidraw(rsm_matrix); + m_reflective_shadow_map_cmd_buffer->multidraw(rsm_matrix); + m_reflective_shadow_map_cmd_buffer->multidraw(rsm_matrix); + m_reflective_shadow_map_cmd_buffer->multidraw(rsm_matrix); + m_reflective_shadow_map_cmd_buffer->multidraw(rsm_matrix); } // ---------------------------------------------------------------------------- @@ -775,8 +797,8 @@ void DrawCalls::multidrawReflectiveShadowMaps(const core::matrix4 &rsm_matrix) c */ void DrawCalls::drawIndirectGlow() const { - m_glow_cmd_buffer.bind(); - m_glow_cmd_buffer.drawIndirect(); + m_glow_cmd_buffer->bind(); + m_glow_cmd_buffer->drawIndirect(); } // ---------------------------------------------------------------------------- @@ -785,6 +807,6 @@ void DrawCalls::drawIndirectGlow() const */ void DrawCalls::multidrawGlow() const { - m_glow_cmd_buffer.bind(); - m_glow_cmd_buffer.multidraw(); + m_glow_cmd_buffer->bind(); + m_glow_cmd_buffer->multidraw(); } diff --git a/src/graphics/draw_calls.hpp b/src/graphics/draw_calls.hpp index 1b46702e1..dcc7ca836 100644 --- a/src/graphics/draw_calls.hpp +++ b/src/graphics/draw_calls.hpp @@ -43,10 +43,10 @@ private: MeshMap m_glow_pass_mesh; /** meshes data in VRAM */ - SolidCommandBuffer m_solid_cmd_buffer; - ShadowCommandBuffer m_shadow_cmd_buffer; - ReflectiveShadowMapCommandBuffer m_reflective_shadow_map_cmd_buffer; - GlowCommandBuffer m_glow_cmd_buffer; + SolidCommandBuffer *m_solid_cmd_buffer = NULL; + ShadowCommandBuffer *m_shadow_cmd_buffer = NULL; + ReflectiveShadowMapCommandBuffer *m_reflective_shadow_map_cmd_buffer = NULL; + GlowCommandBuffer *m_glow_cmd_buffer = NULL; void clearLists(); @@ -71,6 +71,9 @@ private: bool drawRSM); public: + DrawCalls(); + ~DrawCalls(); + void prepareDrawCalls(ShadowMatrices& shadow_matrices, irr::scene::ICameraSceneNode *camnode, unsigned &solid_poly_count, diff --git a/src/graphics/draw_policies.cpp b/src/graphics/draw_policies.cpp index cfbb6b9fb..4986e244d 100644 --- a/src/graphics/draw_policies.cpp +++ b/src/graphics/draw_policies.cpp @@ -21,7 +21,7 @@ // ---------------------------------------------------------------------------- template -void renderMeshes1stPass(const DrawCalls& draw_calls) +void renderMeshes1stPass() { auto &meshes = T::List::getInstance()->SolidPass; T::FirstPassShader::getInstance()->use(); @@ -137,14 +137,14 @@ void drawRSM(const core::matrix4 & rsm_matrix) // ---------------------------------------------------------------------------- void GL3DrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const { - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); + renderMeshes1stPass(); + renderMeshes1stPass(); + renderMeshes1stPass(); + renderMeshes1stPass(); + renderMeshes1stPass(); + renderMeshes1stPass(); + renderMeshes1stPass(); + renderMeshes1stPass(); } // ---------------------------------------------------------------------------- @@ -202,10 +202,10 @@ void IndirectDrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const { //TODO: find a way to add TextureMarix in instanced shaders, //and remove these four lines - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); + renderMeshes1stPass(); + renderMeshes1stPass(); + renderMeshes1stPass(); + renderMeshes1stPass(); draw_calls.drawIndirectSolidFirstPass(); } @@ -263,10 +263,10 @@ void MultidrawPolicy::drawSolidFirstPass(const DrawCalls& draw_calls) const { //TODO: find a way to add TextureMarix in instanced shaders, //and remove these four lines - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); - renderMeshes1stPass(draw_calls); + renderMeshes1stPass(); + renderMeshes1stPass(); + renderMeshes1stPass(); + renderMeshes1stPass(); draw_calls.multidrawSolidFirstPass(); }