Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: glUniform [ i ] fvARB problem

  1. #1
    Junior Member Regular Contributor Zulfiqar Malik's Avatar
    Join Date
    Jun 2004
    Location
    London, UK
    Posts
    247

    glUniform [ i ] fvARB problem

    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.
    Zulfiqar Inayat Malik.
    Senior Developer, The Foundry.

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: glUniform [ i ] fvARB problem

    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.

  3. #3
    Junior Member Regular Contributor
    Join Date
    May 2001
    Posts
    137

    Re: glUniform [ i ] fvARB problem

    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:
    Code :
    void main()
    {
    	gl_Position = ftransform(); 
    }
    And here the fragment shader:
    Code :
    uniform float weights[15];
     
    void main()
    {       
    	gl_FragColor=vec4(weights[0],weights[1],weights[2],1.0); 
    }
    And this code is used to set the uniforms (after activating the shaders):
    Code :
    GLfloat weights[15];
    weights[0]=1.0;
    weights[1]=0.7;
    weights[2]=0.5;
    weights[3]=0.4;
    GLuint paramWeights=glGetUniformLocationARB(shaderSystem->getHandle(), "weights");	
    		glUniform1fvARB(paramWeights,4,weights);
    (paramWeights 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:
    Code :
    	paramWeights=glGetUniformLocationARB(shaderSystem->getHandle(), "weights[0]");	
    glUniform1fARB(paramWeights,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).

  4. #4
    Junior Member Regular Contributor Zulfiqar Malik's Avatar
    Join Date
    Jun 2004
    Location
    London, UK
    Posts
    247

    Re: glUniform [ i ] fvARB problem

    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.
    Zulfiqar Inayat Malik.
    Senior Developer, The Foundry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •