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 2 of 2

Thread: mat4 array GLSL issues

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    23

    mat4 array GLSL issues

    Hey all.

    I'm currently trying to upload an array of mat4 to a GLSL shader problem. I'm however having quiet a bit of difficulty finding out what I'm doing wrong (If it's not a driver bug).

    Silly test GLSL code:
    Code :
    // Attributes
    in vec4 m_kColor;
     
    out vec4 FRAGDATA0;
     
    uniform mat4 akTest[4];
     
    // Shader code
    void main()
    {
            vec4 kTest = m_kColor;
            for (int i = 0; i < 4; i++)
            {
                    kTest = akTest[i] * kTest;
            }
     
            FRAGDATA0 = kTest;
    }

    Silly test CPU program:
    Code :
    int loc0 = pkTest->GetUniformLocation("akTest[0]"); // <-- Returns 0
    int loc1 = pkTest->GetUniformLocation("akTest[1]"); // <-- Returns 1 (Should be 4)
    int loc2 = pkTest->GetUniformLocation("akTest[2]"); // <-- Returns 2  (Should be 8)
    int loc3 = pkTest->GetUniformLocation("akTest[3]"); // <-- Returns 3  (Should be 12)


    As you can see from the above test code I'm not getting the matrix locations I would expect. Afaik a matrix in a GLSL shader takes up 4 128bit registers. When trying to upload the matrices using glUniformMatrix4fv(m_iLocation, 4, GL_FALSE, akMatrices);

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: mat4 array GLSL issues

    Quote Originally Posted by Elurahu
    When trying to upload the matrices using glUniformMatrix4fv(m_iLocation, 4, GL_FALSE, akMatrices);
    That's the right call. m_iLocation should be the return value of glGetUniformLocation() on "akTest".

    As for the rest, looks like you're presuming that "location" should be an offset in floats, but I don't understand why you think it should be. It's just an abstract handle AFAIK.

    You might post a short test program that illustrates your problem.

Posting Permissions

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