Reinitializing an OpenGL ES 2 Window in a NativeActivity Application

Solved! See update below.

We port a large application in C ++ to Android, and everything works fine until it comes to pausing and resuming the application. We listen to the APP_CMD_INIT_WINDOW command, and when this happens, we reinitialize all egl commands to get the surface, context, and display. After this point, the screen is black. However, if we set glClearColor after it works as it should, it means that we have at least a window and we can draw it. This makes us think that there may be something else that will not be reinitialized.

My question is whether there are buffers, shader programs, or other cached things that need to be cleaned and reloaded after resuming (or before a pause) and suitable ways to test this. We suspect this may be relevant to our application, referencing old buffers using the old EGL context, but we do not know. The application uses many textures and off-screen buffers.


UPDATE: As usual, after a week of testing various things, we finally solve it immediately after creating the message. Here is the solution:

All cached textures, buffers, and shaders are associated with a context descriptor created by EGL. There are several things that are initialized to create a GL context, and the window surface is one of them. This is the only thing that depends on the ANativeWindow object, which is destroyed and recreated when the application is paused and resumed. Thus, it is the only one to be recreated.

In short:

Run eglCreateWindowSurface again after resuming with a new window object as an argument.

+3
source share
2 answers

All cached textures, buffers, and shaders are associated with a context descriptor created by EGL. There are several things that are initialized to create a GL context, and the window surface is one of them. This is the only thing that depends on the ANativeWindow object, which is destroyed and recreated when the application is paused and resumed. Thus, it is the only one to be recreated.

In short:

Run eglCreateWindowSurface again after resuming with a new window object as an argument.

+4
source

I had to call both eglCreateWindowSurface and eglMakeCurrent while reusing everything else and it worked (android 4.2)

0
source

All Articles