GLBUFFERDATA(3G)

GLBUFFERDATA β€” the <3G> manual page, but make it cute ✨

okay bestie, this is the <3G> manual page, and it’s lowkey all about giving a buffer object a brand-new little data store. main character energy only πŸ’…

✨ NAME ✨

glBufferData, glNamedBufferData β€” creates and initializes a buffer object's data store. periodt.

πŸ’» C SPECIFICATION πŸ’»

void glBufferData(GLenum target, GLsizeiptr size, const GLvoid * data,
                  GLenum usage);

void glNamedBufferData(GLuint buffer, GLsizeiptr size, const void *data,
                       GLenum usage);

πŸŽ€ PARAMETERS πŸŽ€

  • target β€” Specifies the target to which the buffer object is bound for glBufferData, which must be one of the buffer binding targets in the following table. The buffer binding targets and their purposes are:
    • 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 glNamedBufferData function.
  • size β€” Specifies the size in bytes of the buffer object's new data store.
  • 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.
  • usage β€” Specifies the expected usage pattern of the data store. The symbolic constant must be GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY.

πŸ¦‹ DESCRIPTION πŸ¦‹

glBufferData and glNamedBufferData create a new data store for a buffer object. In case of glBufferData, the buffer object currently bound to target is used. For glNamedBufferData, a buffer object associated with ID specified by the caller in buffer will be used instead.

While creating the new storage, any pre-existing data store is deleted. The new data store is created with the specified size in bytes and usage. If data is not NULL, the data store is initialized with data from this pointer. In its initial state, the new data store is not mapped, it has a NULL mapped pointer, and its mapped access is GL_READ_WRITE.

usage is a hint to the GL implementation as to how a buffer object's data store will be accessed. This enables the GL implementation to make more intelligent decisions that may significantly impact buffer object performance. It does not, however, constrain the actual usage of the data store. usage can be broken down into two parts: first, the frequency of access (modification and usage), and second, the nature of that access. The frequency of access may be one of these:

  • STREAM β€” The data store contents will be modified once and used at most a few times.
  • STATIC β€” The data store contents will be modified once and used many times.
  • DYNAMIC β€” The data store contents will be modified repeatedly and used many times.

The nature of access may be one of these:

  • DRAW β€” The data store contents are modified by the application, and used as the source for GL drawing and image specification commands.
  • READ β€” The data store contents are modified by reading data from the GL, and used to return that data when queried by the application.
  • COPY β€” The data store contents are modified by reading data from the GL, and used as the source for GL drawing and image specification commands.

πŸ“ NOTES πŸ“

  • If data is NULL, a data store of the specified size is still created, but its contents remain uninitialized and thus undefined. no cap, that means don’t count on what’s inside.
  • Clients must align data elements consistently with the requirements of the client platform, with an additional base-level requirement that an offset within a buffer to a datum comprising N bytes be a multiple of N.
  • 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.

πŸ’€ ERRORS πŸ’€

  • GL_INVALID_ENUM is generated by glBufferData if target is not one of the accepted buffer targets.
  • GL_INVALID_ENUM is generated if usage is not GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY.
  • GL_INVALID_VALUE is generated if size is negative.
  • GL_INVALID_OPERATION is generated by glBufferData if the reserved buffer object name 0 is bound to target.
  • GL_INVALID_OPERATION is generated by glNamedBufferData if buffer is not the name of an existing buffer object.
  • GL_INVALID_OPERATION is generated if the GL_BUFFER_IMMUTABLE_STORAGE flag of the buffer object is GL_TRUE.
  • GL_OUT_OF_MEMORY is generated if the GL is unable to create a data store with the specified size.

πŸ”Ž ASSOCIATED GETS πŸ”Ž

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

🌈 VERSION SUPPORT 🌈

OpenGL Version columns: 2.0, 2.1, 3.0, 3.1, 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5.

  • Function / Feature Name: glBufferData β€” 2.0 βœ”, 2.1 βœ”, 3.0 βœ”, 3.1 βœ”, 3.2 βœ”, 3.3 βœ”, 4.0 βœ”, 4.1 βœ”, 4.2 βœ”, 4.3 βœ”, 4.4 βœ”, 4.5 βœ”
  • Function / Feature Name: glNamedBufferData β€” 2.0 -, 2.1 -, 3.0 -, 3.1 -, 3.2 -, 3.3 -, 4.0 -, 4.1 -, 4.2 -, 4.3 -, 4.4 -, 4.5 βœ”

πŸ’« SEE ALSO πŸ’«

okay so like, go read these next, they're literally the rest of the buffer saga and you need them:

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

that's the whole friend group fr fr β€” bind it, sub-data it, map it, unmap it. slay πŸ’…


first copyright block, copy-pasted with love (and legally required precision, ngl):

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/.

and there's a second copyright block too, because of course there is β€” the way this page has two of them is giving "extra credit energy" ✨

Copyright Β© 2005 Sams Publishing Copyright Β© 2010-2014 Khronos Group

🌸 and that's the whole page bestie, you're done, go touch some grass (after you call glUnmapBuffer(), obviously) πŸ¦‹

little sign-off moment: this was GLBUFFERDATA(3G), dated 08/09/2021, and the source field literally says [FIXME: source] β€” not me clocking that the manpage itself has an unresolved FIXME 😭 iconic behavior, truly. mwah πŸ’–

πŸ“¦ where this page comes from