View Full Version : glUniform [ i ] fvARB problem

Zulfiqar Malik
02-09-2005, 04:12 AM
I was using glUniform3fvARB(location, count, *value); for passing vectors to a vertex shader and i noticed (after a day of banging!) that the vector i was passing was not coming out right in the vertex/fragment shader. I read the documentation (both official and also from the Orange Book) and found that the "count" parameter should be the number of items passed i.e. 1 in case you are passing a 3d vector (i was passing a 3d position vector). But nothing seems to be working right, i tried passing 3 and 1 in case of a 3d vector but the results in both cases were inconsistent (from the ones i was getting while using an equivalent CG shader). Is this a known nVidia issue (i am using the latest drivers). Can someone give me more information on this please.

P.S: I then worked around by passing the parameter as glUniform3fARB(...) and that worked out fine without any change in the vs/ps code, but i want to directly pass an array.

02-09-2005, 04:51 AM
Are you sure both the function pointer queried with wglGetProcAddress and the pointer to your data are correct?
Post the code which fails including the data you give to glUniform3fvARB.

02-09-2005, 09:41 AM
I seem to have a similar problem (6629 on SuSE 9.2). I fail to set an array with a length greater than 3. Here's the vertex shader:

void main()
gl_Position = ftransform();
}And here the fragment shader:

uniform float weights[15];

void main()
}And this code is used to set the uniforms (after activating the shaders):

GLfloat weights[15];
GLuint paramWeights=glGetUniformLocationARB(shaderSystem->getHandle(), "weights");
glUniform1fvARB(paramWeights,4,weights);(paramWeig hts is 0 after the call).
The red component in the fragment shader appears to be 0. If I replace the argument 4 with 3 the red component appears to get the right value 1.
If I try to access the array elements via:

paramWeights=glGetUniformLocationARB(shaderSystem->getHandle(), "weights[0]");
... and so on for 1..3 ...the value for weight[0] in the fragment shader changes from 1 to 0 as soon as I set the third array element. Again glGetUniformLocationARB returns i for the index i (i.e. a valid value).

Zulfiqar Malik
02-09-2005, 06:53 PM
Yeah, the pointer to the function is correct. Here is the vertex program

varying vec3 lightWorldDir;
uniform vec3 lightPos;
void main()
gl_Position = ftransform();
lightWorldDir = lightPos - gl_Vertex.xyz;

and the fragment program

varying vec3 lightWorldDir;
uniform vec3 spotDir;
void main()
vec3 lwdNorm = normalize(-lightWorldDir);
float dp = dot(spotDir, lwdNorm);
gl_FragColor = vec4(dp, dp, dp, dp);

and i pass the lightPos and spotDir using the following

glUniform3fvARB(location, 1, lightPos.v);
glUniform3fvARB(location, 1, spotDir.v);

I have tried the following too

glUniform3fvARB(location, 3, lightPos.v);
glUniform3fvARB(location, 3, spotDir.v);

but none seems to work. passing the parameters as:

glUniform3fARB(location, lightPos.x, lightPos.y, lightPos.z);
glUniform3fARB(location, spotDir.x, spotDir.y, spotDir.z);

works fine.