GLDRAWRANGEELEMENTS(3G)
π
GLDRAWRANGEELEMENTS β ok so bestie, let's talk about glDrawRangeElements
(that's a section of the OpenGL manual, and yeah the placeholder header literally says [FIXME: manual], we love a work-in-progress queen π)
πΈ NAME πΈ
glDrawRangeElements β render primitives from array data, but make it range-restricted β¨
π¦ C SPECIFICATION π¦
void glDrawRangeElements(GLenum mode, GLuint start, GLuint end,
GLsizei count, GLenum type,
const GLvoid * indices);
π PARAMETERS π
modeβ tells the GPU what kind of primitives to render, like, the whole vibe of the shape. It accepts these symbolic constants: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_ADJACENCYandGL_PATCHES.startβ the smallest array index that's chillin' insideindices.endβ the biggest array index that's chillin' insideindices.countβ how many elements you want rendered, like a headcount for the party πtypeβ what type the values inindicesare. Has to be one ofGL_UNSIGNED_BYTE,GL_UNSIGNED_SHORT, orGL_UNSIGNED_INT. That's it, that's the list, no negotiations πindicesβ a pointer to wherever you stashed the indices.
β¨ DESCRIPTION β¨
So glDrawRangeElements is basically glDrawElements() but with restrictions β it's the good-girl version, the one that stays in its lane. The mode and count arguments match the corresponding arguments to glDrawElements(), except there's this extra rule: every single value in the arrays count has to lie between start and end, inclusive. No sneaking out of range, bestie π
Implementations will tell you the recommended maximum amounts of vertex and index data, and you get those by calling glGet() with the argument GL_MAX_ELEMENTS_VERTICES and GL_MAX_ELEMENTS_INDICES. So here's the tea: 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. Like, it still works, it's just gonna be slower and a little sad about it π
And listen β there's no requirement that all vertices in the range start end actually get referenced. Nobody's forcing you. But the implementation may partially process unused vertices anyway, which reduces performance from what you could've achieved with an optimal index set. Basically if you're messy about your ranges, you pay for it. Lowkey tragic but that's the deal π«Ά
When glDrawRangeElements is called, it uses count sequential elements from an enabled array, starting at start, to construct a sequence of geometric primitives. The mode specifies what kind of primitives get constructed, and how the array elements construct these primitives. If more than one array is enabled, each is used. All of them. Every single one π
β οΈ Important vibe check: vertex attributes that are modified byglDrawRangeElementshave an unspecified value afterglDrawRangeElementsreturns. Attributes that aren't modified keep their previous values. So don't come crying to me about the ones that got touched, okay? That's undefined territory, that's not my business π
π NOTES π
GL_LINE_STRIP_ADJACENCY, GL_LINES_ADJACENCY, GL_TRIANGLE_STRIP_ADJACENCY and GL_TRIANGLES_ADJACENCY are only available if the GL version is 3.2 or greater. They're the VIP-only constants, iykyk π
π ERRORS π
- It is an error for
indicesto lie outside the rangestartendβ but implementations may not check for this situation. So like, you might just get away with it, and then what happens is implementation-dependent behavior. Which is a fancy way of saying "chaos, unpredicted, good luck" π Don't do it. GL_INVALID_ENUMgets generated ifmodeis not an accepted value.GL_INVALID_VALUEgets generated ifcountis negative. Negative elements? In this economy? No ma'am.GL_INVALID_VALUEgets generated ifend < start. The range has to go the right way, bestie, be serious.GL_INVALID_OPERATIONgets generated if a geometry shader is active andmodeis incompatible with the input primitive type of the geometry shader in the currently installed program object. Yes, that's a whole mouthful, and yes, it will yell at you.GL_INVALID_OPERATIONgets generated if a non-zero buffer object name is bound to an enabled array or the element array and the buffer object's data store is currently mapped. (Mapped = already busy. Don't double-book. Rude.)
π ASSOCIATED GETS π
glGet()with argumentGL_MAX_ELEMENTS_VERTICESglGet()with argumentGL_MAX_ELEMENTS_INDICES
π VERSION SUPPORT π
So the original is a big sparkly table called "Function / Feature Name" versus "OpenGL Version" and honestly the whole row is checks all the way down, bestie. glDrawRangeElements has been booked and busy since forever:
- 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 β
Every. Single. One. Ate and left no crumbs π₯
π§ SEE ALSO π§
glDrawArrays()glDrawElements()glDrawElementsBaseVertex()
(go read those too, they're the sibling lore π)
π COPYRIGHT π
Copyright Β© 1991-2006 Silicon Graphics, Inc. Copyright Β© 2010-2014 Khronos Group. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.
π COPYRIGHT (yes, again, there's two of them) π
Copyright Β© 1991-2006 Silicon Graphics, Inc. Copyright Β© 2010-2014 Khronos Group
π okay that's the whole page!! source note says[FIXME: source]and the date on this one is08/09/2021β so this manual page is a 2021 baby, iconic, and it's theGLDRAWRANGEELEMENTS(3G)page, mwah π go render something beautiful bestie β¨
π¦ 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