Oct 8, 2021, 7:51:14 PM10/8/21
I have two fairly high profile gaming Apps that I ported from iOS to Android with the Marmalade SDK so I could reuse my C++ and OpenGL 1.1 code. Unfortunately, Marmalade went down the toilet several years ago and I'm now in the process of moving these two game over to Android Studio using NDK. I used Google's "native-activity" example from their "native-samples" as a starting point and everything is going surprisingly smoothly. However, whenever my app goes into the background, the OpenGL context gets destroyed and when the app is brought back into the foreground, all my textures have been destroyed too. It sounds like it would be a simple task for me to just re-create all the textures but my code is all over the place and loads textures in various places and it would also be fairly slow to load each asset and convert it to a texture every time the device changed orientation or was brought to the foreground. It looks like Marmalade wrote their own code to save each texture to the device OnPause and recreated it OnResume. That seems like a decent chunk of work so my first question is, does anyone know if there's some code already written somewhere that I can use to save the entire state of the OpenGL context ? I don't need to recreate the exact state of OpenGL when the app is resumed, just need to recreate all the textures. In the meantime, I've modified the native-activity code so it doesn't destroy the context in the "engine_term_display" function and that works. However, my second question is whether this is bad programming practice ? I feel like it is because it seems like the textures would linger in VRAM and affect any other apps that are opened while mine is in the background. However, by some miracle, OpenGL might be written in such a way that when VRAM runs out for another app, my textures would automatically be saved to memory or SD card and restored when my app resumes. Is that wishful thinking ? Thanks !