1、CCEGLViewProtocol:Cocos2d-x和openGL间的接口,桥梁
class CC_DLL CCEGLViewProtocol { public: CCEGLViewProtocol(); virtual ~CCEGLViewProtocol();
virtual void end() = 0; //销毁,子类必须继承 virtual bool isOpenGLReady() = 0; //获得GL渲染系统是否已经准备好 virtual void swapBuffers() = 0; //缓冲区交换 virtual void setIMEKeyboardState(bool bOpen) = 0; //设置输入法状态 virtual const CCSize& getFrameSize() const; //窗体大小 virtual void setFrameSize(float width,float height); virtual CCSize getVisibleSize() const; //openGL视口可见区域 virtual CCPoint getVisibleOrigin() const; virtual void setDesignResolutionSize(float width,float height,ResolutionPolicy resolutionPolicy); virtual void setTouchDelegate(EGLTouchDelegate * pDelegate); //设置触摸委派 virtual void setViewPortInPoints(float x,float y,float w,float h); //设置openGL视口矩形 virtual void setScissorInPoints(float x,float h); //设置裁剪矩形 virtual bool isScissorEnabled(); //裁剪相关 virtual CCRect getScissorRect(); virtual void setViewName(const char* pszViewName); //视窗名字 const char* getViewName(); virtual void handleTouchesBegin(int num,int ids[],float xs[],float ys[]); //触摸事件处理 virtual void handleTouchesMove(int num,float ys[]); virtual void handleTouchesEnd(int num,float ys[]); virtual void handleTouchesCancel(int num,float ys[]); const CCRect& getViewPortRect() const; //获取openGL视口矩形 float getScaleX() const; //获得缩放因子 float getScaleY() const; private: void getSetOfTouchesEndOrCancel(CCSet& set,int num,float ys[]); protected: EGLTouchDelegate* m_pDelegate; CCSize m_obScreenSize; CCSize m_obDesignResolutionSize; CCRect m_obViewPortRect; char m_szViewName[50]; float m_fScaleX; float m_fScaleY; ResolutionPolicy m_eResolutionPolicy; };2、CCEGLView:继承自CCEGLViewProtocol,处理openGL方面的工作
class CC_DLL CCEGLView : public CCEGLViewProtocol { public: CCEGLView(); virtual ~CCEGLView(); virtual bool isOpenGLReady(); //以下6个均为重载函数 virtual void end(); virtual void swapBuffers(); virtual void setFrameSize(float width,float height); virtual void setEditorFrameSize(float width,HWND hWnd); virtual void setIMEKeyboardState(bool bOpen); void setMenuResource(LPCWSTR menu); //设置菜单资源 void setWndProc(CUSTOM_WND_PROC proc); //设置消息处理函数 protected: virtual bool Create(); public: bool initGL(); //初始化openGL void destroyGL(); //销毁openGL virtual LRESULT WindowProc(UINT message,WPARAM wParam,LPARAM lParam); //消息处理函数 HWND getHWnd(); //Win32平台,窗体句柄 virtual void resize(int width,int height); void setFrameZoomFactor(float fZoomFactor); float getFrameZoomFactor(); virtual void centerWindow(); typedef void (*LPFN_ACCELEROMETER_KEYHOOK)( UINT message,LPARAM lParam ); void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook ); virtual void setViewPortInPoints(float x,float h); virtual void setScissorInPoints(float x,float h); static CCEGLView* sharedOpenGLView(); //获得实例句柄 protected: static CCEGLView* s_pEglView; bool m_bCaptured; HWND m_hWnd; HDC m_hDC; HGLRC m_hRC; LPFN_ACCELEROMETER_KEYHOOK m_lpfnAccelerometerKeyHook; bool m_bSupportTouch; LPCWSTR m_menu; CUSTOM_WND_PROC m_wndproc; float m_fFrameZoomFactor; };
typedef LRESULT (*CUSTOM_WND_PROC)(UINT message,LPARAM lParam,BOOL* pProcessed);原文链接:https://www.f2er.com/cocos2dx/343825.html