Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android textureView与OpenGL结合中的问题_Android_Opengl Es_Textureview - Fatal编程技术网

Android textureView与OpenGL结合中的问题

Android textureView与OpenGL结合中的问题,android,opengl-es,textureview,Android,Opengl Es,Textureview,目前我正在尝试使用textureView和OpenGL,我的目标是从SurfaceTexture读取缓冲区。经过大量的搜索,我找到了,但是没有找到一个使用textureview的合适的例子 我尝试的是创建一个纹理并尝试设置textureView以使用它: @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(null); getWindow().addFla

目前我正在尝试使用textureView和OpenGL,我的目标是从SurfaceTexture读取缓冲区。经过大量的搜索,我找到了,但是没有找到一个使用textureview的合适的例子

我尝试的是创建一个纹理并尝试设置textureView以使用它:

    @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;
}
但这让我意识到了一个错误:

GLConsumer已附加到上下文

我也发现了,但是在我尝试了这里描述的方法之后,我从glReadPixels得到的是完全黑色的,所以我想必须将surfaceTexture附加到GLcontext才能读取像素

谁能给我一些帮助吗?

你应该看看这个

本例使用surfaceView,只需替换为textureView

386行:“mDisplaySurface=newwindowsurface(mEglCore,holder.getSurface(),false);” 只需使用textureView中的surfacetexture替换holder.getSurface()

还有一种读取缓冲区的方法


请查看保存框方法。

谢谢您的回答!通过surfacetexture,我需要自己创建一个还是使用textureview自动创建的一个?如果我使用textureview自动创建的纹理id,我如何获得surfacetexture绑定到的纹理id,以便我可以在windowsurface上绘制框架?(另外,我查看了android sdk,发现surfacetexture在创建时没有绑定到任何GLcontext),如果我使用我在代码中创建的纹理id,会有我提到的错误,但它不起作用。?你的演示不正确。正确的方法是:1、使用textureView中的surfacetexture创建屏幕窗口曲面2。使用oes纹理3创建另一个surfacetexture。将摄影机绑定到新的surfacetexture,这样摄影机将为surfacetexture提供帧4。在oes纹理中绘制帧以显示windowsurface。太棒了!!!您完美地解决了我的问题~另外,我还有一个问题,当我尝试直接从窗口表面读取像素时,相机预览速度非常慢,因此我将纹理渲染到偏移屏幕表面,然后它解决了问题,你能告诉我这背后的机制是什么吗?opengl api readPixel会将数据从gpu ram读取到cpu ram,这很慢。因此readPixel将阻止渲染线程,相机预览的fps将减少。如果你想要更平滑的效果,你应该使用从opengl 3.0开始引入的PBO技术。