I would like to implement a renderer making heavy use of instancing.
Here’s what I see as a global pipeline for rendering :
- Update Scene Graph
- Perform visibility tests and store model matrices of geometry about to be drawn
- Sort matrices per-instance (mesh) and per-depth(earlyZ!)
- For each instance (mesh)
- Stream matrices in a VBO (I’ll call it the instance VBO) in a specified range.
- Bind VAO
- For each submesh, bind material (UBO, textures and shader program) and call a drawinstanced function.
I’d recover the matrix with four vec4 with in attributes in the vertex shader and use the VertexAttribDivisor function(instead of using a TBO(slower) or UBO(less flexible for dynamic number of instances)).
Now I would like to update the buffer with the algorithm described by Rob Barris just here (using mapbufferrange and gl_unsynced_bit) : http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=273484&page=4.
Unfortunately, VAOs make this impossible since pointers to vertex attributes are constant making it possible for the gpu to read in a range to which I could be writing in some usecases (adding instances dynamically during the application loop)
This is quite annoying , and I might just try not to use VAOs -at least, bind one and then forget about it-… Is there anything I can/could/should do? (Or perhaps my idea isn’t good …)