gpt4 book ai didi

Android OpenGL SurfaceTexture(外部图像)与普通纹理的结合

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:45 27 4
gpt4 key购买 nike

我想将相机预览 SurfaceTexture 与一些覆盖纹理混合。我正在使用这些着色器进行处理:

private final String vss = "attribute vec2 vPosition;\n"
+ "attribute vec2 vTexCoord;\n"
+ "varying vec2 texCoord;\n"
+ "void main() {\n"
+ " texCoord = vTexCoord;\n"
+ " gl_Position = vec4 ( vPosition.x, vPosition.y, 0.0, 1.0 );\n"
+ "}";

private final String fss = "#extension GL_OES_EGL_image_external : require\n"
+ "precision mediump float;\n"
+ "uniform samplerExternalOES sTexture;\n"
+ "uniform sampler2D filterTexture;\n"
+ "varying vec2 texCoord;\n"
+ "void main() {\n"
+" vec4 t_camera = texture2D(sTexture,texCoord);\n"
//+" vec4 t_overlayer = texture2D(filterTexture, texCoord);\n"
//+ " gl_FragColor = t_overlayer;\n" + "}";
+ " gl_FragColor = t_camera;\n" + "}";

我的目标是混合使用 t_camerat_overlayer。当我分别显示 t_camerat_overlayer 时,它起作用了(显示相机预览或纹理)。但是,当我取消注释 t_overlayer 时,t_camera 会变成黑色(采样率不佳)。我的覆盖层纹理是 512x512 和 CLAMPT_TO_EDGE。此问题仅在以下示例中发生:Android Emulator、HTC Evo 3D。但在 SGS3、HTC One X 上,它工作得很好。

怎么了?是 Evo 3D 缺少某些扩展还是什么?

最佳答案

我想您遇到这个问题是因为您没有在代码中设置正确的纹理 ID。这是一个典型的假设错误,看似合乎逻辑,但实际上文档中并未如此定义。如果您查看此扩展的文档,您会看到以下(编辑过的)文本:

Each TEXTURE_EXTERNAL_OES texture object may require up to 3 texture image units for each texture unit to which it is bound. When is set to TEXTURE_EXTERNAL_OES this value will be between 1 and 3 (inclusive). For other valid texture targets this value will always be 1. Note that, when a TEXTURE_EXTERNAL_OES texture object is bound, the number of texture image units required by a single texture unit may be 1, 2, or 3, while for other texture objects each texture unit requires exactly 1 texture image unit.

这意味着至少还有一个可以工作,前提是您使用 id 0。在你的情况下:

GLES20.glUniform1i(sTextureHandle, 1);
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
sTextureId);

对于您的 2D 纹理:

GLES20.glUniform1i(filterTextureHandle, 0);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, filterTextureID);

我相信这会适合你。

关于Android OpenGL SurfaceTexture(外部图像)与普通纹理的结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13376254/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com