From c797af0fe9dcf0107bf7df559f865486678861f9 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 24 Oct 2012 10:03:19 +0800 Subject: [PATCH] fixed #1522: CCEGLView class of desktop platforms should override CCEGLViewProtocol::setScissorInPoints. --- cocos2dx/platform/linux/CCEGLView.cpp | 9 +++++++++ cocos2dx/platform/linux/CCEGLView.h | 2 ++ cocos2dx/platform/mac/CCEGLView.h | 1 + cocos2dx/platform/mac/CCEGLView.mm | 10 ++++++++++ cocos2dx/platform/win32/CCEGLView.cpp | 8 ++++++++ cocos2dx/platform/win32/CCEGLView.h | 2 ++ 6 files changed, 32 insertions(+) diff --git a/cocos2dx/platform/linux/CCEGLView.cpp b/cocos2dx/platform/linux/CCEGLView.cpp index 99744d378b..6cabdcb5ac 100644 --- a/cocos2dx/platform/linux/CCEGLView.cpp +++ b/cocos2dx/platform/linux/CCEGLView.cpp @@ -261,6 +261,15 @@ void CCEGLView::setViewPortInPoints(float x , float y , float w , float h) (GLsizei)(h * m_fScaleY * m_fFrameZoomFactor)); } +void CCEGLView::setScissorInPoints(float x , float y , float w , float h) +{ + glScissor((GLint)(x * m_fScaleX * m_fFrameZoomFactor + m_obViewPortRect.origin.x * m_fFrameZoomFactor), + (GLint)(y * m_fScaleY * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor), + (GLsizei)(w * m_fScaleX * m_fFrameZoomFactor), + (GLsizei)(h * m_fScaleY * m_fFrameZoomFactor)); +} + + bool CCEGLView::isOpenGLReady() { return bIsInit; diff --git a/cocos2dx/platform/linux/CCEGLView.h b/cocos2dx/platform/linux/CCEGLView.h index 65cb82f7ff..c65489efdd 100644 --- a/cocos2dx/platform/linux/CCEGLView.h +++ b/cocos2dx/platform/linux/CCEGLView.h @@ -33,6 +33,8 @@ public: */ virtual void setFrameSize(float width, float height); virtual void setViewPortInPoints(float x , float y , float w , float h); + virtual void setScissorInPoints(float x , float y , float w , float h); + /* * Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop. */ diff --git a/cocos2dx/platform/mac/CCEGLView.h b/cocos2dx/platform/mac/CCEGLView.h index c0182b8bbd..3c1708cd82 100755 --- a/cocos2dx/platform/mac/CCEGLView.h +++ b/cocos2dx/platform/mac/CCEGLView.h @@ -49,6 +49,7 @@ public: * Set opengl view port rectangle with points. */ virtual void setViewPortInPoints(float x , float y , float w , float h); + virtual void setScissorInPoints(float x , float y , float w , float h); virtual void setIMEKeyboardState(bool bOpen); virtual void setMultiTouchMask(bool mask); diff --git a/cocos2dx/platform/mac/CCEGLView.mm b/cocos2dx/platform/mac/CCEGLView.mm index 92d22ab021..b098e8a1f8 100755 --- a/cocos2dx/platform/mac/CCEGLView.mm +++ b/cocos2dx/platform/mac/CCEGLView.mm @@ -98,6 +98,16 @@ void CCEGLView::setViewPortInPoints(float x , float y , float w , float h) (GLsizei)(h * m_fScaleY * frameZoomFactor)); } +void CCEGLView::setScissorInPoints(float x , float y , float w , float h) +{ + float frameZoomFactor = [[EAGLView sharedEGLView] frameZoomFactor]; + + glScissor((GLint)(x * m_fScaleX * frameZoomFactor + m_obViewPortRect.origin.x * frameZoomFactor), + (GLint)(y * m_fScaleY * frameZoomFactor + m_obViewPortRect.origin.y * frameZoomFactor), + (GLsizei)(w * m_fScaleX * frameZoomFactor), + (GLsizei)(h * m_fScaleY * frameZoomFactor)); +} + void CCEGLView::setMultiTouchMask(bool mask) { //EAGLView *glView = [EAGLView sharedEGLView]; diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index ed49e15a7b..3dc8a05be3 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -697,6 +697,14 @@ void CCEGLView::setViewPortInPoints(float x , float y , float w , float h) (GLsizei)(h * m_fScaleY * m_fFrameZoomFactor)); } +void CCEGLView::setScissorInPoints(float x , float y , float w , float h) +{ + glScissor((GLint)(x * m_fScaleX * m_fFrameZoomFactor + m_obViewPortRect.origin.x * m_fFrameZoomFactor), + (GLint)(y * m_fScaleY * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor), + (GLsizei)(w * m_fScaleX * m_fFrameZoomFactor), + (GLsizei)(h * m_fScaleY * m_fFrameZoomFactor)); +} + CCEGLView* CCEGLView::sharedOpenGLView() { static CCEGLView* s_pEglView = NULL; diff --git a/cocos2dx/platform/win32/CCEGLView.h b/cocos2dx/platform/win32/CCEGLView.h index 896ac939db..c1c3d475e2 100644 --- a/cocos2dx/platform/win32/CCEGLView.h +++ b/cocos2dx/platform/win32/CCEGLView.h @@ -73,6 +73,8 @@ public: void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook ); virtual void setViewPortInPoints(float x , float y , float w , float h); + virtual void setScissorInPoints(float x , float y , float w , float h); + // static function /** @brief get the shared main open gl window