Hi,
Lately, I’ve been pondering on the intended usage pattern of Vertex Array Objects (VAO). Clearly, their intent is to “batch” multiple calls to glVertexAttribPointer() for meshes with many attributes.
For now, I’ve been considering to create a VAO for each individual mesh/shader combination because different shader programs may require a different set of vertex attributes to be enabled. This will likely result in a large number of created VAOs and I’ve read reports of users telling that this results in a performance hit on certain driver implementations.
Another option would be to create a single VAO per mesh and use the same VAO across all shader programs. My concern with this approach is that some attributes may be enabled while they are not required by the shader. The specification is rather vague about the actual behavior of unused yet enabled attributes and I suspect that the details of how to deal with this is left to hardware vendors. I fear I may run into performance/compatibility issue if I follow this path.
Of course, it would be possible to enable/disable individual vertex attributes on the VAO slightly before invoking a “draw” command, but then, VAO lose their primary purpose of “doing everything in a single bind() call”.
Thus, I would like to have some recommendations regarding VAO usage and how I can expect them to behave under the two different paths (ie: 1 VAO per shader/mesh combination & 1 VAO per mesh with unused but enabled attributes). Which option is more reasonable?
Thanks for your help,
PM