smart-fun / smartGL

SmartGL is a Graphic Engine for creating Android Games and Apps. It is based on OpenGL and handles 2D Sprites and 3D Textured Objects.
Apache License 2.0
109 stars 24 forks source link

Show SmartGl app from the background running apps, take long time ? #20

Open jehadmashhour opened 5 years ago

jehadmashhour commented 5 years ago

Thanks for this really great library .

After I return to show the SmartGl app from the background running apps list , it takes a lot of time to be shown the application , why & how to solve this issue ?

smart-fun commented 5 years ago

Hello and thank you for your comment !

Basically when the app goes in background, (most of the time) Android releases OpenGL stuff like Textures or Shaders so that other apps can run correctly. When your app comes back to front, you have to rebuild everything and it takes time. In theory you should be able to preload some data and keep them while in background, but it not recommended and probably if you do this and use too much memory Android will delete it anyway.

So smartGL lib behaviour is to unalloc all openGL stuff when going to background and redo the job when going to front.

Regarding optimizations, first try to measure what takes time (for example add Logs and look at the time). If this is the loading of the Objects, perhaps you can try to load them once, and when going back to front, reassign new Textures. Or keep the WavefrontModel, and only call the .toObject() so that the loading / parsing of wavefront is done only once.

If the loading of the texture is too long, maybe they are too big. Or you could keep some bitmaps in memory, and only rebuild a texture from a bitmap in cache.

If you do measure what takes time, please share your results !

thanks,

Arnaud.