PDA

View Full Version : glDrawElements and glDrawArrays in same VAO?



normvcr
03-29-2015, 01:54 AM
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.

GClements
03-29-2015, 02:13 AM
Can you call both glDrawElements and glDrawArrays in the same VAO? (drawing two different objects with the two different approaches).
Yes.


If using two different VAOs, can they share the same compiled/linked program,
Yes.


or must the program be compiled/linked for each VAO, separately?
No.


Any suggestions for documentation that discusses such things methodically?
The only documentation which really discusses anything "methodically" is the specification (https://www.opengl.org/registry/) and the reference pages (https://www.opengl.org/sdk/docs/man/). 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.

normvcr
03-29-2015, 09:07 AM
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 :p . 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.

GClements
03-29-2015, 10:43 AM
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".

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.

Alfonse Reinheart
03-29-2015, 11:00 AM
A more explicit description of VAO state (https://www.opengl.org/wiki/Vertex_Specification) can be found on the OpenGL Wiki. It covers all of the VAO's state, as well as the functions that modify it.

normvcr
04-02-2015, 04:15 PM
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.

Alfonse Reinheart
04-04-2015, 09:35 AM
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.