quote:Original post by assen
For example, imagine an architecture where you have "World" objects (meshes, terrain patches etc.) and each of them has a "Renderable" counterpart when the engine has decided it's likely to be visible.
That's actually not even high level enough. Consider hardware assisted occlusion culling or LOD techniques, displacement mapped or fully procedural objects (where you have to take internal representations into account, when culling the object), clip plane extraction, matrix order, differences in coordinate frames, etc.
We had long discussions in our company, when the idea about multi-API support was brought up a couple of years ago. We tried several medium-level approaches, and they all failed at some point: either the OO interface became obscure and unflexible, or you had to sacrifice speed. Both were not acceptable.
We settled on a very high level approach: everything from object level on (including scenegraph, culling, visibility determination, LOD, lighting, etc) is taken by an API-specific implementation. The abstraction level of the interface is pretty high, a little like this:
class CRenderSystem { public: // object handling virtual void AddObject(CObjectBase &) = 0; virtual void RemoveObject(CObjectBase &) = 0; virtual void ModifyObject(CObjectBase &) = 0; virtual bool QueryObjectVisibility(CObjectBase &) = 0; // ... etc, 20+ object manipulation methods ... // General scene rendering virtual void DispatchShaderClasses() = 0; virtual void DispatchFatBuffer() = 0; virtual void RenderNow() = 0; virtual void RenderDeferred() = 0; virtual void ManualBufferSwap() = 0; // ... etc ...};
Until now, we have our primary OpenGL renderer. A part of the team used this interface to build a non-realtime RenderMan-based raytracing engine (a totally different architecture). There were no major problems. A D3D port should also be very easy with this approach. A big advantage is maximal performance. A big drawback, however, is that the support of a new API requires the re-implementation of large parts of the engine.
[edited by - Yann L on June 3, 2003 1:30:24 PM]