Currently, my application uses only Direct3D9 for graphics, but in the future I plan to expand it to D3D10 and, possibly, OpenGL. The question is, how can I do this neatly?
There are currently various rendering methods in my code
void Render(boost::function<void()> &Call) { D3dDevice->BeginScene(); Call(); D3dDevice->EndScene(); D3dDevice->Present(0,0,0,0); }
Then the function passed depends on the exact state, for example MainMenu-> Render, Loading-> Render, etc. Then they will call methods of other objects.
void RenderGame() { for(entity::iterator it = entity::instances.begin();it != entity::instance.end(); ++it) (*it)->Render(); UI->Render(); }
And a class sample derived from entity :: Base
class Sprite: public Base { IDirect3DTexture9 *Tex; Point2 Pos; Size2 Size; public: Sprite(IDirect3DTexture9 *Tex, const Point2 &Pos, const Size2 &Size); virtual void Render(); };
Each method then takes care of how best to display data with more detailed settings (for example, pixel shaders are supported).
The problem is that I'm really not sure how to extend this to be able to use one of which may be slightly different (D3D v OpenGL modes) ...
source share