Reputation: 14099
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?
Upvotes: 6
Views: 2898
Reputation: 99
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.
Upvotes: 0
Reputation: 473192
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
.
Upvotes: 1