From 1f23e6e783af4fdd248536e3fbe1a196dc9e5ba0 Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 15 Dec 2016 11:44:09 +0800 Subject: [PATCH] Remove code used to duplicate VAOs for animated meshes --- src/graphics/command_buffer.cpp | 18 +++++++++--------- src/graphics/command_buffer.hpp | 13 +++++-------- src/graphics/draw_calls.cpp | 5 ++--- src/graphics/draw_calls.hpp | 8 ++++---- src/graphics/stk_animated_mesh.cpp | 16 +++------------- src/graphics/vao_manager.cpp | 22 ++++++++++------------ src/graphics/vao_manager.hpp | 30 +++--------------------------- 7 files changed, 36 insertions(+), 76 deletions(-) diff --git a/src/graphics/command_buffer.cpp b/src/graphics/command_buffer.cpp index a7e4a624b..fa41e86ed 100644 --- a/src/graphics/command_buffer.cpp +++ b/src/graphics/command_buffer.cpp @@ -158,7 +158,7 @@ SolidCommandBuffer::SolidCommandBuffer(): CommandBuffer() } // ---------------------------------------------------------------------------- -void SolidCommandBuffer::fill(SolidPassMeshMap *mesh_map) +void SolidCommandBuffer::fill(MeshMap *mesh_map) { clearMeshes(); @@ -175,7 +175,7 @@ void SolidCommandBuffer::fill(SolidPassMeshMap *mesh_map) Material::SHADERTYPE_ALPHA_TEST_SKINNED_MESH, Material::SHADERTYPE_SOLID_UNLIT_SKINNED_MESH); - fillInstanceData + fillInstanceData (mesh_map, three_tex_material_list, InstanceTypeThreeTex); std::vector four_tex_material_list = @@ -183,7 +183,7 @@ void SolidCommandBuffer::fill(SolidPassMeshMap *mesh_map) Material::SHADERTYPE_NORMAL_MAP, Material::SHADERTYPE_NORMAL_MAP_SKINNED_MESH); - fillInstanceData + fillInstanceData (mesh_map, four_tex_material_list, InstanceTypeFourTex); if (!CVS->supportsAsyncInstanceUpload()) @@ -196,7 +196,7 @@ ShadowCommandBuffer::ShadowCommandBuffer(): CommandBuffer() } // ---------------------------------------------------------------------------- -void ShadowCommandBuffer::fill(OtherMeshMap *mesh_map) +void ShadowCommandBuffer::fill(MeshMap *mesh_map) { clearMeshes(); @@ -232,7 +232,7 @@ void ShadowCommandBuffer::fill(OtherMeshMap *mesh_map) + Material::SHADERTYPE_NORMAL_MAP_SKINNED_MESH); } - fillInstanceData + fillInstanceData (mesh_map, shadow_tex_material_list, InstanceTypeShadow); if (!CVS->supportsAsyncInstanceUpload()) @@ -246,7 +246,7 @@ ReflectiveShadowMapCommandBuffer::ReflectiveShadowMapCommandBuffer() } // ---------------------------------------------------------------------------- -void ReflectiveShadowMapCommandBuffer::fill(OtherMeshMap *mesh_map) +void ReflectiveShadowMapCommandBuffer::fill(MeshMap *mesh_map) { clearMeshes(); @@ -260,7 +260,7 @@ void ReflectiveShadowMapCommandBuffer::fill(OtherMeshMap *mesh_map) Material::SHADERTYPE_DETAIL_MAP, Material::SHADERTYPE_NORMAL_MAP); - fillInstanceData + fillInstanceData (mesh_map, rsm_material_list, InstanceTypeRSM); if (!CVS->supportsAsyncInstanceUpload()) @@ -274,14 +274,14 @@ GlowCommandBuffer::GlowCommandBuffer() } // ---------------------------------------------------------------------------- -void GlowCommandBuffer::fill(OtherMeshMap *mesh_map) +void GlowCommandBuffer::fill(MeshMap *mesh_map) { clearMeshes(); if(!CVS->supportsAsyncInstanceUpload()) mapIndirectBuffer(); - fillInstanceData + fillInstanceData (mesh_map, createVector(0), InstanceTypeGlow); if (!CVS->supportsAsyncInstanceUpload()) glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER); diff --git a/src/graphics/command_buffer.hpp b/src/graphics/command_buffer.hpp index 6ae425c73..0fade2f85 100644 --- a/src/graphics/command_buffer.hpp +++ b/src/graphics/command_buffer.hpp @@ -39,10 +39,7 @@ struct InstanceList std::vector m_instance_settings; }; -typedef std::unordered_map , InstanceList, - MeshRenderInfoHash, MeshRenderInfoEquals> SolidPassMeshMap; - -typedef std::unordered_map OtherMeshMap; +typedef std::unordered_map MeshMap; // ---------------------------------------------------------------------------- /** Fill origin, orientation and scale attributes @@ -271,7 +268,7 @@ class SolidCommandBuffer: public CommandBuffer(Material::SHADER { public: SolidCommandBuffer(); - void fill(SolidPassMeshMap *mesh_map); + void fill(MeshMap *mesh_map); // ---------------------------------------------------------------------------- /** First rendering pass; draw all meshes associated with the same material @@ -458,7 +455,7 @@ class ShadowCommandBuffer: public CommandBuffer<4*static_cast(Material::SHA { public: ShadowCommandBuffer(); - void fill(OtherMeshMap *mesh_map); + void fill(MeshMap *mesh_map); // ---------------------------------------------------------------------------- /** Draw shadowmaps for meshes with the same material @@ -532,7 +529,7 @@ class ReflectiveShadowMapCommandBuffer: public CommandBuffer(Ma { public: ReflectiveShadowMapCommandBuffer(); - void fill(OtherMeshMap *mesh_map); + void fill(MeshMap *mesh_map); // ---------------------------------------------------------------------------- /** Draw reflective shadow map for meshes with the same material @@ -615,7 +612,7 @@ class GlowCommandBuffer: public CommandBuffer<1> { public: GlowCommandBuffer(); - void fill(OtherMeshMap *mesh_map); + void fill(MeshMap *mesh_map); // ---------------------------------------------------------------------------- /** Draw glowing meshes. diff --git a/src/graphics/draw_calls.cpp b/src/graphics/draw_calls.cpp index 5e77434b7..fc6bb0a6a 100644 --- a/src/graphics/draw_calls.cpp +++ b/src/graphics/draw_calls.cpp @@ -301,9 +301,8 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, } else { - std::pair mesh_render_info(mesh->mb, NULL); - m_solid_pass_mesh[Mat][mesh_render_info].m_mesh = mesh; - m_solid_pass_mesh[Mat][mesh_render_info].m_instance_settings.emplace_back(Node, mesh->texture_trans, + m_solid_pass_mesh[Mat][mesh->mb].m_mesh = mesh; + m_solid_pass_mesh[Mat][mesh->mb].m_instance_settings.emplace_back(Node, mesh->texture_trans, (mesh->m_render_info && mesh->m_material ? core::vector2df(mesh->m_render_info->getHue(), mesh->m_material->getColorizationFactor()) : core::vector2df(0.0f, 0.0f)), skinning_offset); diff --git a/src/graphics/draw_calls.hpp b/src/graphics/draw_calls.hpp index fc72c4cb9..707f42493 100644 --- a/src/graphics/draw_calls.hpp +++ b/src/graphics/draw_calls.hpp @@ -43,10 +43,10 @@ private: std::vector m_bounding_boxes; /** meshes to draw */ - SolidPassMeshMap m_solid_pass_mesh [ Material::SHADERTYPE_COUNT]; - OtherMeshMap m_shadow_pass_mesh [4 * Material::SHADERTYPE_COUNT]; - OtherMeshMap m_reflective_shadow_map_mesh [ Material::SHADERTYPE_COUNT]; - OtherMeshMap m_glow_pass_mesh; + MeshMap m_solid_pass_mesh [ Material::SHADERTYPE_COUNT]; + MeshMap m_shadow_pass_mesh [4 * Material::SHADERTYPE_COUNT]; + MeshMap m_reflective_shadow_map_mesh [ Material::SHADERTYPE_COUNT]; + MeshMap m_glow_pass_mesh; #if !defined(USE_GLES2) /** meshes data in VRAM */ diff --git a/src/graphics/stk_animated_mesh.cpp b/src/graphics/stk_animated_mesh.cpp index 06f78a08e..588eae88d 100644 --- a/src/graphics/stk_animated_mesh.cpp +++ b/src/graphics/stk_animated_mesh.cpp @@ -99,16 +99,6 @@ void STKAnimatedMesh::updateNoGL() if (!isMaterialInitialized) { - // Use a default render info to distinguish same mesh buffer created by - // different animated mesh node in vao manager when using instanced - // rendering - RenderInfo* default_ri = NULL; - if (CVS->isARBBaseInstanceUsable()) - { - default_ri = new RenderInfo(); - m_static_render_info.push_back(default_ri); - } - video::IVideoDriver* driver = SceneManager->getVideoDriver(); const u32 mb_count = m->getMeshBufferCount(); for (u32 i = 0; i < mb_count; ++i) @@ -142,7 +132,7 @@ void STKAnimatedMesh::updateNoGL() } else { - cur_ri = default_ri; + cur_ri = NULL; } } else @@ -158,7 +148,7 @@ void STKAnimatedMesh::updateNoGL() assert(cur_ri ? cur_ri->isStatic() : true); GLmeshes.push_back(allocateMeshBuffer(mb, m_debug_name, affected || m_all_parts_colorized || (cur_ri - && cur_ri->isTransparent()) ? cur_ri : default_ri)); + && cur_ri->isTransparent()) ? cur_ri : NULL)); if (m_skinned_mesh) ssmb->VertexType = prev_type; } @@ -270,7 +260,7 @@ void STKAnimatedMesh::updateGL() if (CVS->isARBBaseInstanceUsable()) { - std::pair p = VAOManager::getInstance()->getBase(mb,NULL /*GLmeshes[i].m_render_info*/); + std::pair p = VAOManager::getInstance()->getBase(mb); mesh.vaoBaseVertex = p.first; mesh.vaoOffset = p.second; } diff --git a/src/graphics/vao_manager.cpp b/src/graphics/vao_manager.cpp index 1fac8bbf9..0a9914284 100644 --- a/src/graphics/vao_manager.cpp +++ b/src/graphics/vao_manager.cpp @@ -316,7 +316,7 @@ irr::video::E_VERTEX_TYPE VAOManager::getVertexType(enum VTXTYPE tp) } } -void VAOManager::append(scene::IMeshBuffer *mb, VTXTYPE tp, RenderInfo* ri) +void VAOManager::append(scene::IMeshBuffer *mb, VTXTYPE tp) { size_t old_vtx_cnt = last_vertex[tp]; size_t old_idx_cnt = last_index[tp]; @@ -347,28 +347,26 @@ void VAOManager::append(scene::IMeshBuffer *mb, VTXTYPE tp, RenderInfo* ri) glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, old_idx_cnt * sizeof(u16), mb->getIndexCount() * sizeof(u16), mb->getIndices()); } - std::pair key(mb, ri); - mappedBaseVertex[tp][key] = old_vtx_cnt; - mappedBaseIndex[tp][key] = old_idx_cnt * sizeof(u16); + mappedBaseVertex[tp][mb] = old_vtx_cnt; + mappedBaseIndex[tp][mb] = old_idx_cnt * sizeof(u16); } -std::pair VAOManager::getBase(scene::IMeshBuffer *mb, RenderInfo* ri) +std::pair VAOManager::getBase(scene::IMeshBuffer *mb) { VTXTYPE tp = getVTXTYPE(mb->getVertexType()); - std::pair key(mb, ri); - if (mappedBaseVertex[tp].find(key) == mappedBaseVertex[tp].end()) + if (mappedBaseVertex[tp].find(mb) == mappedBaseVertex[tp].end()) { - assert(mappedBaseIndex[tp].find(key) == mappedBaseIndex[tp].end()); - append(mb, tp, ri); + assert(mappedBaseIndex[tp].find(mb) == mappedBaseIndex[tp].end()); + append(mb, tp); regenerateVAO(tp); regenerateInstancedVAO(); } - std::unordered_map, unsigned, MeshRenderInfoHash, MeshRenderInfoEquals>::iterator It; - It = mappedBaseVertex[tp].find(key); + std::unordered_map::iterator It; + It = mappedBaseVertex[tp].find(mb); assert(It != mappedBaseVertex[tp].end()); unsigned vtx = It->second; - It = mappedBaseIndex[tp].find(key); + It = mappedBaseIndex[tp].find(mb); assert(It != mappedBaseIndex[tp].end()); return std::pair(vtx, It->second); } diff --git a/src/graphics/vao_manager.hpp b/src/graphics/vao_manager.hpp index b30e712c3..a9aff69cd 100644 --- a/src/graphics/vao_manager.hpp +++ b/src/graphics/vao_manager.hpp @@ -174,30 +174,6 @@ struct GlowInstanceData #pragma pack(pop) #endif -#include - -class MeshRenderInfoHash -{ -public: - size_t operator() (const std::pair &p) const - { - return (std::hash()(p.first) ^ - (std::hash()(p.second) << 1)); - } -}; - -struct MeshRenderInfoEquals : std::binary_function - &, - const std::pair&, bool> -{ - result_type operator() (first_argument_type lhs, - second_argument_type rhs) const - { - return (lhs.first == rhs.first) && - (lhs.second == rhs.second); - } -}; - class VAOManager : public Singleton { enum VTXTYPE { VTXTYPE_STANDARD, VTXTYPE_TCOORD, VTXTYPE_TANGENT, VTXTYPE_SKINNED_MESH, VTXTYPE_COUNT }; @@ -207,7 +183,7 @@ class VAOManager : public Singleton void *VBOPtr[VTXTYPE_COUNT], *IBOPtr[VTXTYPE_COUNT]; size_t RealVBOSize[VTXTYPE_COUNT], RealIBOSize[VTXTYPE_COUNT]; size_t last_vertex[VTXTYPE_COUNT], last_index[VTXTYPE_COUNT]; - std::unordered_map , unsigned, MeshRenderInfoHash, MeshRenderInfoEquals> mappedBaseVertex[VTXTYPE_COUNT], mappedBaseIndex[VTXTYPE_COUNT]; + std::unordered_map mappedBaseVertex[VTXTYPE_COUNT], mappedBaseIndex[VTXTYPE_COUNT]; std::map, GLuint> InstanceVAO; void cleanInstanceVAOs(); @@ -217,10 +193,10 @@ class VAOManager : public Singleton size_t getVertexPitch(enum VTXTYPE) const; VTXTYPE getVTXTYPE(irr::video::E_VERTEX_TYPE type); irr::video::E_VERTEX_TYPE getVertexType(enum VTXTYPE tp); - void append(irr::scene::IMeshBuffer *, VTXTYPE tp, RenderInfo* ri = NULL); + void append(irr::scene::IMeshBuffer *, VTXTYPE tp); public: VAOManager(); - std::pair getBase(irr::scene::IMeshBuffer *, RenderInfo* ri = NULL); + std::pair getBase(irr::scene::IMeshBuffer *); GLuint getInstanceBuffer(InstanceType it) { return instance_vbo[it]; } void *getInstanceBufferPtr(InstanceType it) { return Ptr[it]; } unsigned getVBO(irr::video::E_VERTEX_TYPE type) { return vbo[getVTXTYPE(type)]; }