GLUNMAPBUFFER(3G)

πŸ’– GLUNMAPBUFFER(3G) β€” bestie edition πŸŽ€

okay so this is the page for glUnmapBuffer and glUnmapNamedBuffer from section 3G of the manual, and honestly? it's giving "cleanup era." ✨


🌸 NAME 🌸

glUnmapBuffer, glUnmapNamedBuffer β€” release the mapping of a buffer object's data store into the client's address space

like, you mapped it, you did your thing, now you're letting it go. closure. πŸ¦‹


✨ C SPECIFICATION ✨

GLboolean glUnmapBuffer(GLenum target);

GLboolean glUnmapNamedBuffer(GLuint buffer);

bestie they literally both return a GLboolean, we love a consistent king πŸ‘‘


πŸŽ€ PARAMETERS πŸŽ€

  • target β€” specifies the target to which the buffer object is bound for glUnmapBuffer, which must be one of the buffer binding targets in the following table:
    • 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 glUnmapNamedBuffer. πŸ‘ˆ that's the whole job. name. that's it.

πŸ’… DESCRIPTION πŸ’…

glUnmapBuffer and glUnmapNamedBuffer unmap (release) any mapping of a specified buffer object into the client's address space (see glMapBufferRange() and glMapBuffer()). no cap, that's literally the function. you're un-mapping. the end of the situationship πŸ’”

okay but here's the serious part so listen up πŸ™ˆ β€” if a mapping is not unmapped before the corresponding buffer object's data store is used by the GL, an error will be generated by any GL command that attempts to dereference the buffer object's data store, unless the buffer was successfully mapped with GL_MAP_PERSISTENT_BIT (see glMapBufferRange()). when a data store is unmapped, the mapped pointer becomes invalid. ⚠️ like, that pointer? gone. deceased. do not touch it.

glUnmapBuffer returns GL_TRUE unless the data store contents have become corrupt during the time the data store was mapped. This can occur for system-specific reasons that affect the availability of graphics memory, such as screen mode changes. In such situations, GL_FALSE is returned and the data store contents are undefined. An application must detect this rare condition and reinitialize the data store. 😭 so rare but so real β€” your app HAS to check for it, i don't make the rules.

slayful convenience note: a buffer object's mapped data store is automatically unmapped when the buffer object is deleted or its data store is recreated with glBufferData()). so sometimes the universe handles it for you 🫢


🌈 NOTES 🌈

  • If an error is generated, glUnmapBuffer returns GL_FALSE. (yes, the error case lies to your face with a GLboolean. πŸ’€)
  • The GL_ATOMIC_COUNTER_BUFFER target is accepted 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 gating is so real, check yours before you come for these targets πŸ‘‘


πŸ’€ ERRORS πŸ’€

  • GL_INVALID_ENUM is generated by glUnmapBuffer if target is not one of the buffer binding targets listed above. πŸ™ˆ wrong target bestie.
  • GL_INVALID_OPERATION is generated by glUnmapBuffer if zero is bound to target. nothing bound? nothing to unmap.
  • GL_INVALID_OPERATION is generated by glUnmapNamedBuffer if buffer is not the name of an existing buffer object. bestie that buffer does not exist, i'm sorry 😭
  • GL_INVALID_OPERATION is generated if the buffer object is not in a mapped state. you can't unmap what was never mapped, that's not how any of this works πŸ’…

πŸ” ASSOCIATED GETS πŸ”

glGetBufferParameter() with argument GL_BUFFER_MAPPED. use it to vibe check whether your buffer is mapped fr fr βœ…


πŸ‘‘ VERSION SUPPORT πŸ‘‘

the columns run 2.0, 2.1, 3.0, 3.1, 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5 β€” and here's how the two functions ate:

  • glUnmapBuffer β€” βœ” in every version: 2.0 βœ”, 2.1 βœ”, 3.0 βœ”, 3.1 βœ”, 3.2 βœ”, 3.3 βœ”, 4.0 βœ”, 4.1 βœ”, 4.2 βœ”, 4.3 βœ”, 4.4 βœ”, 4.5 βœ”. iconic, timeless, never missed a single one 🌟
  • glUnmapNamedBuffer β€” only 4.5 gets the βœ”. 2.0 -, 2.1 -, 3.0 -, 3.1 -, 3.2 -, 3.3 -, 4.0 -, 4.1 -, 4.2 -, 4.3 -, 4.4 -, 4.5 βœ”. fashionably late but she arrived πŸŽ€

🌸 SEE ALSO 🌸

  • glBufferData()
  • glDeleteBuffers()
  • glMapBuffer()
  • glMapBufferRange()

the whole friend group honestly 🫢


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 Β© 2005 Addison-Wesley Group Copyright Β© 2010-2014 Khronos Group


yes the copyright section appears twice in the original and yes i kept it twice. every detail stays, that's the rule πŸ’–

alright bestie, that's the whole page β€” source was [FIXME: source] and the date on this one is 08/09/2021, so go forth, unmap your buffers, check your GLboolean, and remember: the pointer is invalid after. no cap. πŸ¦‹βœ¨πŸ’œ

πŸ“¦ where this page comes from