Using SurfaceTexture in combination with RenderScript
Asked Answered
G

1

20

I want to do camera image processing on the GPU on android.

In my current set-up I use a SurfaceTexture to capture frames from the camera image stream as an OpenGL ES texture. This is an efficient way to get the camera stream accesible in my shaders. (http://developer.android.com/reference/android/graphics/SurfaceTexture.html)

Now i would like to start using the new RenderScript API instead of direct OenGL ES usage. (http://developer.android.com/guide/topics/renderscript/index.html)

But to create a SurfaceTexture, i need to pass the openGl Texture ID to the constructor. Unfortunately the texture ID is not available (RenderScript uses the Allocation class to load textures, which does not expose the texture ID). So i am not able to create a SurfaceTexture when using RenderScript.

I have read all documentation on renderscript (which is still pretty sparse) and looked at the samples, but they have no information on the subject.

So my question is: Is it possible to use SurfaceTexture in combination with RenderScript, or is there some other efficient way to use the live camera stream in a RenderScript Graphics script?

Gazebo answered 28/3, 2012 at 13:57 Comment(0)
D
1

If I understand correctly, you already use SurfaceTexture. You can then register a callback with setOnFrameAvailableListener.

I see two solutions :

  1. Implements you own RSTextureView, which inherits from SurfaceTexture.OnFrameAvailableListener. Register your view as the SurfaceTexture callback. Every time your surface view is updated by the camera stream, your RSTextureView will be notified and you can handle it the way you want.

  2. Another solution would be to implement your own RenderScriptGL (still inheriting from SurfaceTexture.OnFrameAvailableListener) and call setSurfaceTexture when the callback is called.

You should be able to combine RenderScript with a SurfaceTexture with at least one of these two solutions.

Disaffection answered 25/6, 2012 at 12:54 Comment(1)
I appreciate the answer, but since posting this question i decided to use GLSL for my application. This is because i didn't find an easy way to make it work, and more recently because the renderscript graphics section will be depreciated in 4.1 (Jelly Bean). Therefore i didn't test this aswer myself. So for other followers of this thread: I accept this answer since it seams reasonable, but i did not implement.Gazebo

© 2022 - 2024 — McMap. All rights reserved.