Call openGL functions after onPause()

258 views Asked by At

I have an Android java application that uses OpenGL ES 1.1 and I have encountered the following problem: When the application is minimized, onPause() is called on the activity. At this point I would like to preserve one of the GL textures (that I rendered stuff into) and save it in memory while the openGL context is destroyed. Then when the application is resumed I can get my texture back. However retrieving an openGL texture requires GL commands that can only be done by the rendering thread, which may or may not have more rendering iterations just before it is stopped.

Is there a known way to handle this?

1

There are 1 answers

2
ClayMontgomery On

The simplest way to do this in Java is to copy the texture image to an Android Bitmap using glReadPixels(). You would first have to render the texture into the framebuffer, or into a RenderBuffer attached to an FBO. This approach will be slow because glReadPixels() is very slow. Also, the Bitmap class does not handle alpha texture images correctly, unless they are completely opaque. Bitmap converts them to pre-multiplied format.

A better approach would be to use native code which would still have to call glReadPixels(), but could store the image in a normal memory buffer without format conversions.