One: Overview:
Each operating system has its own graphics system, the three-dimensional engine will be abstracted out of a window, and then through the inheritance of the way, the sub-class separately encapsulates the windows under different platforms, in addition, the three-dimensional graphics API also supports rendering content to other surfaces, such as textures, so the three-dimensional engine will also abstract a texture , and then, by inheritance, the subclasses encapsulate the textures of different graphics APIs , respectively.
Windows and textures, can be seen as an abstract canvas, receiving the results of three-dimensional engine rendering to this canvas, overall, an abstract canvas, representing the abstract window or texture, different platforms and graphics API under the window and texture sub-class implementation. This is a method of the three-dimensional engine package window system.
Two:OSGDesign of:
1: Inheritance relationship:
Osg::graphicscontext ( graphics system Abstraction )
|-osg::graphicswindow (abstract window and rendering environment)
|-osg::graphicswindowfox ()
|-osg::graphicswindowwx (WX window)
|-OSG::GRAPHICSWINDOWQT (QT window)
|-osg::graphicswindowcarbon (MacOS window)
|-osg::graphicswindowcocoa (Mac OS x Window)
|-osg::graphicswindowios (IOS window)
|-osg::graphicswindowwin32 (Win32 window)
|-osg::graphicswindowx11 (X11 window )
|-OSG::P ixelbuffercarbon (MacOS pixel cache )
|-OSG::P Ixelbuffercocoa (Mac OS x pixel cache)
|-OSG::P ixelBufferWin32 (W32 pixel cache )
|-OSG::P ixelBufferX11 (X11 pixel cache )
- Three: The design ofOGRE :
1: Inheritance relationship:
ogrerendertarget(abstract canvas, receiving engine drawing results)
|-ogrerenderwindow(abstract window)
|-ogrewin32window
|-ogreglxwindow
|-ogreandroidwindow
|-ogred3d9renderwindow
|-ogred3d11renderwindow
|-ogreeagl2window
|-ogreosxcocoawindow
|-ogreosxwindow
|-ogresdlwindow
|-ogrenaclwindow
|-ogrerendertexture
|-d3d11rendertexture
|-d3d9rendertexture
|-glesrendertexture
|-gles2rendertexture
Four: Window Encapsulation Example:
#ifndef canvas_h#define canvas_h#include <iostream> #include <string> #define Callback#define es_window_ RGB 0#define es_window_alpha 1#define es_window_depth 2#define es_window_stencil 4#define Es_window_multisample 8namespace tdengine {typedef void (CALLBACK *tdenginekeyfunc) (unsigned char, int, int); typedef voi D (CALLBACK *tdenginemousefunc) (int, int, int, int), typedef void (CALLBACK *tdenginedrawfunc) (), class Canvas {private: virtual bool Initdisplay (void) {return false;} virtual bool Initwindow (void) {return false;} virtual bool Initcontext (void) {return false;} virtual bool UserInterrupt (void) {return false;} Public:canvas () {_width = 0;_height = 0;_flags = 0;_keyfunc = 0;_mousefunc = 0;_drawfunc = 0;_currfps = 0;_frames = 0;_totaltime = 0;_wndtype = 0;_egldisplay = 0;_eglcontext = 0;_eglsurface = 0;_eglconfig = 0;_clientwidth = 0;_clientHei ght = 0;_handler = null;disablerootevents = 0;} Virtual ~canvas () {}virtual bool CreateWindow (int winwidth, int winheight, int winoptions,std::string wintitle = "") =0;virtual Vo ID mainloop (void) {}virtual void Registerkeyboardfunc (Tdenginekeyfunc keyfunc) {}virtual void Registermousefunc ( Tdenginemousefunc mousefunc) {}virtual void Registerdrawfunc (Tdenginedrawfunc drawfunc) {}virtual void AddEventListener (std::string name, Screenactionhandler action,bool bubble) = 0;virtual void RemoveEventListener (std:: String Name,screenactionhandler action, bool bubble) = 0;virtual void Removeeventalllistener () = 0;virtual void fireevents (const std::string& name,eventoption& eventoption) = 0;public:int _width;int _height;int _flags;std::string _ Title Tdenginekeyfunc _keyfunc; Tdenginemousefunc _mousefunc; Tdenginedrawfunc _drawfunc;float _currfps;int _frames;float _totaltime;unsigned long _wndType;void* _eglDisplay;void* _eglcontext;void* _eglsurface;void* _eglconfig;int _clientwidth;int _clientheight; screenspaceeventhandler* _handler;std::map<sTd::string, screenactionhandler> _callbackactionlist;bool disablerootevents;};} #endif//Canvas_h
#ifndef canvasx11_h#define canvasx11_h#include <X11/Xlib.h> #include <X11/Xatom.h> #include <x11/ xutil.h> #include "Canvas.h" #include "ScreenSpaceEventHandler.h" namespace Cesium {class Canvasx11:public Canvas { Public:window _win;private:virtual bool Initdisplay (void); virtual bool Initwindow (void); virtual bool Initcontext (void virtual bool UserInterrupt (void);p ublic:canvasx11 (); virtual ~canvasx11 (); virtual bool CreateWindow (int winwidth, int winheight, int winoptions,std::string wintitle = ""), virtual void mainloop (void), virtual void Registerkeyboardfunc ( Cesiumkeyfunc keyfun); virtual void Registermousefunc (Cesiummousefunc mousefunc); virtual void Registerdrawfunc ( Cesiumdrawfunc drawfunc); virtual void fireevents (const std::string& name, eventoption& eventoption); virtual void AddEventListener (std::string name, Screenactionhandler action,bool bubble); virtual void Removeeventalllistener () {}void RemoveEventListener (std::string name, Screenactionhandler Callback,booL bubble); static void Movemouse (canvas& Canvas, MouseButtons button,const cartesian2& startposition, const cartesian2& Endposition,bool Shiftkey = False);D isplay* get_xdisplay ();p rivate:display* _xdisplay; Window _rootwin;private:typedef screenactionhandler callfunc;typedef std::vector<callfunc> CallFuncList; typedef std::map<std::string, callfunclist> callbacks; Callbacks _callbacks;std::vector<callfunc> _keydown;std::vector<callfunc> _mousemove;std::vector< callfunc> _mouseup;std::vector<callfunc> _mousedown;std::vector<callfunc> _dblclick;std::vector <CallFunc> _mousewheel;std::vector<callfunc> _touchstart;std::vector<callfunc> _touchmove;std:: Vector<callfunc> _touchend; S32 _numregistered;bool _disablerootevents;};} #endif//Canvasx11_h
Three-dimensional engine design-graphics window encapsulation