I'm learning about OpenGL/ES. I'm not clear what a binding point is. I looked at the OpenGL documents and also searched the Internet, but couldn't find something which explains binding point well.
Here is an example of what I mean by binding point.
void glUniformBlockBinding( GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
I would appreciate it if you can explain what a binding point is, how it is used, etc.
Uniform block binding points act in exactly the same way as texture units.
In your shader, you refer to a texture sampler (e.g. a sampler2D
) and you associate this sampler to a texture unit by calling glUniform1i(samplerUniformIndex, textureUnitNumber);
. Before drawing with the shader, you then bind a texture to this textureUnitNumber
using a combination of glActiveTexture
(to set the active texture unit), and glBindTexture
to bind a texture to the active texture unit. So there are three concepts here:
Binding points for uniform blocks are the same. You have:
We can compare how a texture and uniform buffer objects are used.
Textures:
GLuint samplerUniformIndex;
glUseProgram(program);
samplerUniformIndex = glGetUniformLocation(program, "mysampler");
glUniform1i(samplerUniformIndex, textureUnitNumber);
Uniform buffers:
GLuint uniformBlockIndex = glGetUniformBlockIndex(program, "myblock");
glUniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding);
Textures:
glActiveTexture(textureUnitNumber);
glBindTexture(textureTarget, texture);
Uniform buffers:
glBindBufferBase(GL_UNIFORM_BUFFER, uniformBlockBinding, uniformBuffer);
Or you can use glBindBufferRange
to bind a specific range of the uniform buffer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With