Start by looking at the "Record GL app with FBO" activity in Grafika. It demonstrates three different ways to do game video recording (well, two that work and one that will work in the future).
You can create an EGL "share group" and put both contexts in it, which is what the Breakout game recorder patch and the Grafika "Show + capture camera" activity do. This gets a bit awkward with GLSurfaceView
because you don't have much control over the context's lifecycle, but if you want to keep the recording state alive during orientation changes and screen-off it works well enough.
The alternative is to recognize that a Surface
is the consumer end of an inter-process buffer queue, and you don't actually need a separate context even though rendering and recording happen in different threads; rather, you just need two instances of EGLSurface
in the same EGLContext
. This is how the "Record GL app with FBO" code works. It's using a plain SurfaceView
to get full control over the EGL context, but you should be able to do something similar with GLSurfaceView
if you're careful with context management.
The activity demonstrates the approach used in Breakout (draw the scene twice), a second technique for rendering to an FBO and then blitting the rendered result, and a third technique that requires glBlitFramebuffer()
from GLES3 and doesn't work on any API 19 device I've tried.