Le Yang wrote:
YoungJae Kwon wrote:
> Dear Le,
> I forgot to mention the cocos2dx version i was using. My codes are based on cocos2dx 0.13-beta.
> I am sorry, but I am not sure how VolatileTexture is implemented in cocos2dx 2.0 version.
> Although I could give you some tips how VolatileTexture works.
> VoltileTexture is required because when android app goes to background, the bind between ‘raw texture data’ and ‘opengl texture id’ which is created by “glTexture2D” function is released.( I don’t know why.)
> All the raw texture data is still there but only ‘binding’ is released.
> So what VolatileTexture do is rebind all the textures which was being used before app went to background.
> Other classes like CCSprite keep only the file path for key to rebind later by VolatileTexture.
> But render texture has no file path property like CCSprite. That’s why addDataTexture function is necessary.
> The raw data which was used to create CCTexture2D inside CCRenderTexture has to be kept for rebinding by VolatileTexture.
So the VoltileTexture keep the data, we just need to rebind the texture id on load, right? I examine the cocos2dx v2.0.1 code again and do some testing. v2.0.1 does that stuff and works fine when tap home button and come back.
But it fails (losing texture) when lock screen and awake. I search the web, it seems to relate to the android GLSurfaceView context issue on pause.
YoungJae, did you have that problem once? How you solve it?
Refer to following codes for CCRenderTexture rebinding.
For CCTextureCache class:
//added by YoungJae Kwon
// below codes are ANDROID ONLY
// rebind frame buffer used by rendertexture
vector keys = m_pRenderTextures~~>allKeys();
for (iter = keys.begin(); iter != keys.end(); iter++)
CCLog(“RenderTexture rebind, key:%s,”,(*iter).c_str());
// remove from volatileTexture cache after rebind
For CCRenderTexture class:// added by YoungJae Kwon
// when app restored from lockscreen in ANDROID, reloaded VolatileTexture should be rebinded to FBO
// generate FBO
// associate texture with FBO
// check if it worked )
GLuint status = ccglCheckFramebufferStatus;
ccBlendFunc tBlendFunc = ;