PDA

View Full Version : Multiple Textures in GLSL



Fitz
02-15-2005, 03:15 PM
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);
}

Relic
02-15-2005, 11:04 PM
This looks ok. The error comes from GL so something with your GLSL or general OpenGL handling might be wrong. Post that code.

yooyo
02-16-2005, 05:39 AM
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

jra101
02-16-2005, 08:45 AM
Did you call glUseProgramObjectARB() before glUniform1iARB?

Fitz
02-16-2005, 09:21 AM
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.

yooyo
02-18-2005, 09:23 AM
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

davej
02-19-2005, 04:22 AM
Originally posted by yooyo:
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...

yooyoIt 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

V-man
02-19-2005, 09:07 AM
Originally posted by davej:

Originally posted by yooyo:
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...

yooyoIt 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 jTrue, 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.