Merge pull request #500 from flyingpacer/renderendcrash

Renderendcrash
This commit is contained in:
minggo 2011-09-05 20:52:50 -07:00
commit 8ccc3321a3
3 changed files with 37 additions and 58 deletions

View File

@ -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 */
void end(bool bIsTOCasheTexture = true);
#else
/** ends grabbing */
void end();
#endif
/** ends grabbing*/
// para bIsTOCacheTexture the parameter is only used for android to cache the texture
void end(bool bIsTOCacheTexture = true);
/** clears the texture with a color */
void clear(float r, float g, float b, float a);
@ -119,7 +115,7 @@ protected:
GLuint m_uFBO;
GLint m_nOldFBO;
CCTexture2D *m_pTexture;
GLubyte *m_pTextureDataBuffer;
CCImage *m_pUITextureImage;
GLenum m_ePixelFormat;
};

View File

@ -42,7 +42,7 @@ CCRenderTexture::CCRenderTexture()
, m_nOldFBO(0)
, m_pTexture(0)
, m_ePixelFormat(kCCTexture2DPixelFormat_RGBA8888)
, m_pTextureDataBuffer(NULL)
, m_pUITextureImage(NULL)
{
}
@ -51,12 +51,7 @@ CCRenderTexture::~CCRenderTexture()
removeAllChildrenWithCleanup(true);
ccglDeleteFramebuffers(1, &m_uFBO);
if (NULL != m_pTextureDataBuffer)
{
delete []m_pTextureDataBuffer;
m_pTextureDataBuffer = NULL;
}
CC_SAFE_DELETE(m_pUITextureImage);
}
CCSprite * CCRenderTexture::getSprite()
@ -209,44 +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 bIsTOCasheTexture)
{
if (bIsTOCasheTexture)
{
if (NULL != m_pTextureDataBuffer)
{
delete []m_pTextureDataBuffer;
m_pTextureDataBuffer = NULL;
}
// to get the rendered texture data
const CCSize& s = m_pTexture->getContentSizeInPixels();
int tx = (int)s.width;
int ty = (int)s.height;
m_pTextureDataBuffer = new GLubyte[tx * ty * 4];
glReadPixels(0,0,tx,ty,GL_RGBA,GL_UNSIGNED_BYTE, m_pTextureDataBuffer);
VolatileTexture::addDataTexture(m_pTexture, m_pTextureDataBuffer, kTexture2DPixelFormat_RGBA8888, s);
}
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);
}
#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)
{
@ -355,8 +342,8 @@ bool CCRenderTexture::getUIImageFromBuffer(CCImage *pImage, int x, int y, int nW
this->begin();
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0,0,nReadBufferWidth,nReadBufferHeight,GL_RGBA,GL_UNSIGNED_BYTE, pTempData);
this->end();
this->end(false);
// to get the actual texture data
// #640 the image read from rendertexture is upseted
for (int i = 0; i < nSavedBufferHeight; ++i)

View File

@ -196,11 +196,7 @@ void RenderTextureTest::ccTouchesMoved(CCSet* touches, CCEvent* event)
}
}
// finish drawing and return context back to the screen
#if CC_ENABLE_CACHE_TEXTTURE_DATA
m_target->end(false);
#else
m_target->end();
#endif
}
void RenderTextureTest::ccTouchesEnded(CCSet* touches, CCEvent* event)