title: Reinitialize OpenGL ES 2 window on NativeActivity resume
body: <p>Solved! See update below.</p>
  
  <p>We are porting a large C++ application to Android, and everything is running fine until it comes to pausing and resuming the application. We listen to the APP_CMD_INIT_WINDOW command, and when it comes we reinitialize all the egl-commands to get a surface, context and display. After this point the screen is black. However, if we set a glClearColor after it works like it should, which means that we at least have the window and it can be drawn to. This leads us to believe that there might be something else that isn't reinitialized.</p>
  
  <p>My question is if there are buffers, shader programs or other cached stuff that needs to be cleared and reloaded after resume (or before pause), and suitable ways of testing this. We suspect that it might have to do with our application referencing to old buffers using the old EGL Context, but we have no way of knowing. The application uses plenty of textures and off-screen buffers.</p>
  
  <hr>
  
  <p>UPDATE: As usual, after a week of trying out different things we finally solve it just after creating the post. Here is the solution:</p>
  
  <p>All cached textures, buffers and shaders are connected to the context handle created by EGL. There are several things initialized to create the GL-context, the window surface being one of them. This is the only one that depends on the ANativeWindow object which is destroyed and recreated when pausing and resuming the application. Thus, this is the only one that needs to be recreated.</p>
  
  <p>In short:</p>
  
  <p>Run the eglCreateWindowSurface again after the resume with the new window object as argument.</p>