Remove code used to duplicate VAOs for animated meshes
This commit is contained in:
parent
6baed2b0dd
commit
1f23e6e783
@ -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<InstanceDataThreeTex, SolidPassMeshMap>
|
||||
fillInstanceData<InstanceDataThreeTex, MeshMap>
|
||||
(mesh_map, three_tex_material_list, InstanceTypeThreeTex);
|
||||
|
||||
std::vector<int> 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<InstanceDataFourTex, SolidPassMeshMap>
|
||||
fillInstanceData<InstanceDataFourTex, MeshMap>
|
||||
(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<InstanceDataSingleTex, OtherMeshMap>
|
||||
fillInstanceData<InstanceDataSingleTex, MeshMap>
|
||||
(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<InstanceDataSingleTex, OtherMeshMap>
|
||||
fillInstanceData<InstanceDataSingleTex, MeshMap>
|
||||
(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<GlowInstanceData, OtherMeshMap>
|
||||
fillInstanceData<GlowInstanceData, MeshMap>
|
||||
(mesh_map, createVector<int>(0), InstanceTypeGlow);
|
||||
if (!CVS->supportsAsyncInstanceUpload())
|
||||
glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER);
|
||||
|
@ -39,10 +39,7 @@ struct InstanceList
|
||||
std::vector<InstanceSettings> m_instance_settings;
|
||||
};
|
||||
|
||||
typedef std::unordered_map <std::pair<scene::IMeshBuffer*, RenderInfo*>, InstanceList,
|
||||
MeshRenderInfoHash, MeshRenderInfoEquals> SolidPassMeshMap;
|
||||
|
||||
typedef std::unordered_map <irr::scene::IMeshBuffer *, InstanceList > OtherMeshMap;
|
||||
typedef std::unordered_map <irr::scene::IMeshBuffer *, InstanceList > MeshMap;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Fill origin, orientation and scale attributes
|
||||
@ -271,7 +268,7 @@ class SolidCommandBuffer: public CommandBuffer<static_cast<int>(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<int>(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<static_cast<int>(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.
|
||||
|
@ -301,9 +301,8 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node,
|
||||
}
|
||||
else
|
||||
{
|
||||
std::pair<scene::IMeshBuffer*, RenderInfo*> 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);
|
||||
|
@ -43,10 +43,10 @@ private:
|
||||
std::vector<float> 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 */
|
||||
|
@ -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<unsigned, unsigned> p = VAOManager::getInstance()->getBase(mb,NULL /*GLmeshes[i].m_render_info*/);
|
||||
std::pair<unsigned, unsigned> p = VAOManager::getInstance()->getBase(mb);
|
||||
mesh.vaoBaseVertex = p.first;
|
||||
mesh.vaoOffset = p.second;
|
||||
}
|
||||
|
@ -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<scene::IMeshBuffer*, RenderInfo*> 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<unsigned, unsigned> VAOManager::getBase(scene::IMeshBuffer *mb, RenderInfo* ri)
|
||||
std::pair<unsigned, unsigned> VAOManager::getBase(scene::IMeshBuffer *mb)
|
||||
{
|
||||
VTXTYPE tp = getVTXTYPE(mb->getVertexType());
|
||||
std::pair<scene::IMeshBuffer*, RenderInfo*> 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<std::pair<scene::IMeshBuffer*, RenderInfo*>, unsigned, MeshRenderInfoHash, MeshRenderInfoEquals>::iterator It;
|
||||
It = mappedBaseVertex[tp].find(key);
|
||||
std::unordered_map<scene::IMeshBuffer*, unsigned>::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<unsigned, unsigned>(vtx, It->second);
|
||||
}
|
||||
|
@ -174,30 +174,6 @@ struct GlowInstanceData
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
#include <functional>
|
||||
|
||||
class MeshRenderInfoHash
|
||||
{
|
||||
public:
|
||||
size_t operator() (const std::pair<irr::scene::IMeshBuffer*, RenderInfo*> &p) const
|
||||
{
|
||||
return (std::hash<irr::scene::IMeshBuffer*>()(p.first) ^
|
||||
(std::hash<RenderInfo*>()(p.second) << 1));
|
||||
}
|
||||
};
|
||||
|
||||
struct MeshRenderInfoEquals : std::binary_function
|
||||
<const std::pair<irr::scene::IMeshBuffer*, RenderInfo*>&,
|
||||
const std::pair<irr::scene::IMeshBuffer*, RenderInfo*>&, 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<VAOManager>
|
||||
{
|
||||
enum VTXTYPE { VTXTYPE_STANDARD, VTXTYPE_TCOORD, VTXTYPE_TANGENT, VTXTYPE_SKINNED_MESH, VTXTYPE_COUNT };
|
||||
@ -207,7 +183,7 @@ class VAOManager : public Singleton<VAOManager>
|
||||
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 <std::pair<irr::scene::IMeshBuffer*, RenderInfo*>, unsigned, MeshRenderInfoHash, MeshRenderInfoEquals> mappedBaseVertex[VTXTYPE_COUNT], mappedBaseIndex[VTXTYPE_COUNT];
|
||||
std::unordered_map<irr::scene::IMeshBuffer*, unsigned> mappedBaseVertex[VTXTYPE_COUNT], mappedBaseIndex[VTXTYPE_COUNT];
|
||||
std::map<std::pair<irr::video::E_VERTEX_TYPE, InstanceType>, GLuint> InstanceVAO;
|
||||
|
||||
void cleanInstanceVAOs();
|
||||
@ -217,10 +193,10 @@ class VAOManager : public Singleton<VAOManager>
|
||||
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<unsigned, unsigned> getBase(irr::scene::IMeshBuffer *, RenderInfo* ri = NULL);
|
||||
std::pair<unsigned, unsigned> 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)]; }
|
||||
|
Loading…
Reference in New Issue
Block a user