Function familiesfamily

glBind*

Make an object the current one for a target or slot, so the following calls act on it or draws use it.

Signature

void glBind{Buffer|Texture|Framebuffer|Renderbuffer}(GLenum target, GLuint name);
void glBindVertexArray(GLuint array);
void glBind{BufferBase|BufferRange|TextureUnit|ImageTexture|VertexBuffer}(GLuint index, …);

How it works

Classic OpenGL is a state machine: most functions do not take the object they act on, they act on whatever is bound. glBufferData changes the buffer bound to GL_ARRAY_BUFFER; glTexParameteri changes the texture bound to GL_TEXTURE_2D on the active unit. So binding has two jobs: choosing what to edit, and choosing what a draw uses.

The second kind of name ends in an index: glBindBufferBase(GL_UNIFORM_BUFFER, 2, ubo) and glBindTextureUnit(3, tex) put an object on a numbered slot that shaders read. Direct State Access removes the first job, editing, and leaves binding only for the second.

Reading the name

(target, name)
Bind to a target such as GL_ARRAY_BUFFER: the object to edit or use.
Base / Range / Unit
Bind to a numbered slot that shaders read (binding = N in GLSL).
0
Binding name 0 unbinds: nothing is current any more.

Functions in this family

Example

example.cpp
1glBindBuffer(GL_ARRAY_BUFFER, vbo);          // choose what to edit
2glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
3
4glBindBufferBase(GL_UNIFORM_BUFFER, 0, ubo); // slot 0 for the shaders
5glBindVertexArray(vao);                      // what the draw uses
6glDrawArrays(GL_TRIANGLES, 0, 3);