GLGETBUFFERSUBDATA(3G)

πŸ’… GLGETBUFFERSUBDATA(3G) β€” the girlies' guide ✨

okay so this is a page from the 3G manual (the OpenGL girlies know πŸ‘‘), and it's literally all about glGetBufferSubData and glGetNamedBufferSubData. Come sit with me bestie, we're gonna read the data store together 🫢


🌸 NAME 🌸

glGetBufferSubData, glGetNamedBufferSubData β€” returns a subset of a buffer object's data store. yeah. that's the whole vibe. it grabs a lil slice of your buffer's data and hands it to you πŸ’–


✨ C SPECIFICATION ✨

like, the actual signatures, no cap:

void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size,
                        GLvoid * data);

void glGetNamedBufferSubData(GLuint buffer, GLintptr offset,
                             GLsizeiptr size, void *data);

πŸŽ€ PARAMETERS πŸŽ€

so here's what you're feeding it:

  • target β€” specifies the target to which the buffer object is bound for glGetBufferSubData, which must be one of the buffer binding targets in the following table. and like, obvi I'm putting it in a list for u, tables are so 2010s πŸ’€
    • GL_ARRAY_BUFFER β€” vertex attributes 🌈
    • GL_ATOMIC_COUNTER_BUFFER β€” atomic counter storage ⭐
    • GL_COPY_READ_BUFFER β€” buffer copy source
    • GL_COPY_WRITE_BUFFER β€” buffer copy destination
    • GL_DISPATCH_INDIRECT_BUFFER β€” indirect compute dispatch commands
    • GL_DRAW_INDIRECT_BUFFER β€” indirect command arguments
    • GL_ELEMENT_ARRAY_BUFFER β€” vertex array indices
    • GL_PIXEL_PACK_BUFFER β€” pixel read target
    • GL_PIXEL_UNPACK_BUFFER β€” texture data source
    • GL_QUERY_BUFFER β€” query result buffer
    • GL_SHADER_STORAGE_BUFFER β€” read-write storage for shaders
    • GL_TEXTURE_BUFFER β€” texture data buffer
    • GL_TRANSFORM_FEEDBACK_BUFFER β€” transform feedback buffer
    • GL_UNIFORM_BUFFER β€” uniform block storage
  • buffer β€” specifies the name of the buffer object for glGetNamedBufferSubData. the name!! as in, the buffer's name, bestie 🏷️
  • offset β€” specifies the offset into the buffer object's data store from which data will be returned, measured in bytes. yes, bytes. count them carefully 🧚
  • size β€” specifies the size in bytes of the data store region being returned πŸ“
  • data β€” specifies a pointer to the location where buffer object data is returned. it's giving "you provide the empty cup, GL pours the juice" πŸ“

πŸ¦‹ DESCRIPTION πŸ¦‹

glGetBufferSubData and glGetNamedBufferSubData return some or all of the data contents of the data store of the specified buffer object. literally some or all, your choice, main character energy πŸ‘‘

Data starting at byte offset and extending for size bytes is copied from the buffer object's data store to the memory pointed to by data.

An error is thrown if the buffer object is currently mapped, or if offset and size together define a range beyond the bounds of the buffer object's data store. like, don't try it πŸ’€

πŸ’œ NOTES πŸ’œ

  • If an error is generated, no change is made to the contents of data. so your buffer's still your buffer, no harm done 🫢
  • The GL_ATOMIC_COUNTER_BUFFER target is available only if the GL version is 4.2 or greater.
  • The GL_DISPATCH_INDIRECT_BUFFER and GL_SHADER_STORAGE_BUFFER targets are available only if the GL version is 4.3 or greater.
  • The GL_QUERY_BUFFER target is available only if the GL version is 4.4 or greater.

(version gatekeeping, honestly. we've all been there πŸ™ˆ)


πŸ’€ ERRORS πŸ’€

the "not me generating an error" moments, let's go:

  • GL_INVALID_ENUM is generated by glGetBufferSubData if target is not one of the generic buffer binding targets.
  • GL_INVALID_OPERATION is generated by glGetBufferSubData if zero is bound to target. zero is literally nothing, bestie, you gotta bind something 😭
  • GL_INVALID_OPERATION is generated by glGetNamedBufferSubData if buffer is not the name of an existing buffer object.
  • GL_INVALID_VALUE is generated if offset or size is negative, or if $offset + size$ is greater than the value of GL_BUFFER_SIZE for the buffer object.
  • GL_INVALID_OPERATION is generated if the buffer object is mapped with glMapBufferRange() or glMapBuffer(), unless it was mapped with the GL_MAP_PERSISTENT_BIT bit set in the glMapBufferRange access flags.

🌈 VERSION SUPPORT 🌈

the compatibility glow-up timeline ✨ (yes I'm listing every single one, we don't skip here)

  • glGetBufferSubData β€” supported in: 2.0 βœ”, 2.1 βœ”, 3.0 βœ”, 3.1 βœ”, 3.2 βœ”, 3.3 βœ”, 4.0 βœ”, 4.1 βœ”, 4.2 βœ”, 4.3 βœ”, 4.4 βœ”, 4.5 βœ”
  • glGetNamedBufferSubData β€” supported in: 2.0 -, 2.1 -, 3.0 -, 3.1 -, 3.2 -, 3.3 -, 4.0 -, 4.1 -, 4.2 -, 4.3 -, 4.4 -, 4.5 βœ”

so like glGetNamedBufferSubData only showed up for 4.5. iconic of her honestly, fashionably late πŸ’…


🐚 SEE ALSO 🐚

go read these next, iykyk:

glBindBuffer(), glBufferData(), glBufferSubData(), glMapBuffer(), glUnmapBuffer()


Copyright Β© 2005 Addison-Wesley. 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 Β© 2005 Sams Publishing Copyright Β© 2011-2014 Khronos Group


and that's the page babes πŸ’– it's from [FIXME: source], version dated 08/09/2021, and it goes out to the whole GLGETBUFFERSUBDATA(3G) crew. slay, go read your buffers responsibly βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from