I have roughly seen 2 different ways rendering engines are commonly handled (there could be more). And was wondering which general design is better for a general purpose engine.
Central Handler Engine
In this kind of engine, a global structure (commonly called engine or renderer) manages the synchronization with the rendering thread. It is responsible to initialize contexts, orchestrate draw queues, manage resources and so on.
A typical draw call would be:
- Object A calls a function in the handler.
- Handler adds object A to a queue
- Once object A reaches the front of the Queue, any buffers that may be needed are loaded and its information is rendered
Distributed Rendering Engine
In this design, rather than having a single handler, each object is responsible for ensuring that its values are loaded into the correct buffers and that all bindings are executed correctly prior to a render call.
A typical render call would be:
- The render thread calls a function in object A that thread safely loads all of its information into the context.
- The render thread calls a draw function in object A that handles the rendering
The second is used far less often than the first, however the first tends to have less delegated methods which reduces call overhead.
Which is better?