View Full Version : uniform int array

01-28-2015, 01:05 PM
I have a shader with this:

uniform int Indices[4];

I'm able to get the location using (read not getting a -1):

IndicesLocation = glGetUniformLocation(program, "Indices");

and when I try to put data there it doesn't appear to work.

GLint Indices[] = { 1, 0, 3, 2 };
glUniform1iv(IndicesLocation, 4, Indices);

When I view my shader program in codeXL it appears only the first element actually gets set. Any idea what I'm doing wrong?

01-28-2015, 11:11 PM
GLint Indices[] = { 1, 0, 3, 2 };
glUniform1iv(IndicesLocation, 4, Indices);

It's not working because you told opengl to create 4 vectors of 1 element in size. Have a look at the documentation.


The maximum vector size is 4 and in this case you would use

GLint Indices[] = { 1, 0, 3, 2 };
glUniform4iv(IndicesLocation, 1, Indices);

Here you create 1 vector of 4 elements in size, probably more what you wanted

01-29-2015, 02:04 AM
What you posted is ok, the problem must be somewhere else. Is the shader active (glUseProgram(program)) when you call glUniform1iv?

01-29-2015, 07:18 AM
Yes the shader is active, all the other uniforms were working correctly. Is it possible that if I had several unused uniforms declared and was trying to glUniform* them, that it could have bad side effects?

uniform int x;
uniform int indices[4];
uniform float y;

void main()
vec4 outColor = vec4(1,1,1,1);
if (indices[0] == 0)
outColor.r = 0;
if (indices[1] == 0)
outColor.g = 0;
if (indices[2] == 0)
outColor.b = 0;
if (indices[3] == 0)
outColor.a = 0;
displayColor = outColor;

because I never used "x" or "y" they get optimized out, but how could that effect "indices"? Oh well, I got around the problem by just not using an array for now. I'll revisit this later when I've developed a bit more.

*note this was just typing off the top of my head not actually the code I had implemented.

Alfonse Reinheart
01-29-2015, 07:30 AM
Doesn't CodeXL have some OpenGL logging functionality, like glIntercept? Either way, could you generate a file that the relevant section of OpenGL calls (after all your context creation stuff)?