Architecture a for a central renderer rather than self-rendering

Posted by The Communist Duck on Game Development See other posts from Game Development or by The Communist Duck
Published on 2010-08-31T14:49:10Z Indexed on 2011/11/17 2:05 UTC
Read the original article Hit count: 278

Filed under:
|

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.

First idea
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.

Second idea
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.

Other ideas
???
PROFIT

Anyone got ideas? Thank you.

© Game Development or respective owner

Related posts about architecture

Related posts about rendering