How general should vertex array objects be?
I'd like to plan ahead and avoid a major revision down the road. I'm having a hard time wrapping my head around a few (possibly conflicting) pieces of wisdom scattered around the internet.
- This answer on VAO best practices:
for each batch: generate VAOs and bind buffers
- Another describes one should share VAOs with multiple objects
- Khronos OpenGL Vertex specification just providing general useful information
This is what I could gather from a half a year of slowly reading specs and docs, building and abstracting away a somewhat structured piece of a game engine.
- The more state changes the slower the execution (self evident)
- VAO holds state for draw calls (for a simple
bind -> draw
) - VBOs are bound to a VAO using the attribute location from a shader program (
glGetAttribLocation -> glVertexAttribPointer
) - These arrays are enabled by location using
glEnableVertexAttribArray
So for a single VAO, how many or what kinds of objects should it take care of? Should a single VBO contain many objects' e.g. normals and the program use offsets when drawing, or is having separate VBOs for each a viable option?
Also, since we enable the attribute array by location inside the shader program, are the VAO and the shader in some way connected?
Any pointers would be greatly appreciated!