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: 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
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    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
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    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/

Posting Permissions

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