I have a simple Android application that displays data with our OpenGL rendering SDK on Android GLSurfaceView . Since we provide the SDK for other users, we need to support all use cases for GLSurfaceViews. Currently, we should be able to rotate the device, recreating all kinds of Android and maintaining the OpenGL context. This comes from a client who needs different layouts in landscape and horizontal modes.
The usual way around this is:
1. Add android:configChanges="orientation|screenSize" to your activity in AndroidManifest.xml and everything will be fine.
This will not work in this case, as it does not recreate representations when rotated. Thus, at the same time, we cannot have different layouts in landscape and horizontal modes.
2. Call GLSurfaceView.onPause() and GLSurfaceView.onResume() from Activity .
Although this is considered good practice, this is not enough because the OpenGL context is destroyed in doing so. Please note that we are still doing this; it just does not solve our problem.
3. Use EGLContextFactory to maintain OpenGL context during rotation.
This is possible and useful, as described in, for example, this answer . This sounds like a hack, but it definitely works. The idea is to simply create an EGLContext if you don't have one, and use it if it exists.
The main problem that we face when using this hack is that the rendering stream is destroyed and recreated when the GLSurfaceView detached and attached to the view hierarchy. It looks like a design by looking at the GLSurfaceView implementation .
In our SDK, we have some Local Store stream associated with the stream, so unexpectedly getting a new rendering stream is not very desirable. We could probably change some state when the visualization flow has changed, but we want to investigate if there are better ways to do this.
So my questions are:
a. Does EGLContextFactory “right” way to manually save an OpenGL context during rotation?
Q. Are there any ways not to destroy and recreate the rendering stream during rotation (without changing the source)?
C. Are there any better / simpler alternatives to achieve rotation with killing / re-creating views while maintaining the OpenGL context and rendering stream?
Additional Information:
- We always call
setPreserveEGLContextOnPause(true); . - There are no problems with the rendering itself, these are just described related problems that are problematic.