Say we bind vertex attribute locations to the same values on two programs. Is it correct to use the same vertex array object to draw with these two programs?
2 Answers
Define "correct."
If two program objects use compatible attribute locations, then they use the same attribute locations. VAOs work off of attribute locations, so a VAO that works with one will work with another. So this will work.
In general, it is a matter of performance whether you actually take advantage of this. It's generally a good idea to avoid changing vertex array state, but it's not clear how important this is relative to other state changes. You're changing programs anyway, so not changing VAOs when you change programs will at worst be no slower and can lead to significant performance increases.
However, it is not clear how much work you should do to minimize vertex array state changes. If you can pack models into the same buffer objects with the same format, you can render all of them without VAO changing using functions like glDrawArrays
or glDrawElementsBaseVertex
.

- 449,505
- 63
- 781
- 982
-
This answer http://stackoverflow.com/questions/4635913/explicit-vs-automatic-attribute-location-binding-for-opengl-shaders basically clarifies what I mean by correct. – Kimi Nov 08 '12 at 20:05
I've tried using the same VAO with different shaders and I could see visual artifacts. (The IDs of the attributes did match) The solution was to use a new VAO for every single program.

- 99
- 1
- 6
-
2This means that you either have another bug, or your OpenGL implementation is broken. The vertex setup state stored in a VAO is completely orthogonal to program state, as long as the programs use the same attribute locations. – Reto Koradi Feb 14 '15 at 03:38