Merge pull request #6512 from dabingnn/v3_renderTextureBug

V3 render texture bug
This commit is contained in:
minggo 2014-04-30 17:52:14 +08:00
commit 2cbbaed5b3
2 changed files with 12 additions and 9 deletions

View File

@ -194,10 +194,11 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat
do do
{ {
_fullRect = _rtTextureRect = Rect(0,0,w,h); _fullRect = _rtTextureRect = Rect(0,0,w,h);
Size size = Director::getInstance()->getWinSizeInPixels(); //Size size = Director::getInstance()->getWinSizeInPixels();
_fullviewPort = Rect(0,0,size.width,size.height); //_fullviewPort = Rect(0,0,size.width,size.height);
w = (int)(w * CC_CONTENT_SCALE_FACTOR()); w = (int)(w * CC_CONTENT_SCALE_FACTOR());
h = (int)(h * CC_CONTENT_SCALE_FACTOR()); h = (int)(h * CC_CONTENT_SCALE_FACTOR());
_fullviewPort = Rect(0,0,w,h);
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO); glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
@ -522,7 +523,6 @@ void RenderTexture::onBegin()
{ {
// //
Director *director = Director::getInstance(); Director *director = Director::getInstance();
Size size = director->getWinSizeInPixels();
_oldProjMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); _oldProjMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _projectionMatrix); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _projectionMatrix);
@ -543,12 +543,15 @@ void RenderTexture::onBegin()
const Size& texSize = _texture->getContentSizeInPixels(); const Size& texSize = _texture->getContentSizeInPixels();
// Calculate the adjustment ratios based on the old and new projections // Calculate the adjustment ratios based on the old and new projections
Size size = director->getWinSizeInPixels();
float widthRatio = size.width / texSize.width; float widthRatio = size.width / texSize.width;
float heightRatio = size.height / texSize.height; float heightRatio = size.height / texSize.height;
Matrix orthoMatrix; Matrix orthoMatrix;
Matrix::createOrthographicOffCenter((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1, 1, &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 //calculate viewport
{ {
Rect viewport; Rect viewport;
@ -696,12 +699,13 @@ void RenderTexture::begin()
// Calculate the adjustment ratios based on the old and new projections // Calculate the adjustment ratios based on the old and new projections
Size size = director->getWinSizeInPixels(); Size size = director->getWinSizeInPixels();
float widthRatio = size.width / texSize.width; float widthRatio = size.width / texSize.width;
float heightRatio = size.height / texSize.height; float heightRatio = size.height / texSize.height;
Matrix orthoMatrix; Matrix orthoMatrix;
Matrix::createOrthographicOffCenter((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1, 1, &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); _groupCommand.init(_globalZOrder);

View File

@ -408,8 +408,7 @@ void RenderTextureZbuffer::renderScreenShot()
{ {
return; return;
} }
texture->setAnchorPoint(Vector2(0, 0));
texture->setKeepMatrix(true);
texture->begin(); texture->begin();
this->visit(); this->visit();