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: generic vertex attrib

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

    generic vertex attrib

    From what I understood from ARB_vertex_shader there is nothing special we have to do to use generic vertex attributes.

    In GLSL, if someone uses gl_Vertex and gl_Normal (which is what I'm doing) and the code we use

    glEnableVertexAttribArrayARB
    glDisableVertexAttribArrayARB
    glVertexAttribPointerARB

    is it suppose to work without having to do anything else?

    It seems gl_Vertex contains valid values, but gl_Normal has a constant (wrong!) normal.

    If I use glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer
    glEnableClientState(GL_NORMAL_ARRAY);
    glNormalPointer

    it works as expected.

    Can someone explain?
    ------------------------------
    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);

  2. #2
    Member Regular Contributor
    Join Date
    Apr 2002
    Location
    Austria
    Posts
    328

    Re: generic vertex attrib

    Do you pass the normal to vertex index number 2 or do you fetch the vertex location with glGetAttribLocationARB("gl_Normal") and then pass the normal to that location?
    There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

    There is another theory which states that this has already happened...

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

    Re: generic vertex attrib

    Originally posted by V-man:
    From what I understood from ARB_vertex_shader there is nothing special we have to do to use generic vertex attributes.

    In GLSL, if someone uses gl_Vertex and gl_Normal (which is what I'm doing) and the code we use

    glEnableVertexAttribArrayARB
    glDisableVertexAttribArrayARB
    glVertexAttribPointerARB

    is it suppose to work without having to do anything else?

    It seems gl_Vertex contains valid values, but gl_Normal has a constant (wrong!) normal.

    If I use glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer
    glEnableClientState(GL_NORMAL_ARRAY);
    glNormalPointer

    it works as expected.

    Can someone explain?
    There is no aliasing between generic vertex attributes and fixed function attributes, except for gl_Vertex and generic attrib 0.
    So using gl_Normal while enabling a vertex attrib is not a proper usage.
    This is true for ARB_vertex_program as well, where aliasing is unspeficied.
    If you want to use generic attributes, you will have to use a generic attribute in your shader, and get (or set) the attribute location in your C code.
    Note as well that getting the location of gl_Normal should return -1, as it is a built in attribute, that you cannot load through generic attribute API.
    so instead of using gl_Normal, use
    attribute vec4 mynormal;
    and then, do a
    glGetAttribLocationARB(prog, "mynormal");
    Then you can enable/setup that vertex attribute.

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

    Re: generic vertex attrib

    so instead of using gl_Normal, use
    attribute vec4 mynormal;
    and then, do a
    glGetAttribLocationARB(prog, "mynormal");
    The problem with this is you have to know ahead of time the name "mynormal".

    Besides, I though the standard attributes occupied specific slots, like for normal it is slot 2.

    There is no aliasing between generic vertex attributes and fixed function attributes, except for gl_Vertex and generic attrib 0.
    From my understanding, they had to do this because vertex or attrib0 is used for signaling, but I don't see an explanation why gl_Normal and attrib2 can't be the same?

    glGetAttribLocationARB(handle, "gl_Normal") is defined to return -1 for some unexplained reason.

    Yes, I know about ARB_vertex_program.
    It too defined normals as beeing mapped to attrib2 but there is no aliasing ... weird
    ------------------------------
    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);

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

    Re: generic vertex attrib

    Originally posted by V-man:
    [QB]The problem with this is you have to know ahead of time the name "mynormal".

    Besides, I though the standard attributes occupied specific slots, like for normal it is slot 2.
    This is not the case. That is what I mean when I say there is no aliasing. the way the spec is written, slot 2 is a generic slot number 2, normal is a built-in slot. They do not end up being the same. In ARB_vertex_shader, you will see no table saying 2 is normal.

    Originally posted by V-man:
    [QB]
    From my understanding, they had to do this because vertex or attrib0 is used for signaling, but I don't see an explanation why gl_Normal and attrib2 can't be the same?
    Well, the spec says they are not.
    From the spec:
    There is no aliasing among generic attributes and conventional attributes. In other
    words, an application can set all MAX_VERTEX_ATTRIBS_ARB generic attributes and all
    conventional attributes without fear of one particular attribute overwriting the value
    of another attribute.

Posting Permissions

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