Results 1 to 7 of 7

Thread: glDrawElements and glDrawArrays in same VAO?

  1. #1
    Newbie Newbie
    Join Date
    Mar 2016
    Posts
    4

    glDrawElements and glDrawArrays in same VAO?

    Can you call both glDrawElements and glDrawArrays in the same VAO? (drawing two different objects with the two different approaches). If using two different VAOs, can they share the same compiled/linked program, or must the program be compiled/linked for each VAO, separately? Any suggestions for documentation that discusses such things methodically? Thanks.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,104
    Quote Originally Posted by normvcr View Post
    Can you call both glDrawElements and glDrawArrays in the same VAO? (drawing two different objects with the two different approaches).
    Yes.

    Quote Originally Posted by normvcr View Post
    If using two different VAOs, can they share the same compiled/linked program,
    Yes.

    Quote Originally Posted by normvcr View Post
    or must the program be compiled/linked for each VAO, separately?
    No.

    Quote Originally Posted by normvcr View Post
    Any suggestions for documentation that discusses such things methodically?
    The only documentation which really discusses anything "methodically" is the specification and the reference pages. But you won't find anything in those which states that explicitly. You're asking about potential restrictions which don't actually exist. If such restrictions existed, they would be mentioned; they don't exist so they aren't mentioned.

    Essentially, VAOs are just a mechanism for grouping certain state into an object so that you can control a large amount of state with a single call.

  3. #3
    Newbie Newbie
    Join Date
    Mar 2016
    Posts
    4
    Thanks for the clear answers. I have started going through one of the above references
    https://www.opengl.org/registry/doc/glspec45.core.pdf
    From page 3,
    One of the main goals of this Specification is to describe OpenGL objects
    and context state explicitly, to elucidate how they change in response to OpenGL
    commands, and to indicate what their effects are.
    Hopefully, I can pull what I am looking for out of the 825 pages . I suppose anything that is used via a "bind" type of statement is owned by the current VAO, but I suspect it is more complicated than that.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,104
    Quote Originally Posted by normvcr View Post
    Thanks for the clear answers. I have started going through one of the above references
    https://www.opengl.org/registry/doc/glspec45.core.pdf
    Hopefully, I can pull what I am looking for out of the 825 pages
    Section 10.3.1, "Vertex Array Objects".
    Quote Originally Posted by normvcr View Post
    I suppose anything that is used via a "bind" type of statement is owned by the current VAO, but I suspect it is more complicated than that.
    A VAO holds the state for each attribute array or binding. Roughly, the parameters to glVertexAttribPointer or glVertexAttribFormat, the buffer bound to GL_ARRAY_BUFFER at the time of the the glVertexAttribPointer call, the enabled state (glEnableVertexAttribArray), and any divisor (glVertexAttribDivisor). In addition, it holds the current binding for GL_ELEMENT_ARRAY_BUFFER. For the full details, see tables 23.3 and 23.4.

  5. #5
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674
    A more explicit description of VAO state can be found on the OpenGL Wiki. It covers all of the VAO's state, as well as the functions that modify it.

  6. #6
    Newbie Newbie
    Join Date
    Mar 2016
    Posts
    4
    The article and spec were useful. On a related question, within the same VAO, is it possible to have two different buffers supplying data to the same attribute? For example, I have a point cloud (GL_POINTS) and a bounding box (GL_LINE_STRIP), which currently share a single big buffer, which is filled in by two calls to glBufferSubData.

    I have come across OGLplus
    http://oglplus.org/
    which I plan to test out in my next project. It is a light C++ wrapper around OpenGL, which, for example, manages allocation/deallocation of VAOs , buffers et al. Thanks for the feedback.

  7. #7
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674
    Quote Originally Posted by normvcr View Post
    The article and spec were useful. On a related question, within the same VAO, is it possible to have two different buffers supplying data to the same attribute? For example, I have a point cloud (GL_POINTS) and a bounding box (GL_LINE_STRIP), which currently share a single big buffer, which is filled in by two calls to glBufferSubData.
    It is not possible for a single attribute to come from multiple buffers. And indeed, what would that mean? If you have a 'vec4' input variable in your vertex shader, what would it mean for its data to come from multiple buffers? Do you want the first two components to come from one buffer, with the last two coming from another?

    There's no reason you can render your example with two glDraw calls. The first call draws the point cloud, and the second draws the lines. Since they're both in the same buffer (and presumably use the same vertex format), there's no reason to want to switch VAOs between them.

Similar Threads

  1. glDrawElements vs. glDrawArrays
    By Nikki_k in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-30-2014, 05:21 AM
  2. glDrawArrays vs glDrawElements
    By Kopelrativ in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-20-2011, 04:59 AM
  3. glDrawElements vs glDrawArrays
    By V-man in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 09-19-2001, 05:36 PM
  4. glDrawElements vs glDrawArrays
    By jorritTyberghein in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 05-24-2001, 12:51 AM
  5. glDrawArrays vs glDrawElements
    By KRONOS in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 07-22-2000, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean