I am having trouble setting/getting arrays of uniforms. Say I have a shader with only one uniform:
uniform float af = float(1.0, 1.0);
glGetObjectParameteriv returns 1 for GL_OBJECT_ACTIVE_UNIFORMS. For index 0, glGetActiveUniform return a size of 2 as expected. Now how do I query the values in the array? The SDK says to call glGetUniform for each element of the array. How do I get the index for each element? The orange book explicitly says not to assume the array elements are in order (e.g. index 0 is af, index 1 is af). This seems reasonable since if I add another uniform to the shader, glGetActiveUniform reports index 0 is af and index 1 is the new uniform:
uniform float af = float(1.0, 1.0); uniform float f = 5.0;
Things get really interested when I call glGetUniformLocation with various strings:
glGetUniformLocation(handle, "af") -> 0 glGetUniformLocation(handle, "af") -> 0 glGetUniformLocation(handle, "af") -> 1 glGetUniformLocation(handle, "f") -> 2
Now I’m confused. glGetActiveUniform return “f” for index 1 but glGetUniformLocation says its index 2. It looks like only the index returned from glGetActiveUniform can be trusted, not the one input to glGetActiveUniform.
Perhaps I need to call glGetUniformLocation for each string after I call glGetActiveUniform for each index?
Thanks for any clarification.