opengl - c++ Having multiple graphics options -
currently app uses direct3d9 graphics, in future i' m planning extend d3d10 , possibly opengl. question how can in tidy way?
at present there various render methods in code
void render(boost::function<void()> &call) { d3ddevice->beginscene(); call(); d3ddevice->endscene(); d3ddevice->present(0,0,0,0); } the function passed depends on exact state, eg mainmenu->render, loading->render, etc. these oftern call methods of other objects.
void rendergame() { for(entity::iterator = entity::instances.begin();it != entity::instance.end(); ++it) (*it)->render(); ui->render(); } and sample class derived 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 takes care of how best render given more detailed settings (eg pixel shaders supported or not).
the problem i'm not sure how extend able use 1 of, may different (d3d v opengl) render modes...
define interface sufficient application's graphic output demands. implement interface every renderer want support.
class irenderer { public: virtual ~irenderer() {} virtual void rendermodel(cmodel* model) = 0; virtual void drawscreenquad(int x1, int y1, int x2, int y2) = 0; // ...etc... }; class copenglrenderer : public irenderer { public: virtual void rendermodel(cmodel* model) { // render model using opengl } virtual void drawscreenquad(int x1, int y1, int x2, int y2) { // draw screen aligned quad using opengl } }; class cdirect3drenderer : public irenderer { // similar, render using direct3d }; properly designing , maintaining these interfaces can challenging though.
in case operate render driver dependent objects textures, can use factory pattern have separate renderers each create own implementation of e.g. itexture using factory method in irenderer:
class irenderer { //... virtual itexture* createtexture(const char* filename) = 0; //... }; class copenglrenderer : public irenderer { //... virtual itexture* createtexture(const char* filename) { // copengltexture opengl specific itexture implementation return new copengltexture(filename); } //... }; isn't idea @ existing (3d) engines though? in experience designing kind of interfaces distracts want make :)
Comments
Post a Comment