4

I want to draw on top of a SurfaceTexture that is connected to a Camera via setPreviewTexture. I can get the SurfaceTexture by a SurfaceTextureListener. But if I just try to use eglCreateWindowSurface & eglMakeCurrent it fails due to the surface already being connected.

1) Is it possible to draw on this surface at all? Or does binding it to the camera make it impossible to do that.

2) If it isn't possible. Can the surface be used (or copied) quickly to an OpenGL texture and used in a separate surface? If so how?

3) If not, what would be the fastest way to get the camera preview out of a SurfaceTexture and into OpenGL?

Also note, the code that gave me the failure regarding already being connected was inspired by Romain Guy's post here: http://groups.google.com/group/android-developers/browse_thread/thread/539457146a401cf1

Grimmace
  • 4,021
  • 1
  • 31
  • 25

1 Answers1

6

Yes this is possible, indeed the whole point of a SurfaceTexture. The problem was that I was thinking about them backward. In order to get them to work you need to:

1) Create a texture through OpenGL.
2) Pass this texture to the constructor of new SurfaceTexture.
3) Give this new SurfaceTexture to the camera.
4) Make sure you are using OES_External (see documentation for
details).

My biggest problem was trying to figure out how to do the reverse. That is, create a SurfaceTexture and pass it into OpenGL. But the opposite is the correct way to do it.

Grimmace
  • 4,021
  • 1
  • 31
  • 25
  • 1
    Interesting, thanks. How did you create the EGL context in the first place to create the OpenGL texture? Do you have a GLSurfaceView? Thanks. – user1906 Apr 30 '14 at 01:32
  • Here is where user1906 posts his question, and gets an answer: http://stackoverflow.com/a/23380229/199364 – ToolmakerSteve Jan 06 '17 at 04:00