GLBUFFERSTORAGE(3G)

okay so welcome to the GLBUFFERSTORAGE(3G) page β€” the whole manual name is literally in the house, and this one is all about creating and initializing a buffer object's immutable data store. buckle up, bestie, it's giving big OpenGL energy πŸ’…

✨ NAME ✨

glBufferStorage, glNamedBufferStorage β€” creates and initializes a buffer object's immutable data store. periodt.

🧾 C SPECIFICATION 🧾

void glBufferStorage(GLenum target, GLsizeiptr size,
                     const GLvoid * data, GLbitfield flags);

void glNamedBufferStorage(GLuint buffer, GLsizeiptr size,
                          const void *data, GLbitfield flags);

🌸 PARAMETERS 🌸

  • target β€” specifies the target to which the buffer object is bound for glBufferStorage, and it must be one of the buffer binding targets in the following list. the original had a whole table, but tables aren't allowed in this terminal glow-up, so every single row is right here instead:
    • 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 the glNamedBufferStorage function. yes bestie, this one is for the named-buffer girlies.
  • size β€” specifies the size in bytes of the buffer object's new data store. it's the whole "how much room are we giving this thing" number.
  • data β€” specifies a pointer to data that will be copied into the data store for initialization, or NULL if no data is to be copied. literally "do you have starter data or not."
  • flags β€” specifies the intended usage of the buffer's data store. must be a bitwise combination of the following flags: GL_DYNAMIC_STORAGE_BIT, GL_MAP_READ_BIT, GL_MAP_WRITE_BIT, GL_MAP_PERSISTENT_BIT, GL_MAP_COHERENT_BIT, and GL_CLIENT_STORAGE_BIT.

πŸ’– DESCRIPTION πŸ’–

glBufferStorage and glNamedBufferStorage create a new immutable data store. for glBufferStorage, the buffer object currently bound to target will be initialized. for glNamedBufferStorage, buffer is the name of the buffer object that will be configured. the size of the data store is specified by size. if an initial data is available, its address may be supplied in data. otherwise, to create an uninitialized data store, data should be NULL.

the flags parameter specifies the intended usage of the buffer's data store. it must be a bitwise combination of a subset of the following flags:

  • GL_DYNAMIC_STORAGE_BIT β€” the contents of the data store may be updated after creation through calls to glBufferSubData(). if this bit is not set, the buffer content may not be directly updated by the client. the data argument may be used to specify the initial content of the buffer's data store regardless of the presence of the GL_DYNAMIC_STORAGE_BIT. regardless of the presence of this bit, buffers may always be updated with server-side calls such as glCopyBufferSubData() and glClearBufferSubData().
  • GL_MAP_READ_BIT β€” the data store may be mapped by the client for read access and a pointer in the client's address space obtained that may be read from.
  • GL_MAP_WRITE_BIT β€” the data store may be mapped by the client for write access and a pointer in the client's address space obtained that may be written through.
  • GL_MAP_PERSISTENT_BIT β€” the client may request that the server read from or write to the buffer while it is mapped. the client's pointer to the data store remains valid so long as the data store is mapped, even during execution of drawing or dispatch commands. iconic persistent behavior, honestly.
  • GL_MAP_COHERENT_BIT β€” shared access to buffers that are simultaneously mapped for client access and are used by the server will be coherent, so long as that mapping is performed using glMapBufferRange(). that is, data written to the store by either the client or server will be immediately visible to the other with no further action taken by the application. in particular:
    • if GL_MAP_COHERENT_BIT is not set and the client performs a write followed by a call to the glMemoryBarrier() command with the GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT set, then in subsequent commands the server will see the writes.
    • if GL_MAP_COHERENT_BIT is set and the client performs a write, then in subsequent commands the server will see the writes.
    • if GL_MAP_COHERENT_BIT is not set and the server performs a write, the application must call glMemoryBarrier() with the GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT set and then call glFenceSync() with GL_SYNC_GPU_COMMANDS_COMPLETE (or glFinish). then the CPU will see the writes after the sync is complete.
    • if GL_MAP_COHERENT_BIT is set and the server does a write, the app must call glFenceSync with GL_SYNC_GPU_COMMANDS_COMPLETE (or glFinish()). then the CPU will see the writes after the sync is complete.
  • GL_CLIENT_STORAGE_BIT β€” when all other criteria for the buffer storage allocation are met, this bit may be used by an implementation to determine whether to use storage that is local to the server or to the client to serve as the backing store for the buffer.

the allowed combinations of flags are subject to certain restrictions. they are as follows:

  • if flags contains GL_MAP_PERSISTENT_BIT, it must also contain at least one of GL_MAP_READ_BIT or GL_MAP_WRITE_BIT.
  • if flags contains GL_MAP_COHERENT_BIT, it must also contain GL_MAP_PERSISTENT_BIT.

πŸŽ€ NOTES πŸŽ€

glBufferStorage is available only if the GL version is 4.4 or greater.

glNamedBufferStorage is available only if the GL version is 4.5 or greater.

if data is NULL, a data store of the specified size is still created, but its contents remain uninitialized and thus undefined. so like… it exists, but it's not giving initialized content, bestie. proceed accordingly πŸ’€

πŸ’€ ERRORS πŸ’€

  • GL_INVALID_ENUM is generated by glBufferStorage if target is not one of the accepted buffer targets.
  • GL_INVALID_OPERATION is generated by glNamedBufferStorage if buffer is not the name of an existing buffer object.
  • GL_INVALID_VALUE is generated if size is less than or equal to zero.
  • GL_INVALID_OPERATION is generated by glBufferStorage if the reserved buffer object name 0 is bound to target.
  • GL_OUT_OF_MEMORY is generated if the GL is unable to create a data store with the properties requested in flags.
  • GL_INVALID_VALUE is generated if flags has any bits set other than those defined above.
  • GL_INVALID_VALUE error is generated if flags contains GL_MAP_PERSISTENT_BIT but does not contain at least one of GL_MAP_READ_BIT or GL_MAP_WRITE_BIT.
  • GL_INVALID_VALUE is generated if flags contains GL_MAP_COHERENT_BIT, but does not also contain GL_MAP_PERSISTENT_BIT.
  • GL_INVALID_OPERATION is generated by glBufferStorage if the GL_BUFFER_IMMUTABLE_STORAGE flag of the buffer bound to target is GL_TRUE.

πŸ” ASSOCIATED GETS πŸ”

  • glGetBufferSubData()
  • glGetBufferParameter() with argument GL_BUFFER_SIZE or GL_BUFFER_USAGE

✨ VERSION SUPPORT ✨

okay bestie, here's the vibe check on when you can actually use these functions πŸ’… the columns are the OpenGL versions, the rows are the function/feature names:

  • glBufferStorage β€” OpenGL 2.0: -, 2.1: -, 3.0: -, 3.1: -, 3.2: -, 3.3: -, 4.0: -, 4.1: -, 4.2: -, 4.3: -, 4.4: βœ”, 4.5: βœ”
  • glNamedBufferStorage β€” OpenGL 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, glBufferStorage is giving "I've been here since 4.4" and glNamedBufferStorage is literally the 4.5-only baby of the family 😭 no cap, check your context version before you call these or you're gonna have a bad time πŸ™ˆ


🌈 SEE ALSO 🌈

go read these next, they're the whole friend group fr fr:

  • glBindBuffer()
  • glBufferSubData()
  • glMapBuffer()
  • glUnmapBuffer()

Copyright Β© 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 Β© 2014 Khronos Group


and that's the whole page, bestie 🫢✨ this lil icon was brought to you by source <bold>[FIXME: source]</bold>, dated <bold>08/09/2021</bold>, filed under GLBUFFERSTORAGE(3G) β€” mwah πŸ’‹ go forth and allocate some storage πŸŽ€

πŸ“¦ where this page comes from