渲染与靶的纹理相机preVIEW GL_TEXTURE_2D [英] Render camera preview on a Texture with target GL_TEXTURE_2D

查看:2307
本文介绍了渲染与靶的纹理相机preVIEW GL_TEXTURE_2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使相机preVIEW上一个OpenGL纹理与目标 GL_TEXTURE_2D 。我非常清楚的表面纹理,而是因为它仅与 GL_TEXTURE_EXTERNAL_OES 的作品,我不能使用它。在表面纹理的文件,它写道:

I'm trying to render the camera preview on an OpenGL Texture with target GL_TEXTURE_2D. I'm very well aware of SurfaceTexture but I cannot use it because it only works with GL_TEXTURE_EXTERNAL_OES. In the documentation of SurfaceTexture, it's written :

 Each time the texture is bound it must be bound to the GL_TEXTURE_EXTERNAL_OES target rather than the GL_TEXTURE_2D target

我不能使用 GL_TEXTURE_EXTERNAL_OES 因为,我将不得不作出了很大的变化在我现有的code。

I cannot use GL_TEXTURE_EXTERNAL_OES because, I'll have to make a lot of changes in my existing code.

有没有办法实现这一目标是快呢?

Is there a way to achieve this which is fast too ?

推荐答案

我能想出的唯一办法是听表面纹理当新的帧来你只是重绘在 GL_TEXTURE_2D 目标。

The only way I can come up with is to listen to the SurfaceTexture and when new frame comes you just redraw it on a GL_TEXTURE_2D target.

当来到OpenGL ES的领域,事情可能会变得非常复杂。让我尝试用我有限的经验来解释这个给你。下面的一些伪code。

When coming to the OpenGL ES field, things can get really complicated. Let me try to explain this to you with my limited experience. Some pseudocode below.


  1. 如果您想渲染相机数据到屏幕外的纹理,你需要一个离屏帧缓冲。有些功能你可能需要。

  1. If you want to render the camera data to a off-screen texture, you'll need a off-screen frame buffer. Some functions you may need.

GLES20.glGenTextures(1, textures, 0);
GLES20.glGenFramebuffers(1, frames, 0);
GLES20.glGenRenderbuffers(1, frameRender, 0);
GLES20.glActiveTexture(ActiveTexture);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA,
            width, height, 0, GLES20.GL_RGBA,
            GLES20.GL_UNSIGNED_BYTE, directIntBuffer);
GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER,
            frameRender[0]);
GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER,
            GLES20.GL_DEPTH_COMPONENT16, width, height);
GLES20.glViewport(0, 0, width, height);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frames[0]);
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER,
            GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D,
            textures[0], 0);
GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER,
            GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER,
            frameRender[0]);


  • 编译你的顶点片段着色器和链接你的程序

  • Compile your vertex and fragment shaders and link your program.

    绑定你的表面纹理从相机到一定GL_TEXTURE

    Bind your SurfaceTexture from camera to a certain GL_TEXTURE

    GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, cameraSurfaceTextureHandle);
    


  • GLES20.glUseProgram(yourProgram),链接上述所有在一起, GLES20.glDrawElements

  • GLES20.glUseProgram(yourProgram), link all the above together, and GLES20.glDrawElements

    这篇关于渲染与靶的纹理相机preVIEW GL_TEXTURE_2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆