Direct State AccessGL 4.5

glNamedBufferSubData

glBufferSubData without binding: overwrites part of a buffer by ID.

Signature

void glNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data);

How it works

Copies size bytes from your memory into the buffer, starting offset bytes in. The size of the buffer does not change, so the range must fit inside it. It is the simplest way to update a uniform buffer or a few vertices each frame.

With storage made by glNamedBufferStorage, the buffer must have been created with GL_DYNAMIC_STORAGE_BIT, or this call is refused.

Parameters

bufferGLuint

Buffer to update.

offsetGLintptr

Start in bytes.

sizeGLsizeiptr

Bytes to write.

dataconst void *

Source data.

Tips & pitfalls

  • Direct State Access (GL 4.5): the object is passed as a parameter, so nothing needs to be bound and no global state is disturbed.

  • Immutable buffers need GL_DYNAMIC_STORAGE_BIT for this to work.

Example

example.cpp
1glNamedBufferSubData(ubo, 0, sizeof(CameraData), &camera);
Official Khronos documentation