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 forglBufferStorage, 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 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 the buffer object for theglNamedBufferStoragefunction. 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, orNULLif 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, andGL_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 toglBufferSubData(). if this bit is not set, the buffer content may not be directly updated by the client. thedataargument may be used to specify the initial content of the buffer's data store regardless of the presence of theGL_DYNAMIC_STORAGE_BIT. regardless of the presence of this bit, buffers may always be updated with server-side calls such asglCopyBufferSubData()andglClearBufferSubData().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 usingglMapBufferRange(). 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_BITis not set and the client performs a write followed by a call to theglMemoryBarrier()command with theGL_CLIENT_MAPPED_BUFFER_BARRIER_BITset, then in subsequent commands the server will see the writes. - if
GL_MAP_COHERENT_BITis set and the client performs a write, then in subsequent commands the server will see the writes. - if
GL_MAP_COHERENT_BITis not set and the server performs a write, the application must callglMemoryBarrier()with theGL_CLIENT_MAPPED_BUFFER_BARRIER_BITset and then callglFenceSync()withGL_SYNC_GPU_COMMANDS_COMPLETE(orglFinish). then the CPU will see the writes after the sync is complete. - if
GL_MAP_COHERENT_BITis set and the server does a write, the app must callglFenceSyncwithGL_SYNC_GPU_COMMANDS_COMPLETE(orglFinish()). then the CPU will see the writes after the sync is complete.
- if
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
flagscontainsGL_MAP_PERSISTENT_BIT, it must also contain at least one ofGL_MAP_READ_BITorGL_MAP_WRITE_BIT. - if
flagscontainsGL_MAP_COHERENT_BIT, it must also containGL_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.
ifdataisNULL, 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_ENUMis generated byglBufferStorageiftargetis not one of the accepted buffer targets.GL_INVALID_OPERATIONis generated byglNamedBufferStorageifbufferis not the name of an existing buffer object.GL_INVALID_VALUEis generated ifsizeis less than or equal to zero.GL_INVALID_OPERATIONis generated byglBufferStorageif the reserved buffer object name0is bound totarget.GL_OUT_OF_MEMORYis generated if the GL is unable to create a data store with the properties requested inflags.GL_INVALID_VALUEis generated ifflagshas any bits set other than those defined above.GL_INVALID_VALUEerror is generated ifflagscontainsGL_MAP_PERSISTENT_BITbut does not contain at least one ofGL_MAP_READ_BITorGL_MAP_WRITE_BIT.GL_INVALID_VALUEis generated ifflagscontainsGL_MAP_COHERENT_BIT, but does not also containGL_MAP_PERSISTENT_BIT.GL_INVALID_OPERATIONis generated byglBufferStorageif theGL_BUFFER_IMMUTABLE_STORAGEflag of the buffer bound totargetisGL_TRUE.
π ASSOCIATED GETS π
glGetBufferSubData()glGetBufferParameter()with argumentGL_BUFFER_SIZEorGL_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β OpenGL2.0:-,2.1:-,3.0:-,3.1:-,3.2:-,3.3:-,4.0:-,4.1:-,4.2:-,4.3:-,4.4:β,4.5:βglNamedBufferStorageβ OpenGL2.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 π
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
- 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