Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a binding point in OpenGL/OpenGL ES?

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.

like image 583
shervin0 Avatar asked Sep 06 '25 06:09

shervin0


1 Answers

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:

  1. A binding point (the texture unit)
  2. The resource to be used (the texture)
  3. The thing using the resource (the sampler uniform in your shader)

Binding points for uniform blocks are the same. You have:

  1. A uniform block binding point
  2. A resource to be used. In this case this is the buffer object which stores the uniform block data.
  3. The thing using the resource, which is the uniform block in your shader.

We can compare how a texture and uniform buffer objects are used.

Associating the binding point with the thing using the resource:

Textures:

GLuint samplerUniformIndex;
glUseProgram(program);
samplerUniformIndex = glGetUniformLocation(program, "mysampler");
glUniform1i(samplerUniformIndex, textureUnitNumber);

Uniform buffers:

GLuint uniformBlockIndex = glGetUniformBlockIndex(program, "myblock");
glUniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding);

Associating the resource with its binding point:

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.

like image 99
Alex Lo Avatar answered Sep 07 '25 20:09

Alex Lo