3

I was reading the OpenGL ES 2 Shading Language specification (PDF), when I went through this code:

      invariant varying mediump vec3 Color;

I think understand the invariance concept, but the meaning of an "invariant varying" seems quite puzzling to me.

Can someone explain to me the meaning and why this is useful ?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Antzi
  • 12,831
  • 7
  • 48
  • 74

2 Answers2

2

invariant is a keyword to inform the shader optimiser that the optimiser should keep in mind that the output of the variable for the same input in 2 different times should be the same. Some optimisation usually gives different results in different times, based on many factors. This keyword will make sure optimiser avoids using those techniques in this particular variable.

codetiger
  • 2,650
  • 20
  • 37
0

invariant does not mean const. invariant is a property of how the expressions leading to the generation of that value will be compiled.

varying is a property that specifies what happens to that value after the VS finishes executing. varying variables are passed to the rasterizer for interpolation.

One controls how data is fed into the variable. The other controls where the data in that variable eventually goes. They're orthogonal, not antinomic.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982