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 areGL_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, andGL_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 theGL_DRAW_INDIRECT_BUFFERbinding at the time of a call toglMultiDrawArraysIndirect, thenindirectis 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
baseInstancemember of theDrawArraysIndirectCommandstructure 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. π glMultiDrawArraysIndirectis available only if the GL version is 4.3 or greater.
π ERRORS π
GL_INVALID_ENUMis generated ifmodeis not an accepted value.GL_INVALID_VALUEis generated ifstrideis not a multiple of four.GL_INVALID_VALUEis generated ifdrawcountis negative.GL_INVALID_OPERATIONis generated if a non-zero buffer object name is bound to an enabled array or to theGL_DRAW_INDIRECT_BUFFERbinding and the buffer object's data store is currently mapped.GL_INVALID_OPERATIONis generated if a geometry shader is active andmodeis incompatible with the input primitive type of the geometry shader in the currently installed program object.GL_INVALID_OPERATIONis generated ifmodeisGL_PATCHESand 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 π
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
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 Β· MIT and Open Publication
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms