Reputation: 23
I'm trying to get my android 2.3 NativeActivity to resume successfully when returning from sleep mode. It's a purely native activity using OpenGL.
I have used android:configChanges="orientation" in the manifest to avoid getting destroyed when entering sleep.
When I receive the APP_CMD_TERM_WINDOW, I unload my GL resources and terminate GL.
The problem appears when I try to initialize GL when I return from sleep mode. When I get the APP_CMD_INIT_WINDOW, and try to init GL as usual, I fail to create a new surface.
eglCreateWindowSurface returns EGL_BAD_MATCH and it's game over...
Any thoughts?
Upvotes: 2
Views: 2809
Reputation: 106
I've found most of the EGL example source code using NativeActivity (NVIDIA, Sony Ericsson), using or not the native-app-glue library, have this issue.
The problem is that, in some devices, the window you get when receiving the APP_CMD_INIT_WINDOW after returning from sleep mode is different than the one you have on initialization. Most of the EGL initializations I've seen in sample code call eglChooseConfig
with a hardcoded attribute array (usually the one suited for the flagship device of that manufacturer).
You should check the format of the window with ANativeWindow_getFormat
and only choose a 565 EGL configuration when the NativeWindow has WINDOW_FORMAT_RGB_565
, in the other cases use a 888 configuration.
You can use two attribute arrays or, even better, you can get all the configurations from eglChooseConfig, use eglGetConfigAttrib
to get the values (depth, stencil, etc.) and seek one that has exactly the values you want. It may not have exactly the depth size or stencil size you specify, but you should be fine with a configuration with bigger stencil or depth buffer.
Upvotes: 5