我对使用glMultiDrawElementsIndirect()感到困惑,是否有人可以向我解释该绘图命令使用的cmd结构的含义?
struct cmd:
count = ..
primCount = ..
firstIndex = ..
baseVertex = ..
baseInstance = ..
如果我有三个不同的三角形条画,那会是这样的吗?
for (int n = 0; n < 3; n++)
{
count = indexCount;
primCount = 1;
firstIndex = n * count;
baseVertex = 0;
baseInstance = n;
...
}
设置缓冲区:
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);
}
绘图命令:
gl.glBindVertexArray(vaoBuff.get(0));
glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, vboBuff.get(0));
gl.glMultiDrawElementsIndirect(GL4.GL_TRIANGLE_STRIP, GL4.GL_UNSIGNED_INT, null, 3, 0);
修正了它,顶点数据中出现了一些问题。另一个是正确的。