I'm trying to build the command array but I keep on getting "broken" mesh draws. here is the struct I try to populate:
My Vertex/indices are stored in buffers as :
QVector<QVector3D> mVertex; // all meshes in 1 vector
QVector<unsigned int> mIndices; // all meshes in 1 vector
int mIndicesCount = mIndices.size(); // this is per mesh accessible
int mVertexCount = mVertex.size(); // this is per mesh accessible
The loop :
int skip =0;
int offset =0;
for (size_t u = 0; u < jobSize; ++u) {
DrawElementsIndirectCommand *cmd = &dstCmds[u];
cmd->count = mNodeList[u]->mIndicesCount;
cmd->instanceCount = 1;
cmd->firstIndex = skip;
cmd->baseVertex = offset;
cmd->baseInstance = 1;
skip += (mNodeList[u]->mIndicesCount * sizeof(unsigned int));
offset += (mNodeList[u]->mVertexCount / sizeof(unsigned int));
}
Does any1 see any errors here? I'm lost.
Also tried this :
skip += (mNodeList[u]->mIndicesCount / sizeof(unsigned int));
offset += (mNodeList[u]->mVertexCount);
based on > OpenGL glMultiDrawElementsIndirect with Interleaved Buffers
EDIT 2 I could not get it to work with the suggesions in comments, or I did somethingw rong... here is the main code responsible for building the buffers & commands. PS. this exercise is about trying to follow AZDO - https://github.com/nvMcJohn/apitest/blob/master/src/solutions/untexturedobjects/gl/bufferstorage.cpp
int jobSize = mNodeList.size();
QVector<QVector3D> mVertex;
QVector<QVector3D> mNormals;
QVector<unsigned int> mIndices;
for (auto &node:mNodeList) {
mVertex.append(node->mVertex);
mNormals.append(node->mVertexNormal);
mIndices.append(node->mIndices);
}
glBindVertexArray(m_varray);
glBindBuffer(GL_ARRAY_BUFFER, m_vb);
glBufferData(GL_ARRAY_BUFFER, mVertex.size() * sizeof(QVector3D), &mVertex[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ib);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, mIndices.size() * sizeof(unsigned int), &mIndices[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
mShader->enableAttributeArray("In_v3Pos");
mShader->setAttributeBuffer("In_v3Pos", GL_FLOAT, 0, 3, sizeof(QVector3D));
glBindBuffer(GL_ARRAY_BUFFER, m_vn);
glBufferData(GL_ARRAY_BUFFER, mNormals.size() * sizeof(QVector3D), &mNormals[0], GL_STATIC_DRAW);
mShader->enableAttributeArray("In_v3Color");
mShader->setAttributeBuffer("In_v3Color", GL_FLOAT, 0, 3, sizeof(QVector3D));
const GLbitfield mapFlags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT;
const GLbitfield createFlags = mapFlags | GL_DYNAMIC_STORAGE_BIT;
mCommands.Destroy();
mCommands.Create(BufferStorage::PersistentlyMappedBuffer, GL_DRAW_INDIRECT_BUFFER, 3 * jobSize, createFlags, mapFlags);
mTransformBuffer.Destroy();
mTransformBuffer.Create(BufferStorage::PersistentlyMappedBuffer, GL_SHADER_STORAGE_BUFFER, 3 * jobSize, createFlags, mapFlags);
glBindVertexArray(0);
DrawElementsIndirectCommand *dstCmds = mCommands.Reserve(jobSize);
int skip = 0;
int offset = 0;
for (size_t u = 0; u < jobSize; ++u) {
DrawElementsIndirectCommand *cmd = &dstCmds[u];
cmd->count = mNodeList[u]->mIndicesCount;
cmd->instanceCount = 1;
cmd->firstIndex = skip*sizeof(unsigned int);
cmd->baseVertex = offset;
cmd->baseInstance = 0;
skip += mNodeList[u]->mIndicesCount ;
offset += mNodeList[u]->mVertexCount;
}