【问题标题】:Avoid display of offscreen texture避免显示离屏纹理
【发布时间】:2016-06-22 12:50:31
【问题描述】:

我有一个安卓媒体播放器应用程序。我使用了一个附加到 FBO 的屏幕外纹理,它使用着色器程序 1 并具有屏幕上的纹理 它使用着色器程序 2。

为简单起见,假设我的 shader1 输出红色。 (R = 1)。我的第二个着色器从第一个着色器读取 r 值并使绿色 = 1。 所以实际上我应该得到 r+g = yellow。

我的问题是,在第一瞬间,我得到了红色屏幕(来自屏幕外纹理),然后突然变成黄色。在我的真实场景中,一开始的瞬间红色是一个问题。 有办法解决吗?

函数OnSurfaceChanged:

// 1st texture:

int[] textures = new int[1];
GLES20.glGenTextures(1, textures, 0);
mTexture1 = textures[0];
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexture1);

// 2nd texture

int[] textures2d = new int[1];
GLES20.glGenTextures(1, textures2d, 0);
mTexture2 = textures2d[0];
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture2);

GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA,
                width, height, 0, GLES20.GL_RGBA,
                GLES20.GL_UNSIGNED_BYTE, null);

// FBO
int handle2[] = { 0 };
GLES20.glGenFramebuffers(1, handle2, 0);
mFrameBufferHandle2 = handle2[0];
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBufferHandle2);

GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER,
                GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D,
                mTexture2, 0);

surface1 = new SurfaceTexture(mTexture1);
... pass it to mediaplayer

函数onDrawFrame:

GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

// Shader 1
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBufferHandle2);
GLES20.glViewport(0, 0, mViewportWidth, mViewportHeight);
glUseProgram(shader1);
.....
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexture1);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

// Shader 2
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
GLES20.glViewport(0, 0, mViewportWidth, mViewportHeight);
glUseProgram(shader2);
...
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture2);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

【问题讨论】:

    标签: android opengl-es-2.0 render-to-texture


    【解决方案1】:

    可以通过添加解决它

     GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
     GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
    

    在 GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0) 之后;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-03
      相关资源
      最近更新 更多