OpenGL ES does not destroy contexts or surfaces during orientation changes. The View
hierarchy does do this; GLSurfaceView
is particularly fond of releasing everything it can find.
The onSurfaceCreated()
callbacks are associated with Surfaces
and Views
. When the orientation changes you go through the activity lifecycle events, which tear down the View
, and they in turn tear down the Surface
. If this didn't happen, and you continued to render into the same Surface
, then everything you did would appear to be rotated 90 degrees. (Remember, SurfaceView
surfaces are sent directly to the system compositor, not composited with the UI by the application.)
The usual practice is just to let everything get torn down and then build it back up again.
If this doesn't work for some reason, I would recommend that you do your rendering off-screen and then blit the texture to the current surface. You can see an example of this in Grafika's "Double decode" activity, which renders into a pair of SurfaceTextures
that it connects (and re-connects) to a pair of TextureViews
. Another way to do the same thing would be to create an FBO, render into that, and blit that to your SurfaceView
(you can see an example of FBO setup / blit in Grafika's "Record GL app" activity).