diff --git a/cocos2dx/include/CCRenderTexture.h b/cocos2dx/include/CCRenderTexture.h index 347acc6809..f912510d97 100644 --- a/cocos2dx/include/CCRenderTexture.h +++ b/cocos2dx/include/CCRenderTexture.h @@ -78,13 +78,9 @@ public: /** end is key word of lua, use other name to export to lua. */ inline void endToLua(){ end();}; -#if CC_ENABLE_CACHE_TEXTTURE_DATA - /** ends grabbing for android */ + /** ends grabbing*/ + // para bIsTOCacheTexture the parameter is only used for android to cache the texture void end(bool bIsTOCacheTexture = true); -#else - /** ends grabbing */ - void end(); -#endif /** clears the texture with a color */ void clear(float r, float g, float b, float a); diff --git a/cocos2dx/misc_nodes/CCRenderTexture.cpp b/cocos2dx/misc_nodes/CCRenderTexture.cpp index f5b0b2a536..75fec26a66 100644 --- a/cocos2dx/misc_nodes/CCRenderTexture.cpp +++ b/cocos2dx/misc_nodes/CCRenderTexture.cpp @@ -204,46 +204,36 @@ void CCRenderTexture::beginWithClear(float r, float g, float b, float a) glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); } -#if CC_ENABLE_CACHE_TEXTTURE_DATA - void CCRenderTexture::end(bool bIsTOCacheTexture) - { - ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO); - // Restore the original matrix and viewport - glPopMatrix(); - CCSize size = CCDirector::sharedDirector()->getDisplaySizeInPixels(); - // glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height); - CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, size.width, size.height); - - if (bIsTOCacheTexture) - { - CC_SAFE_DELETE(m_pUITextureImage); - - // to get the rendered texture data - const CCSize& s = m_pTexture->getContentSizeInPixels(); - int tx = (int)s.width; - int ty = (int)s.height; - m_pUITextureImage = new CCImage; - if (true == getUIImageFromBuffer(m_pUITextureImage, 0, 0, tx, ty)) - { - VolatileTexture::addDataTexture(m_pTexture, m_pUITextureImage->getData(), kTexture2DPixelFormat_RGBA8888, s); - } - else - { - CCLOG("Cache rendertexture failed!"); - } - } - } -#else - void CCRenderTexture::end() - { - ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO); - // Restore the original matrix and viewport - glPopMatrix(); - CCSize size = CCDirector::sharedDirector()->getDisplaySizeInPixels(); +void CCRenderTexture::end(bool bIsTOCacheTexture) +{ + ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO); + // Restore the original matrix and viewport + glPopMatrix(); + CCSize size = CCDirector::sharedDirector()->getDisplaySizeInPixels(); // glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height); - CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, size.width, size.height); - } -#endif + CCDirector::sharedDirector()->getOpenGLView()->setViewPortInPoints(0, 0, size.width, size.height); + +#if CC_ENABLE_CACHE_TEXTTURE_DATA + if (bIsTOCacheTexture) + { + CC_SAFE_DELETE(m_pUITextureImage); + + // to get the rendered texture data + const CCSize& s = m_pTexture->getContentSizeInPixels(); + int tx = (int)s.width; + int ty = (int)s.height; + m_pUITextureImage = new CCImage; + if (true == getUIImageFromBuffer(m_pUITextureImage, 0, 0, tx, ty)) + { + VolatileTexture::addDataTexture(m_pTexture, m_pUITextureImage->getData(), kTexture2DPixelFormat_RGBA8888, s); + } + else + { + CCLOG("Cache rendertexture failed!"); + } + } +#endif +} void CCRenderTexture::clear(float r, float g, float b, float a) {