I just upgrade my app from cocos2dx 2.1.4 to 2.2, but my two CCRenderTexture sprite will become black when the app comes back from background, it doesn’t happen in 2.1.4. I test on Galaxy S3 with OS 4.1.1.
Update1: I then test some phones the problem is still there, the only phone works is Galaxy note 2 on OS 4.1.2, any thoughts?
following is the error info I got:
10-09 17:04:58.402: E/Adreno200-ES20(4020): <qgl2DrvAPI_glFramebufferTexture2D:1282>: GL_INVALID_OPERATION
10-09 17:04:58.452: D/cocos2d-x debug info(4020): OpenGL error 0x0502 in /Users/suyuzhang/Documents/cocos2d-x-2.2.0/projects/RockTheVault/proj.android/…/…/…/cocos2dx/misc_nodes/CCRenderTexture.cpp begin 407
I looked into CCRenderTexture.cpp line 407, it saids
“Certain Qualcomm Andreno gpu’s will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of CCRenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don’t have the same issue with switching frame buffers.”
Not working device is Galaxy S3 T-mobile which has Andreno gpu, the working device is Galaxy note 2 which doesn’t have Andreno gpu.
Then I comment following codes, everything works fine
>checkForGLExtension)>initWithData(data, (CCTexture2DPixelFormat)m_ePixelFormat, powW, powH, CCSizeMake((float)w, (float)h));
m_pTextureCopy = new CCTexture2D;
// — bind a temporary texture so we can clear the render buffer without losing our texture
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTextureCopy->getName(), 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0);
I think there should be a bug somewhere.