PDA

View Full Version : What's the meaning of the indirect cmd used in glMultiDrawElementsIndirect



A_Shuang
03-16-2015, 09:27 AM
I'm confused about using glMultiDrawElementsIndirect(), could anyone explain to me the meaning of the cmd struct used by that drawing command?

struct cmd:

count = ..
primCount = ..
firstIndex = ..
baseVertex = ..
baseInstance = ..

if I have three different triangle strips to draw, would that be like this?

for (int n = 0; n < 3; n++)
{
count = indexCount;
primCount = 1;
firstIndex = n * count;
baseVertex = 0;
baseInstance = n;
}

Setup Buffers:

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

gl.glGenBuffers(5, vboBuff);

//bind indirect buffer object
gl.glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, vboBuff.get(0));
gl.glBufferData(GL4.GL_DRAW_INDIRECT_BUFFER, instanceCount * 5 * 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 / column_subdivision * 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 vertex index data buffer object
gl.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, vboBuff.get(3));
gl.glBufferData(GL4.GL_ELEMENT_ARRAY_BUFFER, instanceCount / column_subdivision * indexBuffSize * Integer.SIZE / 8, null, GL4.GL_STATIC_DRAW);
gl.glBufferSubData(...);

//bind texture coordinate data buffer object
gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, vboBuff.get(4));
gl.glBufferData(GL4.GL_ARRAY_BUFFER, instanceCount / column_subdivision * 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 command:

gl.glMultiDrawElementsIndirect(GL4.GL_TRIANGLE_STR IP, GL4.GL_UNSIGNED_INT, null, 3, 0);

Fixed it, it was the problem about vertex data, nothing relevant to the drawing commands. And the baseVertex should be 0.

Alfonse Reinheart
03-16-2015, 09:54 AM
The struct members have the exact same meaning as the corresponding parameters to glDrawElementsInstancedBaseVertexBaseInstance​() (https://www.opengl.org/wiki/GLAPI/glDrawElementsInstancedBaseVertexBaseInstance).

A_Shuang
03-16-2015, 10:14 AM
The struct members have the exact same meaning as the corresponding parameters to glDrawElementsInstancedBaseVertexBaseInstance​() (https://www.opengl.org/wiki/GLAPI/glDrawElementsInstancedBaseVertexBaseInstance).

So if my first strip is: 10, 0, 11, 1, ... 19, 9
second strip: 20, 10, ... 29, 19
then the baseVertex should be 10 * n ? (n means the index of the strip)

Alfonse Reinheart
03-16-2015, 10:25 AM
then the baseVertex should be 10 * n ? (n means the index of the strip)

No. The BaseVertex is the index offset to be added to each index in the index list for that primitive (https://www.opengl.org/wiki/Vertex_Rendering#Base_Index). Your indices appear to already have any such offset, so having a BaseVertex other than 0 makes no sense.

When I linked you to that page, I was kind of hoping you would read it.

A_Shuang
03-16-2015, 07:20 PM
No. The BaseVertex is the index offset to be added to each index in the index list for that primitive (https://www.opengl.org/wiki/Vertex_Rendering#Base_Index). Your indices appear to already have any such offset, so having a BaseVertex other than 0 makes no sense.

When I linked you to that page, I was kind of hoping you would read it.

I did that. Thanks. And I have already tried 0 before you said that, yet it still appeared not correctly. So I was assuming that I misunderstood it.

Alfonse Reinheart
03-16-2015, 07:29 PM
OK, show us the code that actually works. That is, the sequence of drawing commands that actually achieves what you're trying to do.