表面纹理(外部图像)和普通质地的Andr​​oid OpenGL的组合组合、纹理、质地、图像

2023-09-06 03:00:56 作者:深情而不纠缠

我想混相机preVIEW与表面纹理覆盖一些质感。我使用这些着色器处理:

i would like to mix camera preview SurfaceTexture with some overlay texture. I am using these shaders for processing:

    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分开,它的工作原理(显示相机preVIEW或纹理)。但是,当我取消t_overlayer,然后t_camera变成黑色(在某种程度上严重采样)。我的覆盖层质地512×512和CLAMPT_TO_EDGE。 Android模拟器,HTC EVO 3D:例如只发生此问题。 但在SGS3,HTC One X的,它工作得很好。

My goal is to mix t_camera and t_overlayer. When i show t_camera or t_overlayer separately, it works (showing camera preview or texture). But when i uncomment t_overlayer, then t_camera became black (somehow badly sampled). My overlayer texture is 512x512 and CLAMPT_TO_EDGE. This problem occurs only for example on: Android Emulator, HTC Evo 3D. But on SGS3, HTC One X, it works just fine.

什么是错的?难道EVO 3D缺少一些扩展还是什么?

What is wrong? Is it Evo 3D missing some extension or what?

推荐答案

这是不是一个答案,而是详细阐述了问题 - 也许这会帮助一个OpenGL ES专家,得到这个问题的想法。

This is not an answer, but rather an elaboration of the question - maybe it will help an OpenGl ES expert to get an idea of the problem.

我有用于覆盖3纹理和一个外部的纹理,用于捕捉从媒体播放器的输出。如果我只用外部的纹理,产量预期,由MPlayer的帧。相同的全code正常工作的Nexus4,三星Galaxy S3,S4等(所有设备可​​以使用的Adreno图形处理器,或ARM公司的Mali400)在硬件上的区别是,的Nexus 7采用了NVIDIA的Tegra 3板。

I have 3 textures used for overlay, and one external texture, used to capture output from media player. If I use only external texture, output is as expected, frames from MPlayer. The same full code works fine on Nexus4, Samsung Galaxy S3, S4, etc. (all devices use either adreno gpus, or Arm's Mali400) The difference in hardware is that Nexus 7 uses Nvidia Tegra 3 board.

修改的(是如何解决在我身边)的:

英伟达Tegra 3的要求外纹理采样器被称为与采样中最低的字母顺序命名,同时为Adreno 220似乎都需要相反。另外,T3需要外部纹理一次取样。由于采用了Android 4.3和较新的设备,这些缺陷可能会得到解决。在NVIDIA方面,这是一个错误,早已解决,但Nexus的司机后来才更新。因此,我不得不检查哪些GPU为present,并相应地调整code。

Nvidia Tegra 3 requires that external texture sampler is called with a name with lowest alphabetical ordering among samplers, while Adreno 220 seem to require the reverse. Also, T3 require that external texture is sampled last. With devices using Android 4.3 and newer, these bugs may be solved. On Nvidia side, it was a bug, solved long ago but Nexus drivers were updated only later. So I had to check which gpu was present, and adapt code accordingly.