About defaultToKeepPixels

Started by kiffa, September 21, 2012, 09:59:10 AM

Previous topic - Next topic

kiffa

If i set defaultToKeepPixels=false; the texture in vm will be free after uploaded to gpu.

And you don't suggest doing like this, because if the OpenGL context change, there will some bad things happen.

Could you explain more? When and how will the OpenGL context change? if  defaultToKeepPixels==false and OpenGL conext changed, what will happen?

EgonOlsen

The context changes if you rotate the screen, pause/resume the app...and in some Android versions even right after startup. Without the pixels, you'll lose textures because they have to be uploaded and bound to the new context. If you are using a Virtualizer, you are not gaining any memory by setting this to false btw.

Thomas.

#2
Context is not changed while rotating the screen if you have line below in your manifest.
android:restoreNeedsApplication="true"

edit: How can I back textures after context changes? I tried load all textures, but it causes out of memory error...

EgonOlsen

You have to flush the TextureManager and load everything from scratch. But it's easier to use the Virtualizer instead. I still don't get what you are doing that eats up all the memory...how large are your assets? If loading the textures causes trouble, then they are either too big, too many...or the rest of the data used is too large.

Thomas.

#4
Ok, I'll try it. If I set "Texture.defaultToKeepPixels = false;" my game has 17MB, otherwise 48MB. All textures are in 1024*1024 (I prefer larger textures, It looks much better in my opinion).

edit: could you tell me what is on the line 2134 in GLRenderer? I have some NullPointerException... But when I think about uploading of new textures, TextureManager.flush() causes a lot of problems in this case. Texture layers is linked by texture id, and this id will be probably completely different in new texture manager... Is there any way how to keep textures out of main memory, but avoid problems when context is changed?

edit2: oh, just two posts before... Virtualizer, it is much, much slower (loading time increased about 50%), but I have much more free VM.

And is possible find how much free GPU memory is?

EgonOlsen

You have to assign the textures again after reloading them. Actually, the option to discard the pixels is there for applications that exit on pause anyway like benchmarks. It's not meant to be used for games except if you want to reload and reassign everything all the time.

No idea about free GPU memory. I don't even know how it is assigned/managed  on Android. It might depend on the GPU as well.

Thomas.

I want to use "Texture.defaultToKeepPixels(false)" and load all textures after change context myself instead of using Virtualizer. What I need for it?

EgonOlsen

Either use replaceTexture to replace them in the TextureManager or flush the TextureManager, reload all the texture and assign them again to your objects. If you don't the objects will still use the old references, which aren't valid anymore. Any particular reason why you want to do this?

Thomas.

Objects are binded to id of textures? Is there any possibility for setter and getter for ids of textures? Reason is two times longer loading time on high-end devices, on "low-end" it is more than 30 seconds on test scene. In my opinion is unnecessary load and save textures. I have to save names and patches of textures due the changing quality of textures during the game, so from my side is easy add id or something...

EgonOlsen

They are bound to the internal ids, not to the gl ids. It may work if you flush the manager and load and add the texture in exactly the same way as before because that should lead to the same ids.

Thomas.

This could be a problem. Not all textures are flush, at least I think so. Before loading GUI textures defaultToKeepPixels is set to true after that set to false. And I'm using auxiliary texture (white point) for menu elements. It would not be impossible to carry out the same way, but wouldn't be easier to just rewrite the internal ids? :)

EgonOlsen

If you call flush, everything will get flushed...i'm not sure what you mean by "Not all textures are flush"!?

Thomas.

Some textures are stored in GPU and also in RAM. One texture is just white point, created in application. Loading all textures exactly in same order would be very confusing and complicated.

EgonOlsen

It doesn't matter. The manager is empty after calling flush and the context is lost anyway. There's no other way than to load them all again, regardless of if they exited system or gpu ram or both before...they are all gone.

Thomas.

I thought this way.
defaultToKeepPixels = true -> GUI textures -> defaultToKeepPixels = false -> objects textures