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.

Yes.

Yes.

No.

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.

Thanks for the clear answers. I have started going through one of the above references

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 :stuck_out_tongue: . 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.

[QUOTE=normvcr;1265223]Thanks for the clear answers. I have started going through one of the above references

Hopefully, I can pull what I am looking for out of the 825 pages[/QUOTE]
Section 10.3.1, “Vertex Array Objects”.

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.

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.

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.

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.