2
votes

"Global variables and Interface Blocks can be declared with the uniform​ qualifier. This means that the value does not change between multiple executions of a shader during the rendering of a primitive (ie: during a glDraw* call). These values are set by the user from the OpenGL API. They are constant, but not compile-time constant (so not const​)."

http://www.opengl.org/wiki/Type_Qualifier_(GLSL)#Storage_qualifier

I guess I'm asking why the uniform variables cannot just be constant at compile time as well.

1
Humorously, even if they were constant that would change nothing. Constant variables may consume the same pool of storage as uniform variables. In fact, if you ever enumerate the list of uniforms in a linked GLSL program on an NV driver, you will notice it renames constants something along the lines of _<func_name>_<var_name>_0 and assigns them uniform locations.Andon M. Coleman

1 Answers

2
votes

Because they are not constant!

They are constant for every rendering call, but you can set a new value for each one.

For example you could set a uniform to contain a color value, set it to pink and draw your 3d model and it will contain a constant value every time it calls the fragment shader for that drawing operation. But then you can draw something else using the same shader with that uniform set to "green"