Multiple Textures in GLSL

Hello I’ve been trying to access multiple textures within the fragment program, the problem is that when I use glUniform1iARB to bind a texture to any TU besides 0 it gives me error 1281 “Invalid Value”. I use glGetUniformLocationARB to find the sampler2D position so I know the sampler position should not be what is generating this error, especially since I can bind the same position to TU0 and it works fine.
I’m using basically the exact methods shown in the Orange Book. I think there is something wrong with my C++ code because my computer should be able to do 4 textures and 16 texture image units. I downloaded a bump mapping GLSL demo from Nvidia and I was able to compile it and it works fine with 3 textures, they are using the same method to set up the shaders as I am. Is there some secret trick or bug to this?

This is all the fragment program does, textureUnit and textureUnit2 always use the same texture because I cannot get it to bind to any besides TU0.

uniform sampler2D textureUnit;
uniform sampler2D textureUnit2;
varying vec2 texCoord;

void main()
{
vec4 tempFrag2 = texture2D(textureUnit2,texCoord);
vec4 tempFrag = texture2D(textureUnit,texCoord);

gl_FragColor =mix(tempFrag,tempFrag2,0.5);

}

This looks ok. The error comes from GL so something with your GLSL or general OpenGL handling might be wrong. Post that code.

You can call glGetUniformLocationARB after shader linking.

  1. compile vertex shader
  2. compile fragment shader
  3. attach shaders to program object
  4. link program

Now you can call glGetUniformLocationARB and glUniform1iARB.

yooyo

Did you call glUseProgramObjectARB() before glUniform1iARB?

Thx for tips,the code is rather long but the shader itself is compiling correctly, I check it for errors with glGetObjectParameterivARB after each shader is added to the program. Once it links properly I check validation, call glUseProgramObjectARB() and then attempt to bind the uniforms like this…

int loc = glGetUniformLocationARB(hProgamObject,“textureUnit”);
glUniform1iARB(loc,0);

int loc2 = glGetUniformLocationARB(hProgamObject,“textureUnit2”);
glUniform1iARB(loc2,1);

^ this is where GLenum err = glGetError(); returns 1281 “Invalid Value”. loc2 is equal to 39 which seems correct, the program contains an array of 38 uniform matrices and these 2 uniform samplers.

Can you tell us your hw and driver. If you have 38 matrices it uses 38*4 (=152) vec4 in program parametars table. Maybe your hw is limited…

yooyo

Originally posted by yooyo:
[b]Can you tell us your hw and driver. If you have 38 matrices it uses 38*4 (=152) vec4 in program parametars table. Maybe your hw is limited…

yooyo[/b]
It sounds like it might be. 152 vec4s = 608 floats. The minimum legal value for GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB (according to page 194 of the Orange book) is 512 floats. Nvidia’s latest linux drivers have 256!

dave j

Originally posted by davej:
[b] [quote]Originally posted by yooyo:
[b]Can you tell us your hw and driver. If you have 38 matrices it uses 38*4 (=152) vec4 in program parametars table. Maybe your hw is limited…

yooyo[/b]
It sounds like it might be. 152 vec4s = 608 floats. The minimum legal value for GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB (according to page 194 of the Orange book) is 512 floats. Nvidia’s latest linux drivers have 256!

dave j[/b][/QUOTE]True, but there are a few other cards that don’t have that many uniforms but return a very high number which would mean software renderer.

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