Results 1 to 4 of 4

Thread: Headache with glVertexAttribPointer

  1. #1
    Newbie Newbie
    Join Date
    Aug 2012
    Posts
    2

    Headache with glVertexAttribPointer

    I need this in my shader
    Code :
    attribute vec4 weight;
    attribute vec4 index;

    through this,
    Code :
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ARRAY_BUFFER, bufferId);
    glVertexAttribPointer(weightLoc, 4, GL_FLOAT, GL_FALSE, 8,  reinterpret_cast<const GLvoid*>( offsetof(structName, weight)));
    glEnableVertexAttribArray(weightLoc);
    glVertexAttribPointer(indexLoc, 4, GL_FLOAT, GL_FALSE, 8,  reinterpret_cast<const GLvoid*>( offsetof(structName, index)));
    glEnableVertexAttribArray(indexLoc);

    Code :
    struct structName
    {
    float weight;
    int index;
    }

    How can I get it to send 4 floats as 1 vec4, when my data are apart? They are structured such that there are an array of 4 of structName, if you get what I mean. Setting the stride by 8 or 32 doesn't seem to work.. I already have them buffered to the GPU with rows of 4 structName.

    Any help is appreciated!

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    992
    This is simply not possible. Either restructure your client data to a SOA (struct-of-array) layout or have 8 separate attributes in your shader (weight0, index0, weight1, index1, ...).
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Newbie Newbie
    Join Date
    Aug 2012
    Posts
    2
    Thanks, I will try to have rows of weight[4] and index[4] then, as per your former suggestion. If that case, just to confirm with the following code, I should have a vec4 weight and vec4 index instead of a float weight[4] and int index[4] right?
    Code :
    struct structName
    {
    float weight[4];
    int index[4];
    }
     
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ARRAY_BUFFER, bufferId);
    glVertexAttribPointer(weightLoc, 4, GL_FLOAT, GL_FALSE, 32,  reinterpret_cast<const GLvoid*>( offsetof(structName, weight)));
    glEnableVertexAttribArray(weightLoc);
    glVertexAttribPointer(indexLoc, 4, GL_INT, GL_FALSE, 32,  reinterpret_cast<const GLvoid*>( offsetof(structName, index)));
    glEnableVertexAttribArray(indexLoc);

    Thanks again for the help!

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    992
    This should work.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

Similar Threads

  1. Deferred Lighting Headache OpenGL + NvidiaCG
    By S-h-0-X in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 04-19-2012, 11:22 AM
  2. Matrix & Rotation Headache
    By dabeav in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 02-25-2011, 01:41 PM
  3. only using glVertexAttribPointer
    By FryderykC in forum OpenGL: GLSL
    Replies: 3
    Last Post: 02-15-2010, 03:56 PM
  4. ColorTable Headache
    By DarthPaul in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 01-27-2003, 06:33 AM
  5. nVidia drivers, glx, linking, headache :(
    By Goober in forum OpenGL: Linux
    Replies: 10
    Last Post: 07-15-2001, 02:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean