www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: kiffa on September 21, 2012, 09:59:10 am

Title: About defaultToKeepPixels
Post by: kiffa 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?
Title: Re: About defaultToKeepPixels
Post by: EgonOlsen 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.
Title: Re: About defaultToKeepPixels
Post by: Thomas. 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...
Title: Re: About defaultToKeepPixels
Post by: EgonOlsen 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.
Title: Re: About defaultToKeepPixels
Post by: Thomas. 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?
Title: Re: About defaultToKeepPixels
Post by: EgonOlsen 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.
Title: Re: About defaultToKeepPixels
Post by: Thomas. 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?
Title: Re: About defaultToKeepPixels
Post by: EgonOlsen 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?
Title: Re: About defaultToKeepPixels
Post by: Thomas. 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...
Title: Re: About defaultToKeepPixels
Post by: EgonOlsen 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.
Title: Re: About defaultToKeepPixels
Post by: Thomas. 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? :)
Title: Re: About defaultToKeepPixels
Post by: EgonOlsen 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"!?
Title: Re: About defaultToKeepPixels
Post by: Thomas. 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.
Title: Re: About defaultToKeepPixels
Post by: EgonOlsen 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.
Title: Re: About defaultToKeepPixels
Post by: Thomas. on October 06, 2012, 10:34:46 pm
I thought this way.
defaultToKeepPixels = true -> GUI textures -> defaultToKeepPixels = false -> objects textures
Title: Re: About defaultToKeepPixels
Post by: EgonOlsen on October 06, 2012, 10:55:50 pm
If you really want the keep the gui textures in memory for whatever reason, then don't flush and use replaceTexture() to reload all other textures instead. That will keep the ids.
Title: Re: About defaultToKeepPixels
Post by: Thomas. on October 06, 2012, 11:35:37 pm
it works ;)
Title: Re: About defaultToKeepPixels
Post by: Thomas. on October 07, 2012, 01:08:55 am
Egon, what means this error? When I simply ignore it (try-catch) textures are loaded and everything works, but it is not right... and it seems method "onSurfaceChanged" is called many times after change context, is it right?
Code: [Select]
10-07 01:02:49.237: E/AndroidRuntime(8963): FATAL EXCEPTION: GLThread 7583
10-07 01:02:49.237: E/AndroidRuntime(8963): java.lang.RuntimeException: [ 1349564569196 ] - ERROR: java.lang.NullPointerException
10-07 01:02:49.237: E/AndroidRuntime(8963): at com.threed.jpct.GLRenderer.rescale32(GLRenderer.java:1061)
10-07 01:02:49.237: E/AndroidRuntime(8963): at com.threed.jpct.GLRenderer.buildMipmap(GLRenderer.java:983)
10-07 01:02:49.237: E/AndroidRuntime(8963): at com.threed.jpct.GLRenderer.convertTexture(GLRenderer.java:935)
10-07 01:02:49.237: E/AndroidRuntime(8963): at com.threed.jpct.GLRenderer.upload(GLRenderer.java:1603)
10-07 01:02:49.237: E/AndroidRuntime(8963): at com.threed.jpct.TextureManager.preWarm(TextureManager.java:297)
10-07 01:02:49.237: E/AndroidRuntime(8963): at cz.chladek.mygame.util.TextureLoader.loadTextures(TextureLoader.java:149)
10-07 01:02:49.237: E/AndroidRuntime(8963): at cz.chladek.mygame.AppActivity$MyRenderer.onSurfaceCreated(AppActivity.java:525)
10-07 01:02:49.237: E/AndroidRuntime(8963): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494)
10-07 01:02:49.237: E/AndroidRuntime(8963): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
10-07 01:02:49.237: E/AndroidRuntime(8963): at com.threed.jpct.Logger.log(Logger.java:189)
10-07 01:02:49.237: E/AndroidRuntime(8963): at com.threed.jpct.Logger.log(Logger.java:136)
10-07 01:02:49.237: E/AndroidRuntime(8963): at cz.chladek.mygame.util.TextureLoader.loadTextures(TextureLoader.java:154)
10-07 01:02:49.237: E/AndroidRuntime(8963): at cz.chladek.mygame.AppActivity$MyRenderer.onSurfaceCreated(AppActivity.java:525)
10-07 01:02:49.237: E/AndroidRuntime(8963): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494)
10-07 01:02:49.237: E/AndroidRuntime(8963): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
Title: Re: About defaultToKeepPixels
Post by: EgonOlsen on October 07, 2012, 10:35:42 am
Looks like it tries to create mipmaps for a texture that has no pixels. Maybe you haven't replaced all textures without pixels when calling preWarm().
Title: Re: About defaultToKeepPixels
Post by: Thomas. on October 07, 2012, 10:44:49 am
Yes, I replace one texture and upload it. I can not replace all textures at once, because it causes OutOfMemory error...
Title: Re: About defaultToKeepPixels
Post by: EgonOlsen on October 07, 2012, 04:53:49 pm
I see...i should simply exclude textures without pixels from the prewarming.
Title: Re: About defaultToKeepPixels
Post by: EgonOlsen on October 07, 2012, 08:25:27 pm
Please try this jar instead: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)
Title: Re: About defaultToKeepPixels
Post by: Thomas. on October 07, 2012, 09:29:33 pm
thanks ;)