GLBINDBUFFER(3G)
π glBindBuffer β bind a named buffer object
okay bestie, welcome to GLBINDBUFFER(3G), the manual page where we learn how to tell OpenGL "hey, this buffer? yeah, it's the main character now." π
πΈ NAME
glBindBuffer β bind a named buffer object β¨
π¦ C SPECIFICATION
void glBindBuffer(GLenum target, GLuint buffer);
that's it, that's the whole signature, no cap π
π PARAMETERS
targetβ specifies the target to which the buffer object is bound, and it must be one of the buffer binding targets in this list (no improvising, bestie, the spec is watching π):GL_ARRAY_BUFFERβ vertex attributesGL_ATOMIC_COUNTER_BUFFERβ atomic counter storageGL_COPY_READ_BUFFERβ buffer copy sourceGL_COPY_WRITE_BUFFERβ buffer copy destinationGL_DISPATCH_INDIRECT_BUFFERβ indirect compute dispatch commandsGL_DRAW_INDIRECT_BUFFERβ indirect command argumentsGL_ELEMENT_ARRAY_BUFFERβ vertex array indicesGL_PIXEL_PACK_BUFFERβ pixel read targetGL_PIXEL_UNPACK_BUFFERβ texture data sourceGL_QUERY_BUFFERβ query result bufferGL_SHADER_STORAGE_BUFFERβ read-write storage for shadersGL_TEXTURE_BUFFERβ texture data bufferGL_TRANSFORM_FEEDBACK_BUFFERβ transform feedback bufferGL_UNIFORM_BUFFERβ uniform block storage
bufferβ specifies the name of a buffer object π«Ά
β¨ DESCRIPTION
so glBindBuffer binds a buffer object to the specified buffer binding point. literally that's the vibe. when you call glBindBuffer with target set to one of the accepted symbolic constants and buffer set to the name of a buffer object, it binds that buffer object name to the target. and if no buffer object with name buffer exists yet? it just makes one with that name. iconic behaviour, honestly π
when a buffer object is bound to a target, the previous binding for that target is automatically broken. no messy breakups, it's handled. π
buffer object names are unsigned integers. the value zero is reserved, but β and this is the plot twist β there is no default buffer object for each buffer object target. instead, buffer set to zero effectively unbinds any buffer object previously bound, and restores client memory usage for that buffer object target (if supported for that target). so zero is giving "we're so over" energy.
buffer object names and the corresponding buffer object contents are local to the shared object space of the current GL rendering context π β two rendering contexts share buffer object names only if they explicitly enable sharing between contexts through the appropriate GL windows interfaces functions. iykyk.
glGenBuffers() must be used to generate a set of unused buffer object names. like, that's the assignment, do it. π
the state of a buffer object immediately after it is first bound is an unmapped zero-sized memory buffer with GL_READ_WRITE access and GL_STATIC_DRAW usage. fresh out of the wrapper, tiny, and full of potential π₯Ί
while a non-zero buffer object name is bound, GL operations on the target to which it is bound affect the bound buffer object, and queries of the target to which it is bound return state from the bound buffer object. while buffer object name zero is bound, as in the initial state, attempts to modify or query state on the target to which it is bound generates an GL_INVALID_OPERATION error. so yeah, zero is not your friend for that π
π the target-by-target lore (yes, there's lore)
GL_ARRAY_BUFFER β when a non-zero buffer object is bound to the GL_ARRAY_BUFFER target, the vertex array pointer parameter is interpreted as an offset within the buffer object measured in basic machine units.
GL_DRAW_INDIRECT_BUFFER β when a non-zero buffer object is bound to the GL_DRAW_INDIRECT_BUFFER target, parameters for draws issued through glDrawArraysIndirect() and glDrawElementsIndirect() are sourced from the specified offset in that buffer object's data store.
GL_DISPATCH_INDIRECT_BUFFER β when a non-zero buffer object is bound to the GL_DISPATCH_INDIRECT_BUFFER target, the parameters for compute dispatches issued through glDispatchComputeIndirect() are sourced from the specified offset in that buffer object's data store.
GL_ELEMENT_ARRAY_BUFFER β while a non-zero buffer object is bound to the GL_ELEMENT_ARRAY_BUFFER target, the indices parameter of glDrawElements(), glDrawElementsInstanced(), glDrawElementsBaseVertex(), glDrawRangeElements(), glDrawRangeElementsBaseVertex(), glMultiDrawElements(), or glMultiDrawElementsBaseVertex() is interpreted as an offset within the buffer object measured in basic machine units. that's a lot of functions, bestie, hydrate π§
GL_PIXEL_PACK_BUFFER β while a non-zero buffer object is bound to the GL_PIXEL_PACK_BUFFER target, the following commands are affected: glGetCompressedTexImage(), glGetTexImage(), and glReadPixels(). the pointer parameter is interpreted as an offset within the buffer object measured in basic machine units.
GL_PIXEL_UNPACK_BUFFER β while a non-zero buffer object is bound to the GL_PIXEL_UNPACK_BUFFER target, the following commands are affected: glCompressedTexImage1D(), glCompressedTexImage2D(), glCompressedTexImage3D(), glCompressedTexSubImage1D(), glCompressedTexSubImage2D(), glCompressedTexSubImage3D(), glTexImage1D(), glTexImage2D(), glTexImage3D(), glTexSubImage1D(), glTexSubImage2D(), and glTexSubImage3D(). the pointer parameter is interpreted as an offset within the buffer object measured in basic machine units.
GL_COPY_READ_BUFFER and GL_COPY_WRITE_BUFFER β these two targets are provided to allow glCopyBufferSubData() to be used without disturbing the state of other bindings π¦. however, glCopyBufferSubData() may be used with any pair of buffer binding points. flexible queen behaviour.
GL_TRANSFORM_FEEDBACK_BUFFER β this buffer binding point may be passed to glBindBuffer, but it will not directly affect transform feedback state. instead, the indexed GL_TRANSFORM_FEEDBACK_BUFFER bindings must be used through a call to glBindBufferBase() or glBindBufferRange(). this will affect the generic GL_TRANSFORM_FEEDBACK_BUFFER binding. so close, yet so far π
likewise, the GL_UNIFORM_BUFFER, GL_ATOMIC_COUNTER_BUFFER and GL_SHADER_STORAGE_BUFFER buffer binding points may be used, but do not directly affect uniform buffer, atomic counter buffer or shader storage buffer state, respectively. glBindBufferBase() or glBindBufferRange() must be used to bind a buffer to an indexed uniform buffer, atomic counter buffer or shader storage buffer binding point. yes, you need the other function, sorry bestie π
GL_QUERY_BUFFER β this binding point is used to specify a buffer object that is to receive the results of query objects through calls to the glGetQueryObject() family of commands. very "results are in, and they're going in a buffer" π
π how long does a binding even last
a buffer object binding created with glBindBuffer remains active until a different buffer object name is bound to the same target, or until the bound buffer object is deleted with glDeleteBuffers(). loyalty periodt π₯
once created, a named buffer object may be re-bound to any target as often as needed. glow-up, rebrand, whatever. however β and this is the fine print β the GL implementation may make choices about how to optimize the storage of a buffer object based on its initial binding target. so first impressions lowkey matter π
π§ NOTES
version check time, bestie β not everything is available everywhere:
- the
GL_COPY_READ_BUFFER,GL_UNIFORM_BUFFERandGL_TEXTURE_BUFFERtargets are available only if the GL version is 3.1 or greater. - the
GL_ATOMIC_COUNTER_BUFFERtarget is available only if the GL version is 4.2 or greater. - the
GL_DISPATCH_INDIRECT_BUFFERandGL_SHADER_STORAGE_BUFFERtargets are available only if the GL version is 4.3 or greater. - the
GL_QUERY_BUFFERtarget is available only if the GL version is 4.4 or greater.
π ERRORS
GL_INVALID_ENUMis generated iftargetis not one of the allowable values.GL_INVALID_VALUEis generated ifbufferis not a name previously returned from a call toglGenBuffers().
β οΈ ok so real talk, those two errors are not a vibe. pass a badtargetor abuffername you never got fromglGenBuffers()and GL will call you out. no cap.
still with me? good, because there's more coming π
π ASSOCIATED GETS π
okay so if you ever wanna peek at what's currently bound, these are the glGet() calls that'll tell you π β just pass the argument and it hands you back the current binding for that target, no cap:
glGet()with argumentGL_ARRAY_BUFFER_BINDINGglGet()with argumentGL_ATOMIC_COUNTER_BUFFER_BINDINGglGet()with argumentGL_COPY_READ_BUFFER_BINDINGglGet()with argumentGL_COPY_WRITE_BUFFER_BINDINGglGet()with argumentGL_DRAW_INDIRECT_BUFFER_BINDINGglGet()with argumentGL_DISPATCH_INDIRECT_BUFFER_BINDINGglGet()with argumentGL_ELEMENT_ARRAY_BUFFER_BINDINGglGet()with argumentGL_PIXEL_PACK_BUFFER_BINDINGglGet()with argumentGL_PIXEL_UNPACK_BUFFER_BINDINGglGet()with argumentGL_SHADER_STORAGE_BUFFER_BINDINGglGet()with argumentGL_TRANSFORM_FEEDBACK_BUFFER_BINDINGglGet()with argumentGL_UNIFORM_BUFFER_BINDING
like, one per target, bestie. collect 'em all π
β¨ VERSION SUPPORT β¨
okay this part is literally just the vibe check on when you can use this function, and spoiler: it's everywhere π₯
glBindBufferβ supported (β) in OpenGL 2.0, 2.1, 3.0, 3.1, 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, and 4.5
that's right. every single one. twelve for twelve. she ate and left zero crumbs ππ
π¦ SEE ALSO π¦
go be nosy, i love that for you β these are the related calls worth a scroll:
glGenBuffers()glBindBufferBase()glBindBufferRange()glMapBuffer()glUnmapBuffer()glDeleteBuffers()glGet()glIsBuffer()
iykyk, the whole buffer friend group πΈ
π COPYRIGHT π
Copyright Β© 2005 Addison-Wesley. Copyright Β© 2010-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 (yes, again, there's two of them β love that for us) π
Copyright Β© 2005 Sams Publishing
Copyright Β© 2010-2014 Khronos Group
and that's the whole page, bestie π«Ά this lil gem comes from [FIXME: source], dated 08/09/2021, and it's filed under GLBINDBUFFER(3G) β go forth and bind 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