5
\$\begingroup\$

In my journey out of immediate mode I've come across a snag that I haven't been able to find a decent answer for in any tutorial or API, namely: Which data structures are actually invoked when I make a call to a glDraw* function in OpenGL3.3+?

For example, if I want to draw two 3D models and I've put their vertex data in two different VBO's, does invoking glDrawArrays draw everything set under the current VAO? Or does it only draw the currently bound VBO sampling from the currently bound texture?

I basically understand VAO's and VBO's conceptually but its down to implementation that I'm running into problems, it's a big jump to go from the "stability" of immediate mode to the a-synchronicity of modern OpenGL.

\$\endgroup\$
5
\$\begingroup\$

glDrawArrays will draw from the currently bound vertex attribute arrays, which are "created" and bound themselves with glVertexAttribPointer and glEnableVertexAttribArray, which do use the currently bound vertex buffer. It doesn't matter if the vertex attributes are all from one buffer or multiple buffers, and you don't need any particular vertex buffer to be bound when drawing; all the glDraw* functions care about is which vertex attribute arrays are enabled.

\$\endgroup\$
  • 1
    \$\begingroup\$ And if I remember VAOs correctly, binding a different one will cause glDraw* calls to execute across the new VAO's AttribPointers/Arrays, in the state they were in when they were bound?And I suppose in that case whatever my uniforms are set to will be used across everything bound to the current VAO's active AttribPointers/Arrays? \$\endgroup\$ – Stomy Jan 6 '13 at 22:17
  • 1
    \$\begingroup\$ Correct, on both accounts. :) \$\endgroup\$ – jmegaffin Jan 6 '13 at 22:28
  • \$\begingroup\$ Cool! Then my problems have been solved! :D \$\endgroup\$ – Stomy Jan 6 '13 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.