Author Topic: fast way to get contents of SurfaceTexture?  (Read 6578 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
fast way to get contents of SurfaceTexture?
« on: December 19, 2013, 09:10:55 am »
does anybody now a fast way to get contents of a SurfaceTexture?

SurfaceTexture is a very convenient way to direct Android's Camera or MediaPlayer output to a texture in GLSurfaceView, kind of render to texture. But I also need the pixel data of the surface for further processing and the only way I found is via GLES20.glReadPixels which is infeasably slow. only getting pixels without any processing drops FPS to 4 on a Samsung S3.

Some information here: it says a SurfaceTexture is backed by an external texture and that's why its content can not be retrieved in regular ways.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: fast way to get contents of SurfaceTexture?
« Reply #1 on: December 19, 2013, 01:55:45 pm »
glReadPixels is slow but so is every read operation that has to access data in the gpu's domain. I don't see how this can be done faster. Isn't there another way to get the camera's output? Does it has to be via this SurfaceTexture?

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: fast way to get contents of SurfaceTexture?
« Reply #2 on: December 19, 2013, 02:17:56 pm »
yes there is another way, that is:

* register a preview callback to camera.
* convert byte array provided to callback from YUV to some format that jPCT can handle
* make or update a texture out of that
* blit that texture to frame buffer before any other 3d content

despite the overhead of yuv -> jpeg -> texture -> upload cycle, this runs 40 fps (which is vSynch limit I Suppose) on Samsung S3. I'm just trying to figure an easier way.