Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Uniform blocks

  1. #1
    Newbie Newbie
    Join Date
    Oct 2012
    Posts
    1

    Uniform blocks

    (win7 x64)

    I'm trying to use uniform blocks to share data between shader programs, but am confused about some aspects of them.

    I have 2 shader programs, with for example the vertex shaders as:

    Vertex shader for program 1
    Code :
    layout(std140) uniform Block1
    {
    	vec4 var1;
    	vec4 var2;
    }
     
    etc.

    Vertex shader for program 2
    Code :
    layout(std140) uniform Block1
    {
    	// different variable types and/or names
    	float var1;
    	vec4 var3;
    }
     
    etc.

    I actually expected this to not compile, because the uniform block definitions do not match up.
    Why does it compile?
    And what's the best way to distinguish between same-named-but-different uniform blocks?
    Last edited by teravilp; 10-27-2012 at 11:53 AM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    I actually expected this to not compile, because the uniform block definitions do not match up.
    Why does it compile?
    Because program 1 doesn't know anything about program 2. The prohibition against blocks with the same name but different block definitions is within a program, not global. There's no global registry of blocks or something. Indeed, nothing about program 1 can interfere with the compilation/linking of program 2.

    And what's the best way to distinguish between same-named-but-different uniform blocks?
    That's up to you. OpenGL doesn't care if blocks in two different programs have anything in common. OpenGL only cares if two blocks in the same program have the same name but different definitions. It's perfectly valid to have two separate programs use blocks with the same name that are different. What matters is what buffer objects you bind for them and what those buffers contain.

    And that's on you to deal with.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •