Author Topic: About defaultToKeepPixels  (Read 2545 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
About defaultToKeepPixels
« on: September 21, 2012, 09:59:10 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: About defaultToKeepPixels
« Reply #1 on: September 21, 2012, 12:30:22 pm »
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: About defaultToKeepPixels
« Reply #2 on: September 21, 2012, 01:59:42 pm »
Context is not changed while rotating the screen if you have line below in your manifest.
Code: [Select]
android:restoreNeedsApplication="true"
edit: How can I back textures after context changes? I tried load all textures, but it causes out of memory error...
« Last Edit: September 21, 2012, 02:20:33 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: About defaultToKeepPixels
« Reply #3 on: September 21, 2012, 05:02:44 pm »
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: About defaultToKeepPixels
« Reply #4 on: September 21, 2012, 06:39:18 pm »
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?
« Last Edit: September 21, 2012, 10:33:51 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: About defaultToKeepPixels
« Reply #5 on: September 22, 2012, 05:24:01 pm »
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: About defaultToKeepPixels
« Reply #6 on: October 06, 2012, 04:55:32 pm »
I want to use "Texture.defaultToKeepPixels(false)" and load all textures after change context myself instead of using Virtualizer. What I need for it?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: About defaultToKeepPixels
« Reply #7 on: October 06, 2012, 08:58:26 pm »
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?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: About defaultToKeepPixels
« Reply #8 on: October 06, 2012, 09:18:08 pm »
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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: About defaultToKeepPixels
« Reply #9 on: October 06, 2012, 09:25:56 pm »
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: About defaultToKeepPixels
« Reply #10 on: October 06, 2012, 10:06:41 pm »
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? :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: About defaultToKeepPixels
« Reply #11 on: October 06, 2012, 10:08:19 pm »
If you call flush, everything will get flushed...i'm not sure what you mean by "Not all textures are flush"!?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: About defaultToKeepPixels
« Reply #12 on: October 06, 2012, 10:23:31 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: About defaultToKeepPixels
« Reply #13 on: October 06, 2012, 10:31:52 pm »
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: About defaultToKeepPixels
« Reply #14 on: October 06, 2012, 10:34:46 pm »
I thought this way.
defaultToKeepPixels = true -> GUI textures -> defaultToKeepPixels = false -> objects textures