Reputation: 79
I'm currently trying to use glMultiDrawElementsIndirect
in with LWJGL in Java, but I have an error INVALID_OPERATION.
glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, this.modelManager.indirect, NB_TYPE_MESH, 0);
I see in the documentation this error is about the GL_DRAW_INDIRECT_BUFFER
or GL_ELEMENT_ARRAY_BUFFER
, but I don't know where the problem is in my code.
Indirect buffer
int[] indirect = new int[NB_TYPE_MESH*5];
for(int i=0; i<2; i++) {
indirect[i] = getElementCount().get(i);
indirect[1+i] = Game.NB_MAX_OBJECTS/2;
indirect[2+i] = 0;
indirect[3+i] = i==0?0:getElementCount().get(i-1);
indirect[4+i] = i; // maybe 0
}
vboIdIndirect = glGenBuffers();
IntBuffer gIndirectBuffer = MemoryUtil.memAllocInt(indirect.length);
gIndirectBuffer.put(indirect).flip();
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, vboIdIndirect);
glBufferData(GL_DRAW_INDIRECT_BUFFER, gIndirectBuffer, GL_DYNAMIC_DRAW);
and my elements buffer
vboId = glGenBuffers();
vboIdList.add(vboId);
indicesBuffer = MemoryUtil.memAllocInt(indices.length);
indicesBuffer.put(indices).flip();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_DYNAMIC_DRAW);
indices contains indices for NB_TYPE_MESH
types of mesh
Upvotes: 1
Views: 410
Reputation: 211258
If a buffer is bound to the target GL_DRAW_INDIRECT_BUFFER
when glMultiDrawElementsIndirect
is called, the indirect argument is interpreted as an offset in basic machine units into this buffer.
Hence you need to bind the GL_DRAW_INDIRECT_BUFFER
before drawing the elements, but the indirect argument must be null
:
glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, this.modelManager.indirect, NB_TYPE_MESH, 0);
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, vboIdIndirect);
glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, null, NB_TYPE_MESH, 0);
See also Java Code Examples glMultiDrawElementsIndirect()
Upvotes: 1