Android OpenGL结合了SurfaceTexture(外部图像)和普通纹理

概述我想将相机预览SurfaceTexture与一些叠加纹理混合.我正在使用这些着色器进行处理:privatefinalStringvss="attributevec2vPosition;\n"+"attributevec2vTexCoord;\n"+"varyingvec2texCoord;\n"+"voidmain(){\n&quo

我想将相机预览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_camera和t_overlayer.当我单独显示t_camera或t_overlayer时,它可以工作(显示相机预览或纹理).但是当我取消注释t_overlayer时,t_camera变成黑色(不知何故被严重抽样).我的覆盖层纹理是512×512和CLAMPT_TO_EDGE.
此问题仅出现在以下示例:AndroID模拟器,HTC Evo 3D.
但是在SGS3,HTC One X上,它运行得很好.@H_404_11@

怎么了?是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(外部图像)和普通纹理全部内容,希望文章能够帮你解决Android OpenGL结合了SurfaceTexture(外部图像)和普通纹理所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1098726.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存