Danara
Posts: 13
Joined: Mon Dec 31, 2012 8:12 pm
Location: Ottawa Canada

Copy texture to texture

Sat Apr 20, 2013 10:31 pm

My application needs to compare adjacent frames of an MJPEG stream. I am decoding the jpegs via OMX, and each frame is displayed on the screen in GLES via a texture populated by egl_render. I would like to use a shader to subtract each new frame from the one that precedes it, but I can't manage to locate a way to make a copy of the texture without bringing the data back to the arm cpu.

Is there a way to have the GPU make a copy of the texture before it gets overwritten by the next incoming frame? I've tried using glCopyTexImage2D and glCopyTexSubImage2D to grab the texture from the display, but the resulting texture is 100% black. I'm sure that there must be a way to do this, and I could use a hint as to the correct method.

thanks in advance

lb
Posts: 261
Joined: Sat Jan 28, 2012 8:07 pm

Re: Copy texture to texture

Mon Apr 22, 2013 1:11 pm

I'm not sure if it is the most efficient way, but this certainly works and should be much faster than going through host memory:

1. Create an FBO and attach destination texture as color buffer
2. Render into the FBO with suitable shader and source texture

You might be able to combine this with the mixing step in the fragment shader.

Danara
Posts: 13
Joined: Mon Dec 31, 2012 8:12 pm
Location: Ottawa Canada

Re: Copy texture to texture

Mon Apr 22, 2013 2:44 pm

Thanks! I'll try that method soon, and see how it compares to what I'm doing now, which is to copy the area I want using glReadPixels, and then use that buffer as a texture. I was expecting poor performance with this, but on the RPi, it actually performed quite well. Perhaps this is due to DMA and the shared memory architecture on the RPi, but this seems to execute very quickly, and take very little CPU. (640 x 480 in RGBA @ 12 fps uses about 4% CPU. The one downside was that for some reason, the process turns the image upside down, but this was easy to fix by swapping my texture coordinates.

Return to “OpenGLES”