I've defined a struct
in my fragment shader, as below:
struct light_source{
vec4 Ld, location;
int type;
float radii, specular_exponent;
};
And I'm using this uniform
to access the struct members:uniform light_source light_sources[5];
Now, from my C++ code, I'm getting the uniform locations like this:
Ld = glGetUniformLocation(Globals::ProgramId, "light_sources[0].Ld");
Ls = glGetUniformLocation(Globals::ProgramId, "light_sources[0].Ls");
location = glGetUniformLocation(Globals::ProgramId, "light_sources[0].location");
type = glGetUniformLocation(Globals::ProgramId, "light_sources[0].type");
radii = glGetUniformLocation(Globals::ProgramId, "light_sources[0].radii");
specular_exponent = glGetUniformLocation(Globals::ProgramId, "light_sources[0].specular_exponent");
When I print the above values, I find that the values are -1,1,2,-1,3,4 . So, I couldn't get locations for Ld
and type
. Similarly, if I add a new variable to the shader now , some times I get the location, and sometimes I get -1 .
I don't get the problem here. All the variable definitions are correct and there are no typos. Can this behavior be remedied?