Referencing uniform arrays of structs

Simple vertex program…

struct foo {

int bar;


uniform foo foo_single;
uniform foo foo_array[ 10 ];

void main( )
int tmp;

// Do random somthing so the uniform variables exist when
// when glGetUniformLocationARB is called.
tmp =;
tmp = foo_array[ 0 ].bar;

gl_Position = ftransform( );


Then calling:
uloc = glGetUniformLocationARB( prog, “” );
will return a valid location.

uloc = glGetUniformLocationARB( prog, “foo_array[ 0 ].bar” );
will return an invalid location(-1) To my reading of the Orange Book pg. 189 this should be valid.

Don’t think of -1 as “invalid location” but as “not active”.
tmp is never used in a meaningful manner, the compiler should have optimized both foo structs away. If it didn’t, it sucks. :wink:

Your error is something else:
Don’t include your source code formatting into the query: Use “[0]” instead of “[ 0 ]”. It’s not source code, it’s a string constant and it has a specific required form!

That was the problem. Thank you. I never would have thought of that.

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