Fixed bug in CommandBuffer class

This commit is contained in:
Elderme 2015-11-02 22:27:37 +01:00
parent 6ba82eaac9
commit 331cc0827f
4 changed files with 45 additions and 20 deletions

View File

@ -159,14 +159,21 @@ void SolidCommandBuffer::fill(MeshMap *mesh_map, std::vector<GLMesh *> instanced
//Three textures materials //Three textures materials
InstanceDataThreeTex *instance_buffer_three_tex; InstanceDataThreeTex *instance_buffer_three_tex;
if (!CVS->supportsAsyncInstanceUpload())
if (CVS->supportsAsyncInstanceUpload())
{
instance_buffer_three_tex =
(InstanceDataThreeTex*)VAOManager::getInstance()->getInstanceBufferPtr(InstanceTypeThreeTex);
}
else
{ {
glUnmapBuffer(GL_ARRAY_BUFFER); glUnmapBuffer(GL_ARRAY_BUFFER);
glBindBuffer(GL_ARRAY_BUFFER, VAOManager::getInstance()->getInstanceBuffer(InstanceTypeThreeTex)); glBindBuffer(GL_ARRAY_BUFFER, VAOManager::getInstance()->getInstanceBuffer(InstanceTypeThreeTex));
instance_buffer_three_tex = (InstanceDataThreeTex*) instance_buffer_three_tex =
glMapBufferRange(GL_ARRAY_BUFFER, 0, (InstanceDataThreeTex*) glMapBufferRange(GL_ARRAY_BUFFER, 0,
10000 * sizeof(InstanceDataSingleTex), 10000 * sizeof(InstanceDataSingleTex), //TODO: why single?
GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
} }
Material::ShaderType three_tex_materials[2] = Material::ShaderType three_tex_materials[2] =

View File

@ -125,34 +125,33 @@ public:
CommandBuffer(); CommandBuffer();
virtual ~CommandBuffer(); virtual ~CommandBuffer();
inline size_t getPolyCount() {return m_poly_count;} inline size_t getPolyCount() const {return m_poly_count;}
inline void bind() inline void bind() const
{ {
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, m_draw_indirect_cmd_id); glBindBuffer(GL_DRAW_INDIRECT_BUFFER, m_draw_indirect_cmd_id);
} }
/** Draw the i-th mesh with the specified material /** Draw the i-th mesh with the specified material
* (require GL_ARB_base_instance and GL_ARB_draw_indirect extensions) * (require at least OpenGL 4.0
* \param shader_type Only render meshes with the specified material * or GL_ARB_base_instance and GL_ARB_draw_indirect extensions)
*/ */
inline void drawIndirect(Material::ShaderType shader_type, int i) inline void drawIndirect(int material_id, int i) const
{ {
glDrawElementsIndirect(GL_TRIANGLES, glDrawElementsIndirect(GL_TRIANGLES,
GL_UNSIGNED_SHORT, GL_UNSIGNED_SHORT,
(const void*)(m_offset[static_cast<int>(shader_type) + i] * sizeof(DrawElementsIndirectCommand))); (const void*)((m_offset[material_id] + i) * sizeof(DrawElementsIndirectCommand)));
} }
/** Draw the meshes with the specified material /** Draw the meshes with the specified material
* (require AZDO extensions) * (require at least OpenGL 4.3 or AZDO extensions)
* \param shader_type Only render meshes with the specified material
*/ */
inline void multidrawIndirect(Material::ShaderType shader_type) inline void multidrawIndirect(int material_id) const
{ {
glMultiDrawElementsIndirect(GL_TRIANGLES, glMultiDrawElementsIndirect(GL_TRIANGLES,
GL_UNSIGNED_SHORT, GL_UNSIGNED_SHORT,
(const void*)(m_offset[static_cast<int>(shader_type)] * sizeof(DrawElementsIndirectCommand)), (const void*)(m_offset[material_id] * sizeof(DrawElementsIndirectCommand)),
(int) m_size[static_cast<int>(shader_type)], (int) m_size[material_id],
sizeof(DrawElementsIndirectCommand)); sizeof(DrawElementsIndirectCommand));
} }
}; };

View File

@ -547,7 +547,7 @@ void DrawCalls::prepareDrawCalls( ShadowMatrices& shadow_matrices, scene::ICamer
{ {
//TODO //TODO
/*std::vector<GLMesh *> instanced_lists[Material::SHADERTYPE_COUNT]; std::vector<GLMesh *> instanced_lists[Material::SHADERTYPE_COUNT];
instanced_lists[static_cast<int>(Material::SHADERTYPE_SOLID)] = ListInstancedMatDefault::getInstance()->SolidPass; instanced_lists[static_cast<int>(Material::SHADERTYPE_SOLID)] = ListInstancedMatDefault::getInstance()->SolidPass;
instanced_lists[static_cast<int>(Material::SHADERTYPE_ALPHA_TEST)] = ListInstancedMatAlphaRef::getInstance()->SolidPass; instanced_lists[static_cast<int>(Material::SHADERTYPE_ALPHA_TEST)] = ListInstancedMatAlphaRef::getInstance()->SolidPass;
instanced_lists[static_cast<int>(Material::SHADERTYPE_SOLID_UNLIT)] = ListInstancedMatUnlit::getInstance()->SolidPass; instanced_lists[static_cast<int>(Material::SHADERTYPE_SOLID_UNLIT)] = ListInstancedMatUnlit::getInstance()->SolidPass;
@ -556,8 +556,7 @@ void DrawCalls::prepareDrawCalls( ShadowMatrices& shadow_matrices, scene::ICamer
instanced_lists[static_cast<int>(Material::SHADERTYPE_DETAIL_MAP)] = ListInstancedMatDetails::getInstance()->SolidPass; instanced_lists[static_cast<int>(Material::SHADERTYPE_DETAIL_MAP)] = ListInstancedMatDetails::getInstance()->SolidPass;
instanced_lists[static_cast<int>(Material::SHADERTYPE_NORMAL_MAP)] = ListInstancedMatNormalMap::getInstance()->SolidPass; instanced_lists[static_cast<int>(Material::SHADERTYPE_NORMAL_MAP)] = ListInstancedMatNormalMap::getInstance()->SolidPass;
m_solid_cmd_buffer.fill(m_solid_pass_mesh, instanced_lists);*/ m_solid_cmd_buffer.fill(m_solid_pass_mesh, instanced_lists);
size_t offset = 0, current_cmd = 0; size_t offset = 0, current_cmd = 0;
@ -759,3 +758,21 @@ void DrawCalls::renderParticlesList() const
for(auto particles: m_particles_list) for(auto particles: m_particles_list)
particles->render(); particles->render();
} }
/** Draw the i-th mesh with the specified material for the solid pass
* (require at least OpenGL 4.0
* or GL_ARB_base_instance and GL_ARB_draw_indirect extensions)
*/
void DrawCalls::drawIndirectSolidCmd(Material::ShaderType shader_type, int i) const
{
m_solid_cmd_buffer.drawIndirect(static_cast<int>(shader_type), i);
}
/** Draw the meshes with the specified material
* (require at least OpenGL 4.3 or AZDO extensions)
*/
void DrawCalls::multidrawIndirectSolidCmd(Material::ShaderType shader_type) const
{
m_solid_cmd_buffer.multidrawIndirect(static_cast<int>(shader_type));
}

View File

@ -97,7 +97,9 @@ public:
void renderBillboardList() const; void renderBillboardList() const;
void renderParticlesList() const; void renderParticlesList() const;
inline void bindSolidCmd() const { m_solid_cmd_buffer.bind(); }
void drawIndirectSolidCmd(Material::ShaderType shader_type, int i) const;
void multidrawIndirectSolidCmd(Material::ShaderType shader_type) const;
}; };
#endif //HEADER_DRAW_CALLS_HPP #endif //HEADER_DRAW_CALLS_HPP