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: Are uniforms of the same name the same uniform between different shader programs?

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    28

    Are uniforms of the same name the same uniform between different shader programs?

    In the wiki on uniforms, it is said:

    OpenGL does not guarantee that the same uniforms in the two programs will have the same location.
    This would imply that *sometimes* they may in fact be the same?

    I ask because I have two shaders but they have same-name uniforms. I had previously assumed that when I switch between shaders, the uniform data will be the same as the uniform data during that shader's last use.

    But this appears to not be correct. Instead, I have to reset a uniform when I switch to the shader, even if I had used the same shader seconds before without difficulty.

    Is it normal to reset all the uniforms when you change to a new shader?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    This would imply that *sometimes* they may in fact be the same?
    Even if they are, and yes, they may actually be the same, you cannot and should not rely on something that the GL does not guarantee! In case you assign explicit uniform locations (core in 4.3) this of course looks a bit different, since it's not the GL anymore which assigns the locations, but the programmer.

    The wiki also clearly states, that uniforms usually do not change between program executions - this, however, refers to executions of the same program, not two different programs. If you set the uniform values for program 1, it will not affect the uniform values of program 2, even if they are equally named and are assigned the same location by the GL. The uniforms for both programs belong to distinct state vectors!

    The GL spec states the following to be part of the required state for program objects:

    Quote Originally Posted by The GL Spec
    - For each active uniform, three integers, holding its location, size, and type, and an array of type char holding its name.
    - An array holding the values of each active uniform.
    Also, switching a shader program will simply reinstate the last set value for each active uniform. You should not have to set the value anew. So no, it's not normal to change the uniform values when switching programs, at least not for the sole purpose of resetting the same uniform values as before.
    Last edited by thokra; 04-18-2013 at 02:56 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
  •