GLSL ES 2: Is it safe to use uniforms as vectors' array subscripts?

In OpengGL ES 2.0 Programming Guide:
“One thing you need to be
careful of, though, is that if you access a vector with a non-constant integral
expression (e.g., using an integer variable index
), then this might not be
supported in OpenGL ES 2.0.”
“OpenGL ES 2.0 spec does not mandate support for this behavior except for
on a specific variable type (namely, uniform variables
).”

Does the 2nd sentence say “uniforms can be used as array subscripts” or “can indexing uniform vectors”?

Based on my understanding, uniforms are actually constant for shaders, so it is safe to use it?

Thanks!

Does the 2nd sentence say “uniforms can be used as array subscripts” or “can indexing uniform vectors”?

Well, it’s saying the latter, but the former is implied. Uniforms are not integral constant expressions. So if uniform variables declared as an array can be indexed by non-constant expressions, it stands to reason that the non-constant expression could be a uniform just as well as anything else.

Sorry if it was not clear.

The intention is:

  • Sample a texture and get a color.
  • Instead of getting color components via .x/y/z/r/g/b, it would be convenient to use this form: theColor[theIntUniform], which is called array subscripting notation.

Thanks!

[QUOTE=macrod;42317]
Does the 2nd sentence say “uniforms can be used as array subscripts” or “can indexing uniform vectors”?
Thanks![/QUOTE]

P110, see the table in Summary, it really means the later.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.