See OpenGL ES Shading Language 1.00 Specification - Appendix A - Indexing of Arrays, Vectors and Matrices:
The following are constant-index-expressions:
- Constant expressions
- Loop indices as defined in section 4
- Expressions composed of both of the above
Therefore, the index of an array can also be the control variable of a for loop:
for (int i = 0; i < 2; i++)
{
float tst = s[i].x;
// [...]
}
It should be mentioned that this restriction applies to OpenGL ES Shading Language 1.00 (WebGL 1.0), but not to OpenGL ES Shading Language 3.00 (WebGL 2.0).
See OpenGL ES Shading Language 3.00 Specification - 12.30 Dynamic Indexing:
For GLSL ES 1.00, support of dynamic indexing of arrays, vectors and matrices was not mandated because it was not directly supported by some implementations. Software solutions (via program transforms) exist for a subset of cases but lead to poor performance. Should support for dynamic indexing be mandated for GLSL ES 3.00?
RESOLUTION: Mandate support for dynamic indexing of arrays except for sampler arrays, fragment output arrays and uniform block arrays.
GLSL ES 100disallows computing array index, but allows doing logically the same thing in a clumsy way using if/else statements (e.g.if (dist == 0) { tst = s[0].x; } else { tst = s[1].x; }).