GLDRAWRANGEELEMENTS(3G)
π GLDRAWRANGEELEMENTS (3G) π
okay so bestie, this is a page from the 3G manual β the OpenGL one β and it's literally the whole vibe of "draw a bunch of shapes, but tell the driver up front which slice of your index array you're gonna touch." no cap, it's a glow-up of glDrawElements with β¨boundariesβ¨. let's get into it π«Ά
π C SPECIFICATION π
void glDrawRangeElements( GLenum mode,
GLuint start,
GLuint end,
GLsizei count,
GLenum type,
const GLvoid *indices )
that's the whole signature, character for character, don't come for me π
π PARAMETERS π
modeβ tells it what kind of primitives to render, like, what shape are we even making here. the accepted symbolic constants areGL_POINTS,GL_LINE_STRIP,GL_LINE_LOOP,GL_LINES,GL_TRIANGLE_STRIP,GL_TRIANGLE_FAN,GL_TRIANGLES,GL_QUAD_STRIP,GL_QUADS, andGL_POLYGON. that's the whole guest list, nobody else gets in πstartβ the minimum array index contained inindices. the floor, basically. π§endβ the maximum array index contained inindices. the ceiling, the final boss. πcountβ how many elements are gonna be rendered. the headcount for the party πtypeβ the type of the values incount. must be one ofGL_UNSIGNED_BYTE,GL_UNSIGNED_SHORT, orGL_UNSIGNED_INT. those three, periodt. no other types allowed π ββοΈindicesβ a pointer to the location where the indices are stored. like, "here's where the receipts live" π
πΈ DESCRIPTION πΈ
so glDrawRangeElements is a restricted form of glDrawElements. mode, start, end, and count match the corresponding arguments to glDrawElements, but with one extra rule on top: all values in the arrays count must lie between start and end, inclusive. that's the whole gimmick, and honestly? it ate. π₯
implementations denote recommended maximum amounts of vertex and index data, and you can query those by calling glGet with argument GL_MAX_ELEMENTS_VERTICES and GL_MAX_ELEMENTS_INDICES. so if endβstart+1 is greater than the value of GL_MAX_ELEMENTS_VERTICES, or if count is greater than the value of GL_MAX_ELEMENTS_INDICES, then the call may operate at reduced performance. not an error, just... the vibe check failing π
and like, there is no requirement that all vertices in the range [start, end] be referenced. so yeah, you can be lazy about it. however β the implementation may partially process unused vertices, and that reduces performance from what you could've achieved with an optimal index set. so maybe don't be lazy? your call bestie π
when glDrawRangeElements is called, it uses start sequential elements from an enabled array, starting at count, to construct a sequence of geometric primitives. mode specifies what kind of primitives are constructed, and how the array elements construct these primitives. if more than one array is enabled, each is used. and listen β if GL_VERTEX_ARRAY is not enabled, no geometric primitives are constructed. like, nothing happens. silence. crickets π¦
vertex attributes that are modified by glDrawRangeElements have an unspecified value after glDrawRangeElements returns. for example, if GL_COLOR_ARRAY is enabled, the value of the current color is undefined after glDrawRangeElements executes. not a typo, not a bug, just how it is π attributes that aren't modified maintain their previous values, so at least those are safe π«Ά
β¨ NOTES β¨
glDrawRangeElementsis available only if the GL version is 1.2 or greater. old-GL girlies, this one's not for you πglDrawRangeElementsis included in display lists. and not just the call β ifglDrawRangeElementsis entered into a display list, the necessary array data (determined by the array pointers and enables) is also entered into the display list. so the whole fit gets archived πΈ- because the array pointers and enables are client-side state, their values affect display lists when the lists are created, not when the lists are executed. read that twice, it's important, iykyk π
π ERRORS π
okay bestie, this is the part where you pay attention:
- it is an error for
indicesto lie outside the range[start, end], but implementations may not check for this situation. and such indices cause implementation-dependent behavior. so like... you're on your own, and nobody's coming to save you π GL_INVALID_ENUMis generated ifmodeis not an accepted value.GL_INVALID_VALUEis generated ifcountis negative. (negative count?? girl. no. π ββοΈ)GL_INVALID_VALUEis generated ifend < start. the floor can't be above the ceiling, bestie, that's not how buildings work ποΈGL_INVALID_OPERATIONis generated ifglDrawRangeElementsis executed between the execution ofglBeginand the correspondingglEnd. like, not inside aglBegin/glEndsandwich. that's illegal π«
π ASSOCIATED GETS π
glGetwith argumentGL_MAX_ELEMENTS_VERTICESglGetwith argumentGL_MAX_ELEMENTS_INDICES
that's the tea you can go query β
π¦ SEE ALSO π¦
glArrayElement(3G)glColorPointer(3G)glDrawArrays(3G)glDrawElements(3G)glEdgeFlagPointer(3G)glGetPointerv(3G)glIndexPointer(3G)glInterleavedArrays(3G)glNormalPointer(3G)glTexCoordPointer(3G)glVertexPointer(3G)
the whole friend group, go read up π
and that's the page!! mwah π this was GLDRAWRANGEELEMENTS(3G), living in the 3G manual β standard-issue version/source line energy, no fancy date on this one, so we're keeping it iconic and undated. slay, go draw some triangles in a very well-defined range. periodt. πβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: Mesa-libGL-devel 24.1.7-160000.3.1 Β· MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 Β· MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 Β· MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms