GLMAPBUFFER(3G)
π GLMAPBUFFER(3G) β mapping a whole buffer's data store into your address space, no cap β¨
okay so first things first bestie, this is the page for GLMAPBUFFER(3G) β yes, both glMapBuffer and glMapNamedBuffer live here, they're literally sisters π«Ά β and it's a long one, so buckle up.
πΈ NAME πΈ
glMapBuffer, glMapNamedBuffer β map all of a buffer object's data store into the client's address space. the whole thing. the entire store. no crumbs left behind π
β¨ C SPECIFICATION β¨
void *glMapBuffer(GLenum target, GLenum access);
void *glMapNamedBuffer(GLuint buffer, GLenum access);
like, that's it. two little functions. two little pointers. iconic behavior honestly π
π PARAMETERS π
targetβ specifies the target to which the buffer object is bound forglMapBuffer, and it must be one of the buffer binding targets in the following list, okay? no improvising πGL_ARRAY_BUFFERβ vertex attributes πΈGL_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 forglMapNamedBuffer. like, the actual name-name π·οΈaccessβ specifies the access policy forglMapBufferandglMapNamedBuffer, i.e. whether you'll be able to read from it, write to it, or both read from and write to the buffer object's mapped data store. this symbolic constant has to beGL_READ_ONLY,GL_WRITE_ONLY, orGL_READ_WRITE. those three. that's the whole list. π
π¦ DESCRIPTION π¦
glMapBuffer and glMapNamedBuffer map the entire data store of a specified buffer object into the client's address space. yes, the entire data store, we're not doing partials here. the data can then be directly read and/or written relative to the returned pointer, depending on the access policy you specified. it's giving direct line to the data π₯
a pointer to the beginning of the mapped range is returned once all pending operations on that buffer object have completed β and then you can use it to modify and/or query the corresponding range of the data store according to the value of access:
GL_READ_ONLYindicates that the returned pointer may be used to read buffer object data.GL_WRITE_ONLYindicates that the returned pointer may be used to modify buffer object data.GL_READ_WRITEindicates that the returned pointer may be used to read and modify buffer object data. the full package bestie π
if an error is generated, a NULL pointer is returned. that's the vibe check failing bestie π
if no error occurs, the returned pointer will reflect an allocation aligned to the value of GL_MIN_MAP_BUFFER_ALIGNMENT basic machine units. so like, respect the alignment, it's not optional β¨
big warning time π¨ the returned pointer values may not be passed as parameter values to GL commands. for example, they may not be used to specify array pointers, or to specify or query pixel or texture image data. those actions produce undefined results, although implementations may not check for such behavior for performance reasons β so like, the driver might not catch you, but that does not mean you're fine π
and here's another one: no GL error is generated if the returned pointer is accessed in a way inconsistent with access (e.g. used to read from a mapping made with access GL_WRITE_ONLY, or write to a mapping made with access GL_READ_ONLY). BUT the result is undefined and system errors (possibly including program termination π) may occur. so like... don't. fr fr.
mappings to the data stores of buffer objects may have nonstandard performance characteristics, ngl. for example, such mappings may be marked as uncacheable regions of memory, and in such cases reading from them may be very slow. to ensure optimal performance, the client should use the mapping in a fashion consistent with the values of GL_BUFFER_USAGE for the buffer object and of access. using a mapping in a fashion inconsistent with these values is liable to be multiple orders of magnitude slower than using normal memory. like, glacial. tragic. you've been warned π§
β NOTES β
alignment of the returned pointer is guaranteed only if the version of the GL version is 4.2 or greater. also, the GL_ATOMIC_COUNTER_BUFFER target is accepted only if the GL version is 4.2 or greater. so check your version, bestie π
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.
π ERRORS π
GL_INVALID_ENUMis generated byglMapBufferiftargetis not one of the buffer binding targets listed above. wrong target, bestie π«GL_INVALID_OPERATIONis generated byglMapBufferif zero is bound totarget. nothing's bound. tragic.GL_INVALID_OPERATIONis generated byglMapNamedBufferifbufferis not the name of an existing buffer object.GL_INVALID_ENUMis generated ifaccessis notGL_READ_ONLY,GL_WRITE_ONLY, orGL_READ_WRITE.GL_OUT_OF_MEMORYis generated if the GL is unable to map the buffer object's data store. this may occur for a variety of system-specific reasons, such as the absence of sufficient remaining virtual memory πGL_INVALID_OPERATIONis generated if the buffer object is in a mapped state. you can't map a map, we don't do that here π
π ASSOCIATED GETS π
glGetBufferPointerv()with argumentGL_BUFFER_MAP_POINTERglGetBufferParameter()with argumentGL_BUFFER_MAPPED,GL_BUFFER_ACCESS, orGL_BUFFER_USAGEglGet()with pnameGL_MIN_MAP_BUFFER_ALIGNMENT. the value must be a power of two that is at least 64 π
π VERSION SUPPORT π
glMapBufferβ β in OpenGL version2.0,2.1,3.0,3.1,3.2,3.3,4.0,4.1,4.2,4.3,4.4,4.5. all of them. she ate and left no crumbs πglMapNamedBufferβ-in2.0,2.1,3.0,3.1,3.2,3.3,4.0,4.1,4.2,4.3,4.4β and β only in4.5. late bloomer, but she arrived π¦
π SEE ALSO π
glBindBuffer(), glBindBufferBase(), glBindBufferRange(), glBufferData(), glBufferSubData(), glDeleteBuffers(), glMapBufferRange(), glUnmapBuffer()
okay that's the page so far β more is coming, don't go anywhere bestie π«Ά
π COPYRIGHT π
Okay bestie, legal era β but make it cute. Here's who owns what:
- Copyright Β© 2005 Addison-Wesley.
- Copyright Β© 2010-2014 Khronos Group.
And the fine print: this material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. The link, verbatim, no edits:
http://opencontent.org/openpub/
No cap, you actually have to read that license if you're gonna redistribute this. It's giving "read the room" but make it legal π
π COPYRIGHT (the sequel π«Ά) π
And because twice is iconic, here's the same energy again β this block lists it like this:
- Copyright Β© 2005 Addison-Wesley Group
- Copyright Β© 2010-2014 Khronos Group
β¨ And that's the whole page, bestie β you ate. β¨
The footer info for the record: source is listed as [FIXME: source] (yes, literally, a fixme β not me, that's what it says π), dated 08/09/2021, and the page is GLMAPBUFFER(3G). Slay, go map some buffers, ily ππ¦
π¦ 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