Reputation: 31
Currently I am trying to work with both textureView and OpenGL, and my target is to read the buffer from SurfaceTexture. After lots of searching, I found grafika, but fail to find a suitable example that using textureview.(and, for some reason I have to use textureView)
What I try was that I created a texture and tried to set the textureView to use it:
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(null);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_textureview);
displayTextureView=(TextureView) findViewById(R.id.camera_textureview);
mEglCore = new EglCore(null, EglCore.FLAG_RECORDABLE);
mOffscreenSurface=new OffscreenSurface(mEglCore,VIDEO_WIDTH,VIDEO_HEIGHT);
mOffscreenSurface.makeCurrent();
mFullFrameBlit = new FullFrameRect(
new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
mTextureId = mFullFrameBlit.createTextureObject();
mCameraTexture = new SurfaceTexture(false);
mCameraTexture.attachToGLContext(mTextureId);
displayTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
displayTextureView.setSurfaceTexture(mCameraTexture);
mHandler = new MainHandler(this);
Initialized=true;
}
But then it gitves me the error:
GLConsumer is already attached to a context
I have also found this, but after I tried the method described here what I got from glReadPixels was totally black, so I guess the surfaceTexture must be attached to GLcontext to read the pixels.
Can anybody give me some help?
Upvotes: 0
Views: 1420
Reputation: 1201
you should refer to this https://github.com/google/grafika/blob/master/app/src/main/java/com/android/grafika/ContinuousCaptureActivity.java
this example use surfaceView , you just need to replace to textureView.
the 386 row:"mDisplaySurface = new WindowSurface(mEglCore, holder.getSurface(), false);" just replace holder.getSurface() with surfacetexture from textureView.
And there is a method to read buffer https://github.com/google/grafika/blob/master/app/src/main/java/com/android/grafika/gles/EglSurfaceBase.java
look at the saveFrame method.
Upvotes: 1