GLDRAWELEMENTSINSTAN(3G)
π GLDRAWELEMENTSINSTAN(3G) π
okay so this is a page from the [FIXME: manual] situation β yes bestie, the manual name literally says FIXME, we don't ask questions π β and it's all about one extremely specific OpenGL function that lets you draw the same pile of elements a whole bunch of times, except every round gets its own little offset for instanced attributes. iykyk β¨
πΈ NAME πΈ
glDrawElementsInstancedBaseInstance β draws multiple instances of a set of elements, with offset applied to instanced attributes. it's giving "one draw call, many vibes" π
π C SPECIFICATION π
void glDrawElementsInstancedBaseInstance(GLenum mode, GLsizei count,
GLenum type,
const void * indices,
GLsizei primcount,
GLuint baseinstance);
π¦ 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_ADJACENCYandGL_PATCHES. that's the whole guest list, no plus-ones πcountβ how many elements you're rendering. the headcount, basically.typeβ the type of the values sitting inindices. has to be one ofGL_UNSIGNED_BYTE,GL_UNSIGNED_SHORT, orGL_UNSIGNED_INT. pick wrong and it's not gonna be cute π₯indicesβ a pointer to the location where the indices are stored. where the lore lives.primcountβ the number of instances of the specified range of indices to be rendered. yes, we're doing this multiple times. main character energy πbaseinstanceβ the base instance used when fetching instanced vertex attributes. it's a little offset with a big job π«Ά
β¨ DESCRIPTION β¨
so glDrawElementsInstancedBaseInstance behaves identically to glDrawElements(), except that primcount instances of the set of elements are executed, and the value of the internal counter instanceID advances for each iteration. instanceID is an internal 32-bit integer counter that a vertex shader can read as gl_InstanceID. literally the shader's little window into which instance it's currently on π
glDrawElementsInstancedBaseInstance has the same effect as this whole situation right here:
if (mode, count, or type is invalid )
generate appropriate error
else {
for (int i = 0; i < primcount ; i++) {
instanceID = i;
glDrawElements(mode, count, type, indices);
}
instanceID = 0;
}
specific vertex attributes may be classified as instanced through the use of glVertexAttribDivisor(). instanced vertex attributes supply per-instance vertex data to the vertex shader. the index of the vertex fetched from the enabled instanced vertex attribute arrays is calculated as gl _ InstanceID divisor + baseInstance. β οΈ and note bestie: baseinstance does not affect the shader-visible value of gl_InstanceID. it's a sneaky little thing that only touches the attribute fetching, not the counter itself π
π NOTES π
glDrawElementsInstancedBaseInstanceis available only if the GL version is4.2or greater. no 4.2, no function, no exceptions πGL_LINE_STRIP_ADJACENCY,GL_LINES_ADJACENCY,GL_TRIANGLE_STRIP_ADJACENCYandGL_TRIANGLES_ADJACENCYare available only if the GL version is3.2or greater. so those four have their own whole entry requirement, iconic behavior honestly π
π₯ ERRORS π₯
GL_INVALID_ENUMis generated ifmodeis not one ofGL_POINTS,GL_LINE_STRIP,GL_LINE_LOOP,GL_LINES,GL_TRIANGLE_STRIP,GL_TRIANGLE_FAN, orGL_TRIANGLES. (notice this list is shorter than the parameter list β yes, we're being precise, don't @ me β¨)GL_INVALID_VALUEis generated ifcountorprimcountare negative. negative. nope. absolutely not π«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. geometry shader said "that's not my type" πGL_INVALID_OPERATIONis generated if a non-zero buffer object name is bound to an enabled array and the buffer object's data store is currently mapped. mapped memory and drawing are not on speaking terms rn π
π VERSION SUPPORT π
the feature name is glDrawElementsInstancedBaseInstance β here's the vibe check across OpenGL versions, β meaning supported and - meaning nope:
- OpenGL
2.0β- - OpenGL
2.1β- - OpenGL
3.0β- - OpenGL
3.1β- - OpenGL
3.2β- - OpenGL
3.3β- - OpenGL
4.0β- - OpenGL
4.1β- - OpenGL
4.2ββ - OpenGL
4.3ββ - OpenGL
4.4ββ - OpenGL
4.5ββ
so likeβ¦ it shows up at 4.2 and then never leaves. consistent queen π
π SEE ALSO π
glDrawElements()glDrawArraysInstanced()
go read those next, bestie, they're the supporting cast π«Ά
β COPYRIGHT β
Copyright Β© 2011-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 Β© 2011-2014 Khronos Group
ok that's the whole page, no skips, no cap π
and finally, the sign-off: this beauty came from [FIXME: source] and it's dated 08/09/2021, so go forth and instance responsibly, you absolute icon π§ββοΈπ
π¦ 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