Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: glVertexAttribPointer

  1. #1
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    45

    glVertexAttribPointer

    void glVertexAttribPointer( GLuint index,
    GLint size,
    GLenum type,
    GLboolean normalized,
    GLsizei stride,
    const GLvoid * pointer);

    from official site


    about first parameter, what are the options for it ? and is it used instead of specifically defining glvertexpointer, gltexcoordpointer, glcolorpointer and glnormalpointer ?

    so should I use it instead of them, same performance ?

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    For the first parameter, the values are from 0 to whatever the maximum your card supports. Check the value with a call to glGetInteger.
    http://www.opengl.org/wiki/GlVertexAttribPointer

    The function became available in GL 2 and it should probably be the only choice starting GL 3.
    It is a matter of API cleanup and making the API more generic. This change has nothing to do with performance.
    ------------------------------
    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
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    45
    Quote Originally Posted by V-man View Post
    For the first parameter, the values are from 0 to whatever the maximum your card supports. Check the value with a call to glGetInteger.
    http://www.opengl.org/wiki/GlVertexAttribPointer

    The function became available in GL 2 and it should probably be the only choice starting GL 3.
    It is a matter of API cleanup and making the API more generic. This change has nothing to do with performance.
    Thanks again.

    By the way, can i fill stride parameter with sizeof the entire vertex array instead of 0 ? what is the exceptions of this parameter is used differently ?


    and also, there is still no enough explanation about index parameter about it's values.

    edit : oh god i think i got glvertexattribpointer wrong.. i didn't know it was GLSL thing lol. i think i won't use it for a long time.
    Last edited by artariel; 04-30-2012 at 08:32 PM.

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    2
    Quote Originally Posted by V-man View Post
    For the first parameter, the values are from 0 to whatever the maximum your card supports. Check the value with a call to glGetInteger.
    http://www.opengl.org/wiki/GlVertexAttribPointer

    The function became available in GL 2 and it should probably be the only choice starting GL 3.
    It is a matter of API cleanup and making the API more generic. This change has nothing to do with performance.
    I am teaching myself OpenGL and I would greatly appreciate help interpreting the man page reference above.

    The Description section begins with the following sentence.
    glVertexAttribPointer, glVertexAttribIPointer and glVertexAttribLPointer
    specify the location and data format of the array of generic vertex attributes at index _index_ to use when rendering.
    Is the "array of generic vertex attributes" the same as the VertexAttribArray part of the function name glEnableVertexAttribArray()?
    If not, what array is this referring to?

    In the Function Definition section, pointer argument, there is the following sentence.
    Specifies a offset of the first component of the first generic vertex attribute in the array
    in the data store of the buffer currently bound to the GL_ARRAY_BUFFER target.
    Is the array in "the first generic vertex attribute in the array in the data store of the buffer"
    the same array referred to in "array of generic vertex attributes" mentioned from the Description?

    The pointer argument definition states that the attribute array is part of the buffer object; however, the language is nearly identical
    to the attribute array mentioned at the beginning of the Description (which I suspect is a different array).

  5. #5
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Yes, it is the same thing. And yes, you can specify large values for the stride parameter. That is explained on another page of the wiki.
    ------------------------------
    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);

  6. #6
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    45
    Quote Originally Posted by V-man View Post
    Yes, it is the same thing. And yes, you can specify large values for the stride parameter. That is explained on another page of the wiki.
    thanks.

    so i must keep using glvertexpointer, gltexcoordpointer, glcolorpointer and glnormalpointer ?

    By the way, i will convert a glbegin/end based obj loader/renderer to VBOs. Will I get performance gain ?

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,201
    glVertexAttribPointer was originally introduced with the old GL_ARB_vertex_program extension, which defines mappings between conventional attributes and generic attributes, like so:
    Code :
        Generic
        Attribute   Conventional Attribute       Conventional Attribute Command
        ---------   ------------------------     ------------------------------
             0      vertex position              Vertex
             1      vertex weights 0-3           WeightARB, VertexWeightEXT
             2      normal                       Normal
             3      primary color                Color
             4      secondary color              SecondaryColorEXT
             5      fog coordinate               FogCoordEXT
             6      -                            -
             7      -                            -
             8      texture coordinate set 0     MultiTexCoord(TEXTURE0, ...)
             9      texture coordinate set 1     MultiTexCoord(TEXTURE1, ...)
            10      texture coordinate set 2     MultiTexCoord(TEXTURE2, ...)
            11      texture coordinate set 3     MultiTexCoord(TEXTURE3, ...)
            12      texture coordinate set 4     MultiTexCoord(TEXTURE4, ...)
            13      texture coordinate set 5     MultiTexCoord(TEXTURE5, ...)
            14      texture coordinate set 6     MultiTexCoord(TEXTURE6, ...)
            15      texture coordinate set 7     MultiTexCoord(TEXTURE7, ...)
           8+n      texture coordinate set n     MultiTexCoord(TEXTURE0+n, ...)

    (See: http://oss.sgi.com/projects/ogl-samp...ex_program.txt). In general, these might work on all hardware, and if they work on yours and if you're not intending to distribute your program then you could try them and see what happens. Otherwise it would be wise not to depend on them at this stage.

    Converting to VBOs you may or may not get a performance gain. With VBOs you need to be careful of cases where you must update buffer contents every frame, so if your data is not static then you'll be better to write some test programs and become familiar with the specification, use cases and hardware performance characteristics first. Also, if vertex submission/bandwidth is not a bottleneck in your program then even in the best case you're not likely to see much in the way of a performance gain.

  8. #8
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    Be wary however that the mappings hold only for ARB programs - not GLSL programs. In GLSL only attribute 0 is kind of aliased with conventional attribute for vertex position.

  9. #9
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    45
    Quote Originally Posted by mhagain View Post
    glVertexAttribPointer was originally introduced with the old GL_ARB_vertex_program extension, which defines mappings between conventional attributes and generic attributes, like so:

    In general, these might work on all hardware, and if they work on yours and if you're not intending to distribute your program then you could try them and see what happens. Otherwise it would be wise not to depend on them at this stage.
    Thanks for detailed info.

    Are you talking about the glVertexAttribPointer or the other methods (might work on all hardware part) ? So, Are the classical methods like gltexcoordp, glvertexp still safe to use on all hardwares?

  10. #10
    Intern Newbie
    Join Date
    Apr 2012
    Posts
    45
    Oh I have just realized that there's no such function as glBindBuffer and all of the buffer functions in VS2010. I didn't want to start another thread. I get identifier not found error ?!

Posting Permissions

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