BuffersGL 3.0
glBindBufferBase
Connects a whole buffer to a numbered binding point that shaders read from.
Part of the family glBind*
Signature
void glBindBufferBase(GLenum target, GLuint index, GLuint buffer);
How it works
Uniform buffers and shader storage buffers are not attached to a program directly. Instead there is a numbered list of binding points per target; the shader says "my block uses binding 2" and your C++ code puts a buffer at binding 2.
glBindBufferBase fills one of those numbered points with the entire buffer. It also binds the buffer to the generic target, like glBindBuffer would.
Parameters
targetGLenum
Which list of binding points.
Common values
- GL_UNIFORM_BUFFER
- Uniform blocks (read-only, small).
- GL_SHADER_STORAGE_BUFFER
- SSBOs (read/write, large).
- GL_ATOMIC_COUNTER_BUFFER
- Atomic counters.
- GL_TRANSFORM_FEEDBACK_BUFFER
- Transform feedback output.
indexGLuint
Binding point number — must match layout(binding = N) in the shader.
bufferGLuint
Buffer to attach.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_VALUE
- index is greater than or equal to the maximum number of binding points for target.
Example
example.cpp
1// GLSL: layout(std140, binding = 0) uniform Camera { mat4 projection; mat4 view; };
2glBindBufferBase(GL_UNIFORM_BUFFER, 0, uboCamera);