Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
108 views
in Technique[技术] by (71.8m points)

java - Why do I get error INVALID_OPERATION when I call glMultiDrawElementsIndirect

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

question from:https://stackoverflow.com/questions/65859578/why-do-i-get-error-invalid-operation-when-i-call-glmultidrawelementsindirect

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...