What's glUniformBlockBinding used for?

后端 未结 1 1682
借酒劲吻你
借酒劲吻你 2021-01-18 05:58

Assuming I have a shader program with a UniformBlock at index 0.

Binding the UniformBuffer the following is apparently enough to bind a UniformBuffer to

相关标签:
1条回答
  • 2021-01-18 06:28

    Per-program active uniform block indices differ from global binding locations.

    The general idea here is that assuming you use the proper layout, you can bind a uniform buffer to one location in GL and use it in multiple GLSL programs. But the mapping between each program's individual buffer block indices and GL's global binding points needs to be established by this command.

    To put this in perspective, consider sampler uniforms.

    Samplers have a uniform location the same as any other uniform, but that location actually says nothing about the texture image unit the sampler uses. You still bind your textures to GL_TEXTURE7 for instance instead of the location of the sampler uniform.

    The only conceptual difference between samplers and uniform buffers in this respect is that you do not assign the binding location using glUniform1i (...) to set the index. There is a special command that does this for uniform buffers.


    Beginning with GLSL 4.20 (and applied retroactively by GL_ARB_shading_language_420pack), you can also establish a uniform block's binding location explicitly from within the shader.

    GLSL 4.20 (or the appropriate extension) allows you to write the following:

    layout (std140, binding = 0) uniform MyUniformBlock
    {
      vec4 foo;
      vec4 bar;
    };
    

    Done this way, you never have to determine the uniform block index for MyUniformBlock; this block will be bound to 0 at link-time.

    0 讨论(0)
提交回复
热议问题