Originally using a glDrawElementsInstancedBaseVertexscene grid to draw. All attributes of the grid vertices alternate in one buffer object. Only 30 unique grids. So I called the triplex 30 times with the number of instances, etc., but now I want to trigger the drawing calls to one using glMultiDrawElementsIndirect. Since I have no experience with this function, I read articles here and there to understand the implementation with little success. (For testing purposes, all cells are set only once).
Command structure from the OpenGL man page.
struct DrawElementsIndirectCommand
{
GLuint vertexCount;
GLuint instanceCount;
GLuint firstVertex;
GLuint baseVertex;
GLuint baseInstance;
};
DrawElementsIndirectCommand commands[30];
for (size_t index { 0 }; index < 30; ++index)
{
const Mesh* mesh{ m_meshes[index] };
commands[index].vertexCount = mesh->elementCount;
commands[index].instanceCount = 1;
commands[index].firstVertex = mesh->elementOffset();
commands[index].baseVertex = mesh->verticeIndex();
commands[index].baseInstance = 0;
}
Then later along the line, after setting, I draw a picture.
if (RenderMode == MULTIDRAW)
{
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, m_indirectBuffer);
glMultiDrawElementsIndirect (GL_TRIANGLES, GL_UNSIGNED_INT, nullptr, 30, 0);
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
}
else
{
for (size_t index { 0 }; index < 30; ++index)
{
const Mesh* mesh { m_meshes[index] };
glDrawElementsInstancedBaseVertex(
GL_TRIANGLES,
mesh->elementCount,
GL_UNSIGNED_INT,
reinterpret_cast<GLvoid*>(mesh->elementOffset()),
1,
mesh->verticeIndex());
}
}
glDrawElements... - , . glMultiDraw... , firstVertex 0 , ( ), ? , - ?