From bd93a5cb76d97d4120a92ae96ce6038619315655 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 29 Apr 2014 15:08:44 +0800 Subject: [PATCH 1/3] fix bug for renderTexture created which is bigger than screen size --- cocos/2d/CCRenderTexture.cpp | 28 +++++++++---------- .../RenderTextureTest/RenderTextureTest.cpp | 3 +- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index b2d30f348a..2e8923f94f 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -194,11 +194,12 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat do { _fullRect = _rtTextureRect = Rect(0,0,w,h); - Size size = Director::getInstance()->getWinSizeInPixels(); - _fullviewPort = Rect(0,0,size.width,size.height); + //Size size = Director::getInstance()->getWinSizeInPixels(); + //_fullviewPort = Rect(0,0,size.width,size.height); w = (int)(w * CC_CONTENT_SCALE_FACTOR()); h = (int)(h * CC_CONTENT_SCALE_FACTOR()); - + _fullviewPort = Rect(0,0,w,h); + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO); // textures must be power of two squared @@ -522,7 +523,6 @@ void RenderTexture::onBegin() { // Director *director = Director::getInstance(); - Size size = director->getWinSizeInPixels(); _oldProjMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _projectionMatrix); @@ -533,22 +533,19 @@ void RenderTexture::onBegin() if(!_keepMatrix) { director->setProjection(director->getProjection()); - -#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8 - Matrix modifiedProjection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); - modifiedProjection = CCEGLView::sharedOpenGLView()->getReverseOrientationMatrix() * modifiedProjection; - director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION,modifiedProjection); -#endif - + const Size& texSize = _texture->getContentSizeInPixels(); - + // Calculate the adjustment ratios based on the old and new projections + Size size = Director::getInstance()->getWinSizeInPixels(); float widthRatio = size.width / texSize.width; float heightRatio = size.height / texSize.height; + Matrix orthoMatrix; Matrix::createOrthographicOffCenter((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1, 1, &orthoMatrix); - director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, orthoMatrix); + director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix); } + //calculate viewport { Rect viewport; @@ -695,13 +692,14 @@ void RenderTexture::begin() const Size& texSize = _texture->getContentSizeInPixels(); // Calculate the adjustment ratios based on the old and new projections - Size size = director->getWinSizeInPixels(); + Size size = Director::getInstance()->getWinSizeInPixels(); + float widthRatio = size.width / texSize.width; float heightRatio = size.height / texSize.height; Matrix orthoMatrix; Matrix::createOrthographicOffCenter((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1, 1, &orthoMatrix); - director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, orthoMatrix); + director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix); } _groupCommand.init(_globalZOrder); diff --git a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp index 898f3f06a4..99b991281d 100644 --- a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -408,8 +408,7 @@ void RenderTextureZbuffer::renderScreenShot() { return; } - texture->setAnchorPoint(Vector2(0, 0)); - texture->setKeepMatrix(true); + texture->begin(); this->visit(); From faa0f676443ed77fe19b3de7e0491550b767f57a Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 29 Apr 2014 15:13:24 +0800 Subject: [PATCH 2/3] using pointer instead of Director::getInstance() in RenderTexture --- cocos/2d/CCRenderTexture.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 2e8923f94f..855e2d4290 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -537,7 +537,7 @@ void RenderTexture::onBegin() const Size& texSize = _texture->getContentSizeInPixels(); // Calculate the adjustment ratios based on the old and new projections - Size size = Director::getInstance()->getWinSizeInPixels(); + Size size = director->getWinSizeInPixels(); float widthRatio = size.width / texSize.width; float heightRatio = size.height / texSize.height; @@ -692,7 +692,7 @@ void RenderTexture::begin() const Size& texSize = _texture->getContentSizeInPixels(); // Calculate the adjustment ratios based on the old and new projections - Size size = Director::getInstance()->getWinSizeInPixels(); + Size size = director->getWinSizeInPixels(); float widthRatio = size.width / texSize.width; float heightRatio = size.height / texSize.height; From 331c2d3872d4ec35772bfa8d7cfa5ee7a52d75cc Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 29 Apr 2014 16:03:50 +0800 Subject: [PATCH 3/3] readd wp8 code which is removed by accident --- cocos/2d/CCRenderTexture.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 855e2d4290..f8b3bd3cdc 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -533,7 +533,13 @@ void RenderTexture::onBegin() if(!_keepMatrix) { director->setProjection(director->getProjection()); - + +#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8 + Matrix modifiedProjection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + modifiedProjection = CCEGLView::sharedOpenGLView()->getReverseOrientationMatrix() * modifiedProjection; + director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION,modifiedProjection); +#endif + const Size& texSize = _texture->getContentSizeInPixels(); // Calculate the adjustment ratios based on the old and new projections