So i've been trying to think of the best way to decide which graphics interface to use on initialization of my engine. I really like in C# how you can create an interface, inherit from it, then declare an object of that interface and initialize it with one of the inherited classes. I know thats not exactly possible with C++ because you can't create an object from an interface.
I know i'm missing something here, but i was hoping i might get a little insight from some of you here. The way i've decided to go about it, although its going to change once i find a better way, is create an IGraphics interface, then create directx and opengl classes that inherit from that interface. in the app, i have one member for each of those inherited classes. i load in the options file, then initialize the graphics based on whats in the options file. to do this, i have a function which returns a reference to one of those members and then i initialize the graphics. here's some code snippet of what i'm doing, and let me know your thoughts and hopefully a better way of doing this.
application class
class App
{
private:
// both these inherit from the IGraphics interface
static GraphicsD3D11_1 m_GraphicsD3D11_1;
static GraphicsOpenGL m_GraphicsOpenGL;
public:
IGraphics *Graphics();
// more stuff
}
function which decides which api to use
IGraphics *App::Graphics()
{
switch (m_Settings.m_GraphicsAPI)
{
case GraphicsAPI_D3D11_1:
{
return &m_GraphicsD3D11_1;
}
case GraphicsAPI_OPENGL:
{
return &m_GraphicsOpenGL;
}
default:
return NULL;
}
return NULL;
}
then when i need to use the graphics api, i just call it like this:
Graphics()->Initialize(); // just an example of a call to initialize the graphics
any suggestions on a better way to do this. my worry is that it is not the most performant solution, and especially since i need to have declared a member for each graphics api