Falerii
Falerii

Reputation: 31

OpenGL why are uniform variables needed (instead of just constants)

"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.

Upvotes: 2

Views: 396

Answers (1)

jcoder
jcoder

Reputation: 30035

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"

Upvotes: 2

Related Questions