三维引擎设计-图形窗口封装
来源:互联网 发布:成志网络 编辑:程序博客网 时间:2024/05/21 02:21
一:概述:
每个操作系统都有自己的图形系统,三维引擎会抽象出一个窗口,然后通过继承的方式,子类分别封装不同平台下面的窗口,另外,三维图形API也支持将内容渲染到其他表面上,比如纹理中,所以三维引擎也会抽象出一个纹理,再通过继承的方式,由子类分别封装不同图形API的纹理。
窗口和纹理,都可以看成一个抽象的画布,接收三维引擎的结果渲染到这个画布上,总体来说,一个抽象的画布,代表抽象的窗口或纹理,不同平台和图形API下的窗口和纹理又子类实现。这是三维引擎封装窗口系统的一种方法。
二:OSG的设计:
1:继承关系:
osg::GraphicsContext(图形系统抽象)
|-osg::GraphicsWindow(窗口及渲染环境抽象)
|-osg::GraphicsWindowFOX()
|-osg::GraphicsWindowWX(WX窗口)
|-osg::GraphicsWindowQt(QT窗口)
|-osg::GraphicsWindowCarbon(MacOS窗口)
|-osg::GraphicsWindowCocoa(Mac OS X窗口)
|-osg::GraphicsWindowIOS(IOS窗口)
|-osg::GraphicsWindowWin32(Win32窗口)
|-osg::GraphicsWindowX11(X11窗口)
|-osg::PixelBufferCarbon(MacOS像素缓存)
|-osg::PixelBufferCocoa(Mac OS X像素缓存)
|-osg::PixelBufferWin32(W32像素缓存)
|-osg::PixelBufferX11(X11像素缓存)
三:OGRE的设计:
1:继承关系:
OgreRenderTarget(抽象画布,接收引擎绘制结果)
|-OgreRenderWindow(抽象窗口)
|-OgreWin32Window
|-OgreGLXWindow
|-OgreAndroidWindow
|-OgreD3D9RenderWindow
|-OgreD3D11RenderWindow
|-OgreEAGL2Window
|-OgreOSXCocoaWindow
|-OgreOSXWindow
|-OgreSDLWindow
|-OgreNaClWindow
|-OgreRenderTexture
|-D3D11RenderTexture
|-D3D9RenderTexture
|-GLESRenderTexture
|-GLES2RenderTexture
四: 窗口封装例子:
#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 void (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;_clientHeight = 0;_handler = NULL;disableRootEvents = 0;}virtual ~Canvas() {}virtual bool createWindow(int winWidth, int winHeight, int winOptions,std::string winTitle = "") =0;virtual void 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 <span><span>TDEngine</span></span> {class CanvasX11: public Canvas {public:Window _win;private:virtual bool initDisplay(void);virtual bool initWindow(void);virtual bool initContext(void);virtual bool userInterrupt(void);public:CanvasX11();virtual ~CanvasX11();virtual bool createWindow(int winWidth, int winHeight, int winOptions,std::string winTitle = "");virtual void mainLoop(void);virtual void registerKeyboardFunc(<span><span>TDEngine</span></span>KeyFunc keyFun);virtual void registerMouseFunc(<span><span>TDEngine</span></span>MouseFunc mouseFunc);virtual void registerDrawFunc(<span><span>TDEngine</span></span>DrawFunc 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);Display* get_xDisplay();private: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
- 三维引擎设计-图形窗口封装
- 三维引擎设计-多线程渲染(平台API基础和封装大致框架)
- 三维引擎设计-渲染层封装(Osg渲染层结构)
- 引擎设计: 三维引擎总体结构
- 图形用户界面设计------窗口
- 小型三维引擎设计实现-设计目标
- 三维引擎设计专题--文字的渲染
- 三维引擎设计专题--大气散射特效
- 3D图形引擎决定三维产业差异化
- 图形引擎体系设计的一些构思
- 小型三维引擎设计实现-地球的渲染方法
- java图形设计,窗口阻塞的问题。
- 三维图形几何变换
- 图形三维变换
- matlab绘制三维图形
- 三维计算机图形
- Matlab--三维图形
- matlab绘制三维图形
- lua 函数回调技巧
- 游标的使用
- python lambda的使用
- android网络判断
- windows下关于telnet功能的回显问题的解决办法
- 三维引擎设计-图形窗口封装
- 我所认识的GNU make(6) -- 如何生成Makefile文件
- JBOSS EAP 6 系列五 Managed domains 管理域最主要的功能是“统一部署,统一配置”
- SzNOI c003 中缀表达式转后缀表达式
- Amr and Pins——圆的旋转
- Android开发之网络请求通信专题(二):基于HttpClient的文件上传下载
- bbb u-boot mmc总线初始化分析
- getApplication、getBaseContext、this之间的区别
- 视图的使用