Uniformlessnessly ?!?!?

I can use very well 3 slots for uniforms, but when I use a fourth one, the linker doesn’t complain (it complains only when I try to use more uniforms slots), but the values do not seem to be transfered into the shader.

Any clue ?

For more information:

slot 1: 3 floats (might become 4 soon or later)
slot 2: 3 floats (idem)
slot 3: 4 samplers
slot 4: 4 int ← making problems !!

All but the last uniforms are well transfered into the shader, but the last slot is all set to zero.
Could it be because it remains two positions left, one in each the first two slots ?

My graphic card is a Geforce FX.

That doesn’t make much sense. GeForce FX has 256 vec4 slots for uniforms.

it complains only when I try to use more uniforms slots
And what does it say?

What else do you use from the built-in OpenGL state, like all texture matrices, all lights would kill a lot of uniforms.

Thank you for the information. I simplified the things and I effectively can access more uniforms (try with about 6): it complained before about that it cannot access the uniform, but it was along with other errors (I was using a for loop).

I don’t use all lights, neither all texture matrices from the built-in GL states.

But, unfortunately I cannot make the fourth one to work. Here is the little fragment shader portion code about it:

   uniform int tm[4];
   uniform sampler2D sampler[4];
   uniform int tex_nb;


   if (tm[0] == 1){
      out_color = texture2D (sampler[0], gl_TexCoord[0].st);
      out_color = vec4 (0,1,1,1);

The texture only appears when I test tm[0] == 0.

I ensured I pass 1 to all the array values of tm inside my C++ code. I also ensured this is the good gl function that is called for this uniform (4 int as an array): it is the same as for the sampler2D (seems normal). I also tried to pass it as 4 int not as an array but without more success.
All other uniforms work perfectly.

Also I’d like to add this is the only uniform I set as an array of int.

Okay, I think I got it: it’s a problem when sending the uniforms, I confused Uniform4v (1,…) and Uniform1v (4,…): I thought that an array of 4 int could be taken like a single ivec4, but it seems not. Sorry for that big mistake.

But is it normal that a uniform location could be negative ? My last uniform is a single int, and the location I get is -1. But it’s working fine.

If the uniform isn’t used in the shader, the compiler will “throw it away” so when you get the uniform’s location, it returns you -1, which is the same as if the uniform doesn’t exist at all in your shader. Trying to get uniform location with a name beginning with ‘gl_’ returns you -1 as well.

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