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

Thread: Where in the 3.3 core spec can I find this info. on glVertexAttribPointer?

  1. #1
    Intern Contributor
    Join Date
    Mar 2017
    Posts
    51

    Where in the 3.3 core spec can I find this info. on glVertexAttribPointer?

    In the Description section of glVertexAttribPointer in the ref pages, I found this:

    When a generic vertex attribute array is specified, size, type, normalized, stride, and pointer are saved as vertex array state, in addition to the current vertex array buffer object binding.
    In 3.3 core, I'd conclude from this that after you use glVertexAttribPointer as needed with a "VAO" and a "vertex array buffer object" binded, it's okay to unbind the current vertex array buffer object (with glBindBuffer(GL_ARRAY_BUFFER,0)), even while the VAO is still binded. It helped me to understand more this comment from the source code in the LearnOpenGL "Hello Triangle" tutorial:

    Code :
    glBindVertexArray(...);
    glBindBuffer(GL_ARRAY_BUFFER, ...);
    ...
    glVertexAttribPointer(...);
    glEnableVertexAttribArray(...);
    ...
    //note that this is allowed, the call to glVertexAttribPointer registered VBO as the vertex attribute's bound vertex buffer object so afterwards we can safely unbind
    glBindBuffer(GL_ARRAY_BUFFER,0);
    ...
    glBindVertexArray(...);

    Where can I find this information in the 3.3 core spec? I want to make a note of it there. I tried looking in "2.9.6 Vertex Arrays in Buffer Objects", but I can't find anything similar. The first paragraph talks about glVertexAttribPointer, but more about client state rather than vertex array object state.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,173
    Quote Originally Posted by DragonautX View Post
    In 3.3 core, I'd conclude from this that after you use glVertexAttribPointer as needed with a "VAO" and a "vertex array buffer object" binded, it's okay to unbind the current vertex array buffer object (with glBindBuffer(GL_ARRAY_BUFFER,0)), even while the VAO is still binded.

    ...

    Where can I find this information in the 3.3 core spec
    It's not all-in-one-place. If you read the bits in 2.9.1 and 2.9.6 (quoted below), that pretty well covers it.

    Quote Originally Posted by OpenGL 3.3 Core Spec
    2.9.1 Creating and Binding Buffer Objects
    ...
    The binding is effected by calling [glBindBuffer]. target must be one of the targets listed in table 2.8 [(includes ARRAY_BUFFER)].

    2.9.6 Vertex Arrays in Buffer Objects
    ...
    the VertexAttribPointer command copies
    the value of ARRAY_BUFFER_BINDING (the queriable name of the buffer binding
    corresponding to the target ARRAY_BUFFER) to the client state variable VERTEX_-
    ATTRIB_ARRAY_BUFFER_BINDING for the specified index.

    2.10 Vertex Array Objects

    ...
    The currently bound vertex array object is used for all commands which modify
    vertex array state, such as VertexAttribPointer and EnableVertexAttribArray;
    all commands which draw from vertex arrays, such as DrawArrays and DrawElements;
    and all queries of vertex array state (see chapter 6).

    Chapter 6: State and State Requests

    6.1.2 Data Conversions
    ...
    Vertex array state variables are qualified by the value of VERTEX_ARRAY_-
    BINDING to determine which vertex array object is queried. Tables 6.4 and 6.5
    define the set of state stored in a vertex array object....

    Table 6.4. Vertex Array Object State

    VERTEX_ATTRIB_ARRAY_ENABLED
    VERTEX_ATTRIB_ARRAY_SIZE
    VERTEX_ATTRIB_ARRAY_STRIDE
    VERTEX_ATTRIB_ARRAY_TYPE
    VERTEX_ATTRIB_ARRAY_NORMALIZED
    VERTEX_ATTRIB_ARRAY_INTEGER
    VERTEX_ATTRIB_ARRAY_DIVISOR
    VERTEX_ATTRIB_ARRAY_POINTER
    VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
    ELEMENT_ARRAY_BUFFER_BINDING

    Table 6.6. Vertex Array Data (not in Vertex Array objects)

    ARRAY_BUFFER_BINDING
    VERTEX_ARRAY_BINDING
    PRIMITIVE_RESTART
    PRIMITIVE_RESTART_INDEX
    So basically, glBindBuffer on GL_ARRAY_BUFFER just modifies the buffer bound to that buffer object bind target. Whereas glVertexAttribPointer() copies the binding from there into VAO state for the specified vertex attribute. So just calling glBindBuffer on GL_ARRAY_BUFFER doesn't modify VAO state.

    However, calling glBindBuffer on GL_ELEMENT_ARRAY_BUFFER does! (Notice above that it is part of VAO state.)
    Last edited by Dark Photon; 09-21-2017 at 06:47 PM.

  3. #3
    Intern Contributor
    Join Date
    Mar 2017
    Posts
    51
    That was really helpful, seeing it pieced together like that. I thought GL_ARRAY_BUFFER modified VAO state if I binded an object to it while I had a VAO bound, but looks like I was wrong on that. Table 6.6 is great info. too. I didn't know that existed. I think I got ARRAY_BUFFER_BINDING and VERTEX_ARRAY_BINDING mixed up as the same thing, but the table cleared it up for me. I'll keep a note of the ELEMENT_ARRAY_BUFFER_BINDING too.

    Thanks for the help!

Posting Permissions

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