iblis
iblis

Reputation: 199

Android Activity lifecycle and OpenGL ES 2.0 (VBOs, Shaders,..)

Could you describe me when I should recreate vbos, shaders, textures? I know that OpenGL functions are called in separated thread. I call GLSurfaceView's method onResume in Activity's onResume (the same with onPause method). When the GLContext is lost? Let's assume that the user touch home button. Activity's onPause method is called. Should I delete vbo, shaders, textures? Or should I delete those resources when onDestroy is called (resume GL Thread to delete them?)? What if user touch back button? The another question. Should I keep bitmaps, vertices attributes in Java to reinit VBOs, Textures? Now I delete all shaders, vbos & textures each time the Activity's onPaused method is called. I send a special event to event queue. In onSurfaceCreated I reinit all resources. It's working but it's not fast & it consumes a lot of memory. Is there a better solution?

Upvotes: 2

Views: 931

Answers (1)

maverick9888
maverick9888

Reputation: 512

As long as you are using GLSurfaceView , dont worry about deletion of OpenGL resources. Everytime user clicks home button / back button the EGL context and all the resources associated with that context (textures,VBOs,shaders) will be deleted. So it is your responsibility to create them in onSurfaceCreated() method. Moreover I dont think deleting resources in onDestroy() will work because there wont be a valid EGL context available there.

Upvotes: 1

Related Questions