DrawingGL 4.6

glMultiDrawElementsIndirectCount

glMultiDrawElementsIndirect where the number of draws is also read from a GPU buffer.

Signature

void glMultiDrawElementsIndirectCount(GLenum mode, GLenum type, const void *indirect,
                                      GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);

How it works

With glMultiDrawElementsIndirect the CPU still passes drawcount. Here a culling shader can compact the visible objects' commands to the front of the buffer and write how many there are; the draw reads that count from the buffer bound to GL_PARAMETER_BUFFER. Nothing about the visible set goes back to the CPU.

Parameters

mode, typeGLenum
indirectconst void *

Offset of the first command.

drawcountGLintptr

Byte OFFSET of a GLuint count in the GL_PARAMETER_BUFFER (not the count itself).

maxdrawcountGLsizei

Upper limit, in case the count in the buffer is larger.

strideGLsizei

Bytes between commands; 0 = tightly packed.

Errors

When the call is invalid it does nothing and sets an error, which glGetError returns:

GL_INVALID_OPERATION
No buffer bound to GL_PARAMETER_BUFFER or GL_DRAW_INDIRECT_BUFFER.
GL_INVALID_VALUE
drawcount is not a multiple of 4.

Example

example.cpp
1glBindBuffer(GL_DRAW_INDIRECT_BUFFER, visibleCmds);
2glBindBuffer(GL_PARAMETER_BUFFER, visibleCount);
3glMultiDrawElementsIndirectCount(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr,
4                                 0, maxObjects, 0);
Official Khronos documentation