Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse images #956

Open
Deirel opened this issue Apr 6, 2017 · 2 comments
Open

Reuse images #956

Deirel opened this issue Apr 6, 2017 · 2 comments
Labels

Comments

@Deirel
Copy link

Deirel commented Apr 6, 2017

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?

@PrimaryFeather
Copy link
Contributor

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?

@johncridges
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants