Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy a texture in a OpenGL context to another context

I'm trying to record a video using MediaCodec on Android using OpenGL ES 2 contexts.

To do this, I want to use a recordable surface using:

private static final int EGL_RECORDABLE_ANDROID = 0x3142;

to create a new context. Actually, I'm rending a scene in a texture in my First context. And I want to render it in the new context to send the data to MediaCodec.

I'm trying do the same as this breakout tutorial with the Recording patch

I have implemented in my game the InputSurface and GameRecorder, but I only record an empty scene.

My main problem is, the context don't share same OpenGL's objects, and I don't know the best solution to do this.

How could I send the final image render, or the whole scene to render in the same thread to avoid threading problems, to record the surface correctly?

like image 462
vgonisanz Avatar asked Feb 10 '14 11:02

vgonisanz


1 Answers

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.

like image 139
fadden Avatar answered Oct 11 '22 17:10

fadden