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

Thread: GLSL & VBO

  1. #1
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    883

    GLSL & VBO

    Hi,

    Im confused about interaction of this two extensions. Problem is in custom vertex attributes...

    When setup some VBO I also setup standard vertex attribute pointers (pos, norm, color, texcoord).

    In render stage, I bind some VBO and all pointers for this VBO are already prepared (no need to setup pointers again).

    But, whats happend with custom vertex attributes in GLSL? For example I have several GLSL vert&frag programs for static geometry. Should I setup this custom vertex attribute pointers for each shader? Is this pointers safe from VBO switching?

    yooyo

    ps... soory for by bad english...

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: GLSL & VBO

    But, whats happend with custom vertex attributes in GLSL? For example I have several GLSL vert&frag programs for static geometry. Should I setup this custom vertex attribute pointers for each shader? Is this pointers safe from VBO switching?
    Not sure I understand you.

    In each shader, you have something like myvertex and mynormal and mytexcoord right?

    You need to bind them with the generic attributes (for each shader of course).

    For VBO, setup the offset pointers and render.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2004
    Posts
    10

    Re: GLSL & VBO

    Originally posted by yooyo:
    Hi,

    Im confused about interaction of this two extensions. Problem is in custom vertex attributes...

    When setup some VBO I also setup standard vertex attribute pointers (pos, norm, color, texcoord).

    In render stage, I bind some VBO and all pointers for this VBO are already prepared (no need to setup pointers again).

    But, whats happend with custom vertex attributes in GLSL? For example I have several GLSL vert&frag programs for static geometry. Should I setup this custom vertex attribute pointers for each shader? Is this pointers safe from VBO switching?

    yooyo

    ps... soory for by bad english...
    What you seem to imply is that *Pointer calls and BindBuffer calls are unrelated.
    They are not. The *Pointer calls capture the array buffer currently bound.
    So if you do
    BindBuffer(ARRAY_BUFFER, 1)
    VertexPointer(...)
    BindBuffer(ARRAY_BUFFER, 2)
    DrawArrays(...)
    your vertices will come from the vertex buffer 1, not 2. That is true for built in attribute as much as for generic ones.
    If I understand your question correctly, you are wondering whether after calling UseProgramObject, you need to emit AttribPointer calls again. You do not need to. These are totally separated from the program.
    Thinking more about it, I guess your question might be related to the fact that each program potentially maps a generic attribute to a different location.
    You can force the mapping to one that you want (so that your generic attributes never move between programs) through BindAttribLocation before the link happened on the program. Hope this helps.

  4. #4
    Advanced Member Frequent Contributor yooyo's Avatar
    Join Date
    Apr 2003
    Location
    Belgrade, Serbia
    Posts
    883

    Re: GLSL & VBO

    Thanx to all...

    After carefull reading VBO, ARB_VP & ARB_vertex_shader spec I got a clue. VBO save all pointer thats used to it.

    glBindAttribLocation do exactly what I want.

    And another question... What is better (I mean faster) interleaved arrays or separated arrays for each attribute?

    yooyo

  5. #5
    Junior Member Regular Contributor
    Join Date
    Oct 2003
    Location
    Hamburg, Germany
    Posts
    118

    Re: GLSL & VBO

    I think that the gl*Pointer semantics do current hardware more justice than the DirectX-style vertex declarations. Hardware typically has a set of DMA streams to fetch from.

    I personally haven't measured any difference between interleaved and non-interleaved arrays, however this dates back to the times of GF2-GF4.

Posting Permissions

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