This question already has an answer here:
For the architectural side of rendering, there's two main ways: having each object render itself, and having a single renderer which renders everything.
I'm currently aiming for the second idea, for the following reasons:
The list can be sorted to only use shaders once. Else each object would have to bind the shader, because it's not sure if it's active. The objects could be sorted and grouped.
Easier to swap APIs. With a few macro lines, it can be easy to swap between a DirectX renderer and an OpenGL renderer (not a reason for my project, but still a good point)
- Easier to manage rendering code
Of course, if anyone has strong recommendations for the first method, I will listen to them.
But I was wondering how make this work.
The renderer has a list of pointers to the renderable components of each entity, which register themselves on RenderCompoent creation. However, I'm worrying that this may end up as a lot of extra pointer weight. But I can sort the list of pointers every so often.
The entire list of entities is passed to the renderer each render call. The renderer then sorts the list (each call, or maybe once?) and gets what it wants. That's a lot of passing and/or sorting, however.
Anyone got ideas? Thank you.