www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: raft on December 19, 2013, 09:10:55 am

Title: fast way to get contents of SurfaceTexture?
Post by: raft on December 19, 2013, 09:10:55 am
does anybody now a fast way to get contents of a SurfaceTexture (http://developer.android.com/reference/android/graphics/SurfaceTexture.html)?

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 (http://stackoverflow.com/questions/19366660/how-to-save-surfacetexture-as-bitmap): it says a SurfaceTexture is backed by an external texture (http://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image_external.txt) and that's why its content can not be retrieved in regular ways.
Title: Re: fast way to get contents of SurfaceTexture?
Post by: EgonOlsen 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?
Title: Re: fast way to get contents of SurfaceTexture?
Post by: raft 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.