GLMULTIDRAWARRAYSIND(3G)

πŸ’… GLMULTIDRAWARRAYSIND πŸ’…

okay so bestie, this is a page from the 3G manual (yes, the OpenGL one), and it's about glMultiDrawArraysIndirect β€” the function that renders multiple sets of primitives from array data, taking its parameters from memory. no cap, it's a whole vibe. let's get into it 🫢


✨ C SPECIFICATION ✨

void glMultiDrawArraysIndirect(GLenum mode, const void *indirect,
                               GLsizei drawcount, GLsizei stride);

πŸŽ€ PARAMETERS πŸŽ€

  • mode β€” tells the GPU what kind of primitives to render. the accepted symbolic constants are GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_LINE_STRIP_ADJACENCY, GL_LINES_ADJACENCY, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_TRIANGLE_STRIP_ADJACENCY, GL_TRIANGLES_ADJACENCY, and GL_PATCHES. literally the whole roster πŸ’…
  • indirect β€” the address of an array of structures that hold the draw parameters. like, the receipt of what to draw.
  • drawcount β€” how many elements are in that array of draw parameter structures. count 'em.
  • stride β€” the distance, in basic machine units, between elements of the draw parameter array. the gap between besties in the lineup 🌸

πŸ”₯ DESCRIPTION πŸ”₯

glMultiDrawArraysIndirect specifies multiple geometric primitives with very few subroutine calls. it behaves similarly to a multitude of calls to glDrawArraysInstancedBaseInstance(), except that the parameters to each call to glDrawArraysInstancedBaseInstance() are stored in an array in memory at the address given by indirect, separated by the stride, in basic machine units, specified by stride. and if stride is zero? then the array is assumed to be tightly packed in memory. cozy. no gaps, no drama.

the parameters addressed by indirect are packed into an array of structures, and each element takes this form (in C):

typedef  struct {
    uint  count;
    uint  instanceCount;
    uint  first;
    uint  baseInstance;
} DrawArraysIndirectCommand;

a single call to glMultiDrawArraysIndirect is equivalent to this, assuming no errors are generated:

GLsizei n;
for (n = 0; n < drawcount; n++) {
    const DrawArraysIndirectCommand *cmd;
    if (stride != 0) {
        cmd = (const DrawArraysIndirectCommand  *)((uintptr)indirect + n * stride);
    } else  {
        cmd = (const DrawArraysIndirectCommand  *)indirect + n;
    }

    glDrawArraysInstancedBaseInstance(mode, cmd->first, cmd->count, cmd->instanceCount, cmd->baseInstance);
}
if a buffer is bound to the GL_DRAW_INDIRECT_BUFFER binding at the time of a call to glMultiDrawArraysIndirect, then indirect is interpreted as an offset, in basic machine units, into that buffer β€” and the parameter data is read from the buffer rather than from client memory. so it's giving "i live here now" 🏠

in contrast to glDrawArraysInstancedBaseInstance(), the first member of the parameter structure is unsigned, and out-of-range indices do not generate an error. iconic, honestly.

vertex attributes that are modified by glMultiDrawArraysIndirect have an unspecified value after glMultiDrawArraysIndirect returns. attributes that aren't modified remain well defined. so like… mind the ones you touched πŸ™ˆ


πŸ¦‹ NOTES πŸ¦‹

  • the baseInstance member of the DrawArraysIndirectCommand structure is defined only if the GL version is 4.2 or greater. for versions of the GL less than 4.2, this parameter is present but is reserved and should be set to zero. on earlier versions of the GL, behavior is undefined if it is non-zero. so fr fr, set it to zero. πŸ’€
  • glMultiDrawArraysIndirect is available only if the GL version is 4.3 or greater.

πŸ’€ ERRORS πŸ’€

  • GL_INVALID_ENUM is generated if mode is not an accepted value.
  • GL_INVALID_VALUE is generated if stride is not a multiple of four.
  • GL_INVALID_VALUE is generated if drawcount is negative.
  • GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to an enabled array or to the GL_DRAW_INDIRECT_BUFFER binding and the buffer object's data store is currently mapped.
  • GL_INVALID_OPERATION is generated if a geometry shader is active and mode is incompatible with the input primitive type of the geometry shader in the currently installed program object.
  • GL_INVALID_OPERATION is generated if mode is GL_PATCHES and no tessellation control shader is active.

🌈 VERSION SUPPORT 🌈

vibe check on which GL versions have glMultiDrawArraysIndirect:

  • OpenGL 2.0 β€” - (nope)
  • OpenGL 2.1 β€” - (nope)
  • OpenGL 3.0 β€” - (nope)
  • OpenGL 3.1 β€” - (nope)
  • OpenGL 3.2 β€” - (nope)
  • OpenGL 3.3 β€” - (nope)
  • OpenGL 4.0 β€” - (nope)
  • OpenGL 4.1 β€” - (nope)
  • OpenGL 4.2 β€” - (nope)
  • OpenGL 4.3 β€” βœ” (slay)
  • OpenGL 4.4 β€” βœ” (slay)
  • OpenGL 4.5 β€” βœ” (slay)

🌸 SEE ALSO 🌸

glDrawArrays(), glDrawArraysInstanced(), glDrawElements(), glDrawRangeElements(), glDrawArraysIndirect(), glMultiDrawElementsIndirect() β€” the whole friend group, go say hi πŸ’–


Copyright Β© 2012-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.

Copyright Β© 2012-2014 Khronos Group.


and that's the page, bestie πŸŽ€ source is [FIXME: source] and the date on it is 08/09/2021 β€” go forth and indirect-draw responsibly πŸ’œβœ¨

πŸ“¦ where this page comes from