Hi every body,
i’m using render texture on some of my games, and have some issues in android version (like other people as i see on this forum).
so i try some “fix” to improve result and i give you what i done to have something work “not so bad”.
first : most of time, most of time i set end(bool) method parameters to false to increase performance (due to image caching), when i need to save the texture to keep it result in case of interrupt app (call, etc), i set end(bool) parameter to true only 1/20 frame, to keep a “recent version” but not saving all version.
second : i add in the render texture destructor a volatile texture removing, i’m not sure but i think without that it create memory leak and “reload all texture” unusefull waste of time. but it’s not 100% sure…
CCRenderTexture::~CCRenderTexture()
{
#if CC_ENABLE_CACHE_TEXTTURE_DATA
if (m_pTexture)
{
VolatileTexture::removeTexture(m_pTexture);
}
#endif
removeAllChildrenWithCleanup(true);
ccglDeleteFramebuffers(1, &m_uFBO);
CC_SAFE_DELETE(m_pUITextureImage);
}
third : to prevent crash or other issue when returning after a call or other interrupt, i add a restoreFB() methods, which delete frame buffers and recreate it. and i call it when i detect interrupt.
bool CCRenderTexture::restoreFB()
{
ccglDeleteFramebuffers(1, &m_uFBO);
glGetIntegerv(CC_GL_FRAMEBUFFER_BINDING, &m_nOldFBO);
// generate FBO
ccglGenFramebuffers(1, &m_uFBO);
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);
// associate texture with FBO
ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0);
// check if it worked (probably worth doing :) )
GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER);
if (status != CC_GL_FRAMEBUFFER_COMPLETE)
{
CCAssert(0, "Render Texture : Could not attach texture to framebuffer");
CC_SAFE_DELETE(m_pTexture);
return false;
}
ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO);
return true;
}
with all that, i have no memory issue, no performance issue and no crash due to render texture (since now )
i will try in near future, to add a “restoreFB” call to the “reload all texture” or somewhere near to make restore FB easier.
i hope that help someone