Results 1 to 4 of 4

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

  1. #1

    Question 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!

  2. #2
    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.

  3. #3
    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!

  4. #4
    Quote Originally Posted by macrod View Post
    Does the 2nd sentence say "uniforms can be used as array subscripts" or "can indexing uniform vectors"?
    Thanks!
    https://www.khronos.org/files/opengl...g_language.pdf
    P110, see the table in Summary, it really means the later.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean