Archived

This topic is now archived and is closed to further replies.

neurokaotix

Creating an engine with multiple renderer support?

Recommended Posts

I''ve read a lot about how to create an engine with support for multiple renderers but I just can''t grasp exactly how it is done? I mean, so far I''ve picked up that you need have api independed functions that call the specific function for opengl or directx etc.. but I what I don''t understand is how this is actually implemented. And then when people explain it to me it sounds as if they all read it from the same place and don''t actually understand how to implement it either lol Is there someone who could right a few lines of sample code on how it might work? Also if possible, what kind of file structure should my engine have? I was thinking maybe a core.dll that calls opengl.dll or directx.dll to get the specific calls.. *shrugs* I''d rather get your guys'' input. Thanks

Share this post


Link to post
Share on other sites
Are you familiar with the "Visitor" design pattern? Well one way of achieving API independence is to use something similar to that. Suppose you have a scene graph representing your world. In your world you have different geometric types like Character, Room and so on.
Each of those types derive from a common subclass which declares a function something along these lines (assuming C++)

class Object
{
...
virtual void Render(Renderer& renderer) = 0;
...
}

Your renderer then has methods for rendering each kind of geometric types, it acts like the visitor.

class Renderer
{
...

virtual void RenderGeometry(House* house) = 0;
virtual void RenderGeometry(Room* room) = 0;
...
}


Then when you render through your tree you use an overload Render function in each geometry node to do this:

void House::Render(Renderer &renderer)
{
renderer.RenderGeometry(this);
}

this makes sure that the correct render function in the renderer class is called. Then you simply inherit the renderers you want:

class OpenGLRenderer : public Renderer
{
void RenderGeometry(House* house);
...
}


The only place you decide which API to use is when you create your renderer which can be handled by a factory or something.

This is just one way to do it - but it is fairly simple and easy to use (once you get the grasp of it). It's more or less the method David Eberly uses in "3D Game Engine Design".

Codito, ergo sum - Graphics Programming

[edited by - thoooms on January 30, 2003 4:50:59 AM]

Share this post


Link to post
Share on other sites