Direct State AccessGL 4.5

glNamedBufferData

glBufferData without binding: (re)allocates a buffer's storage by ID.

Signature

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

How it works

The same job as glBufferData: throw away the buffer's old storage, allocate size bytes and optionally copy data in. The difference is only how the buffer is named: by ID, so nothing has to be bound to GL_ARRAY_BUFFER first.

Calling it again with the same size and nullptr is the classic way to "orphan" a buffer each frame: the GPU keeps reading the old memory while you fill the new one.

Parameters

bufferGLuint

The buffer to allocate.

sizeGLsizeiptr

Size in bytes.

dataconst void *

Initial data or nullptr.

usageGLenum

GL_STATIC_DRAW, GL_DYNAMIC_DRAW, GL_STREAM_DRAW… (same as glBufferData).

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.

  • If the size never changes, prefer glNamedBufferStorage.

Example

example.cpp
1glNamedBufferData(vbo, sizeof(vertices), vertices, GL_STATIC_DRAW);
Official Khronos documentation