I'm toying with a multiapi and maybe multiplatform rendering system abstraction and just have a C++ related query about interfaces.
If I have the following abstract base classes:
class ISwapChain
{
public:
virtual ~ISwapChain() {}
virtual void Present() = 0;
};
class IRenderTarget
{
public:
virtual ~IRenderTarget() {}
virtual void SomeRenderTargetRelatedMethod() = 0;
};
class IRenderWindow : public ISwapChain, public IRenderTarget
{
public:
virtual ~IRenderWindow() {}
virtual void Resize(/* ... */);
/* ... */
};
So I declare a D3D specific render window like this...
class D3DRenderWindow : public MyWin32Lib::Window /* Win32 specific window wrapper */, IRenderWindow
{
public:
D3DRenderWindow() {}
virtual ~D3DRenderWindow() {}
// ISwapChain stuff
void Present() {}
// IRenderTarger stuff
void Resize() {}
};
It all compiles and works but I've never really needed to composite "interfaces" together like this in C++ and I was wondering if it's a bad idea.
The reason I want to do the above is so I can do something like this:
IRenderer* pRenderer = new Renderer(/* params including D3D, OGL, Software enum */);
IRenderWindow* = pRenderer->CreateWindow(/* some params */);
Note: I know the performance hit of using runtime polymorphism. This is just an experiment. My main framework uses templates to achieve a similar effect at compile time