Open Deirel opened 7 years ago
The idea is more or less to "hibernate" a texture, which means that it's going to be purged from memory until the moment a display object needs it again (at which time it would be restored from its original source, just like after a context loss). Is that correct?
We do this in our project. We "hide" the textures (by disposing the base) to free the GPU memory and as long as you don't try to render them, you're OK. When we want to start rendering them again, we "unhide" them. We use the following kludgy code (mTexture is the texture being hidden):
var mTexture:Texture;
var mOnRestoreSaved:Function;
var mIsHiding:Boolean = false;
public function set hiding(val:Boolean):void
{
if (mIsHiding != val) {
if (val) {
mOnRestoreSaved = mTexture.root.onRestore;
mTexture.root.dispose();
}
else {
mTexture.root.onRestore = mOnRestoreSaved;
if (Starling.current.contextValid) {
mTexture.root.onContextCreated();
}
}
mIsHiding = val;
}
}
The kicker is that the ConcreteTexture.onContextCreated method is private and we had to make it public for this to work.
If there is reason to add ability to temporary unload textures from GPU memory and return it back later, to avoid disposing display objects containing Images and make possible its pooling without spending GPU memory?