Hi.
I am currently constructing a basic 3D game engine using OpenGL, and would like some advice on a bit of an obscure facet that I found very little resources for online.
I’m setting up a batch rendering system that renders groups of meshes in a single draw call based on the material that is applied to them (a material is just an abstraction that maintains a shader program and any texture maps that may need to be inputted into the shader).
In addition to this, I’ll be setting up a scene graph which represents individual objects in the world with child/parent relationships. Each node in the heirarchy will have its own matrix that represents its transform relative to its parent. Now, I’d like the scene graph to work with the batch renderer to ensure that individual models (that will be associated with some of these nodes in the heirarchy) are rendered in the correct position in the world; bearing in mind some of these individual models will probably share a common material so we’d like to group these into a batch.
Now this is where I hit a brick wall…
Although less efficient, the idea of using individual VAOs to render meshes for each object seems more intuitive, since I’d imagine you could swap in the model matrix for that object, issue a draw call and then swap it out.
With batching involved though, there are a few issues (in my mind):
First of all, the batch renderer knows nothing about how vertices (that it is processing) are grouped into objects. As far as it’s concerned, they exist only as a linear buffer of numbers.
Secondly, even if it did know this information, there isn’t any way to swap in and out different matrices as it draws, since all vertices are drawn in one draw call.
I’ve been thinking about this for a while, but cannot seem to figure it out. I don’t know whether or not I’m being extremely dumb or something (forgive if I am).
Anyone who could provide me a better insight into what I’ve discussed here would be much appreciated.