Question using glMultiDrawArraysIndirect and indirect buffer

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Question using glMultiDrawArraysIndirect and indirect buffer

a_shuang
This post was updated on .
I have two objects (A and B) to be rendered using glMultiDrawArraysIndirect(). Each object has a setupBuffers() method for creating, binding a vao, then creating and binding the indirect buffer, instanced ID buffer, vertices buffer and texture coords buffer.

Here is the problem: if I call setupBuffers() of the object A before calling setupBuffers() in B, then only B will be drawn; if I call setupBuffers() of the object B before calling setupBuffers() in A, then only A will be drawn. (No exception is found.) The data stored should be all correct since I've tested both of them.

Object A:

protected void setupBuffers()
{
    gl.glGenVertexArrays(1, vaoBuff);
    gl.glBindVertexArray(vaoBuff.get(0));

    gl.glGenBuffers(4, vboBuff);

    //bind indirect buffer object
    gl.glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, vboBuff.get(0));
    gl.glBufferData(GL4.GL_DRAW_INDIRECT_BUFFER, instanceCount * 4 * Integer.SIZE / 8, null, GL4.GL_STATIC_DRAW);
    gl.glBufferSubData(...);

    //bind draw instance ID in the shader with a buffer object
    gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, vboBuff.get(1));
    gl.glBufferData(GL4.GL_ARRAY_BUFFER, instanceCount * Integer.SIZE / 8, drawIndexBuff, GL4.GL_STATIC_DRAW);
    gl.glVertexAttribIPointer(d_idLoc, 1, GL4.GL_UNSIGNED_INT, 0, 0);
    gl.glVertexAttribDivisor(d_idLoc, 1);
    gl.glEnableVertexAttribArray(d_idLoc);

    //bind vertex data buffer object
    gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, vboBuff.get(2));
    gl.glBufferData(GL4.GL_ARRAY_BUFFER, instanceCount * vertBuffSize * Float.SIZE / 8, null, GL4.GL_STATIC_DRAW);
    gl.glBufferSubData(...);
    gl.glVertexAttribPointer(verPosLoc, 3, GL4.GL_FLOAT, false, 0, 0);
    gl.glEnableVertexAttribArray(verPosLoc);

    //bind texture coordinate data buffer object
    gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, vboBuff.get(3));
    gl.glBufferData(GL4.GL_ARRAY_BUFFER, instanceCount * texBuffSize * Float.SIZE / 8, null, GL4.GL_STATIC_DRAW);
    gl.glBufferSubData(...);
    gl.glVertexAttribPointer(tc_inLoc, 2, GL4.GL_FLOAT, false, 0, 0);
    gl.glEnableVertexAttribArray(tc_inLoc);
}

drawing method in Object A:

gl.glBindVertexArray(vaoBuff.get(0));
gl.glMultiDrawArraysIndirect(GL4.GL_TRIANGLE_STRIP, 0, instanceCount, 0);



Object B:

protected void setupBuffers()
{
    very similar to A...
}

drawing method in Object B:

gl.glBindVertexArray(vaoBuff.get(0));
gl.glMultiDrawArraysIndirect(GL4.GL_PATCHES, 0, instanceCount, 0);


Finally I find the problem which is at:
gl.glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, vboBuff.get(0));

This method used to bind a indirect buffer is called once both in Object A & B, resulting in that problem, yet I have no idea why. Any ideas about that?


Fixed it finally. The GL_DRAW_INDIRECT_BUFFER binding point is not part of vertex array object state. It's global context state. So I'll have to set this to the buffer I want to pull from before performing indirect operations from that buffer (change the above code to):

    gl.glBindVertexArray(vaoBuff.get(0));
    gl.glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, vboBuff.get(0));
    gl.glMultiDrawArraysIndirect(GL4.GL_PATCHES, 0, instanceCount, 0);

then it worked just fine.
Reply | Threaded
Open this post in threaded view
|

Re: Question using glMultiDrawArraysIndirect and indirect buffer

jmaasing
Sounds like you are overwriting the same buffer, is this the same for both A & B "vaoBuff"?
Reply | Threaded
Open this post in threaded view
|

Re: Question using glMultiDrawArraysIndirect and indirect buffer

a_shuang
jmaasing wrote
Sounds like you are overwriting the same buffer, is this the same for both A & B "vaoBuff"?

No I'm not, they are in different objects. Both object A & B have a "vaoBuff". These two are different.