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?

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,676
    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.

Similar Threads

  1. Uniform Blocks and Uniform Buffers only?
    By Septimra in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 07-08-2015, 07:32 AM
  2. Uniform blocks and offsets
    By wizardbox in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-02-2015, 06:45 AM
  3. Using Uniform Blocks for Materials ...
    By tmason in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-16-2014, 03:30 AM
  4. Uniform blocks optimized out
    By Antoine in forum OpenGL: GLSL
    Replies: 5
    Last Post: 02-08-2011, 11:04 AM
  5. Uniform blocks
    By lexez in forum OpenGL: GLSL
    Replies: 0
    Last Post: 09-11-2010, 02:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean