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
glBindBufferMakes a buffer the current one for a given target, so later buffer calls act on it.glBindVertexArrayMakes a VAO current: it records vertex setup calls and is used by draw calls.glBindTextureBinds a texture to a target of the ACTIVE texture unit.glBindFramebufferSelects the framebuffer that draw calls render into (and/or read from).glBindRenderbufferBinds a renderbuffer so glRenderbufferStorage can allocate it.glBindBufferBaseConnects a whole buffer to a numbered binding point that shaders read from.glBindBufferRangeConnects only a slice of a buffer to a numbered binding point.glBindTextureUnitPuts a texture on texture unit number unit, in one call (no glActiveTexture).glBindImageTextureBinds a texture level as an image that shaders can read and write pixel by pixel.glBindVertexBufferPuts a buffer on a binding point of the bound VAO; the attribute formats are described separately.
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);