Robinson
Robinson

Reputation: 10132

Managing OpenGL resources on Android

I've got a basic Activity class, which creates a GLSurfaceView and that is passed a class derived from Renderer in its SetRenderer method. Now I'm aware that OpenGL resources can be lost when the phone or tablet goes to sleep (so far, so DirectX 9), and that these resources must be re-created when the phone returns from its sleep state.

Am I right in thinking that all of my other classes, the activity and so on, are restored exactly as they were when it wakes? i.e. I would only have to re-bind things like textures, shaders, GL state and so on in the onSurfaceCreated method. I don't need to recreate the view, or the renderer object.

Does the onSurfaceCreated method get called when the phone wakes, or just once at start-up? Is the GL object I receive in onSurfaceCreated destroyed (i.e. is it safe to store it and use it through a sleep/wake cycle)?

Upvotes: 1

Views: 505

Answers (1)

Wroclai
Wroclai

Reputation: 26925

Am I right in thinking that all of my other classes, the activity and so on, are restored exactly as they were when it wakes?

That depends if the activity has been killed between these "wake-ups". If the activity has not been killed between these pauses, everything of your classes are restored as they were when you leaved your activity.

I would only have to re-bind things like textures, shaders, GL state and so on in the onSurfaceCreated method. I don't need to recreate the view, or the renderer object.

Correct.

Does the onSurfaceCreated method get called when the phone wakes, or just once at startup?

It gets called every time a new surface is created, which means every time your application comes from background into foreground.

Upvotes: 3

Related Questions