opengl - What's glUniformBlockBinding used for? -


Assume that I have a shader program with the uniform block at index 0 .

To compel the uniformbuffer, there is enough enough to bind the uniformbuffer in the following block:

  glUseprogram (program); Glubbind Buffer (GL_UNIFORM_BUFFER, buffer); Glibindbuffarbase (GL_UIIFRMBUFFER, 0, buffer);   

I only have to use glUniformBlockBinding when I bind buffer to a different index in the shader program.

  // ... glBindBufferBase (GL_UNIFORM_BUFFER, 1, buffer) glUniformBlockBinding (program, 0, 1); // Uniform Block 1 index 0   

Did I understand it correctly? If I use buffer in different programs where appropriate blocks have different indices, then do I have to use glUniformBlockBinding ?

Active program block indices per program are different from global binding locations.

The general idea here is that you consider using the proper layout, you can bind the uniform buffer, one place in GL and use it in many GLSL programs. But mapping between individual buffer block index and global binding points of GL of each program needs to be established by this command.

To keep it in perspective, consider sample uniforms.

Uniform space is similar to any other uniform, but this location does not actually say anything about the Texture Image Unit which uses the sample. For example, you can still tie your texture in GL_TEXTURE7 instead of the location of the sample uniform.

The only conceptual difference between samples and uniform buffers in this regard is that you do not assign that the binding space using glUniform1i (...) to set the index .


With GLSL 4.20 (and applied retroactively), you can clearly establish the binding space of a specific block from within the shaders.

GLSL 4.20 (or the appropriate extension) allows you to type the following:
  Layout (std140, binding = 0) Uniform MyUniform Block { vec4 foo; vec4 times; };   

In this way, you do not need to set an identical block index for MyUiniformBlock any time; This block will be bound to 0 at link-time.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -