5

我们正在 Nexus 10 上使用 OpenGL ES 2.0 开发动态壁纸。

动态壁纸使用 2 个小的 (128x128) 外部帧缓冲区在它们之间进行乒乓渲染以模糊图像。

虽然这在任何设备上都可以正常工作(即使在老化的摩托罗拉里程碑上),但 Nexus 10 存在一个奇怪的问题。这仅在设备处于横向时才有效。如果设备在任何其他位置(90、180 或 270 度)旋转,则帧缓冲区只有清晰的颜色。我已设置glClearColor为红色,因此可以清楚地看到这些帧缓冲区已清除但没有渲染到其中。

我已经在Tegra 2、Tegra 3、Adreno 200、Adreno 320、2 PowerVR GPU 上对其进行了测试,它运行良好。

这看起来像是一些奇怪的驱动程序错误,但也可能是 Mali 驱动程序的一些细节。请指教。

代码摘录。

初始化帧缓冲区:

private void initBloomStuff() {
    mBloomTextureID = loadTexture("textures/empty128.png");
    mBloomVertTextureID = loadTexture("textures/empty128.png");

    mBloomFBHeight = 128;
    mBloomFBWidth = 128;

    float blurSize = 1.0f;

    // Texel offset for blur filter kernel
    m_fTexelOffset = 1.0f / mBloomFBWidth / blurSize;

    ByteBuffer tmpFB, tmpRB;
    IntBuffer handle, renderbuffers;
    int result;

    tmpFB = ByteBuffer.allocateDirect(4);
    tmpFB.order(ByteOrder.nativeOrder());
    handle = tmpFB.asIntBuffer();
    GLES20.glGenFramebuffers(1, handle);
    framebufferHandle = handle.get(0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mBloomTextureID);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebufferHandle);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, mBloomTextureID, 0);

    checkGlError("FB 1");
    tmpRB = ByteBuffer.allocateDirect(4);
    renderbuffers = tmpRB.asIntBuffer();
    GLES20.glGenRenderbuffers(1, renderbuffers);
    checkGlError("FB 1 - glGenRenderbuffers");
    depthbufferHandle = renderbuffers.get(0);
    GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthbufferHandle);
    checkGlError("FB 1 - glBindRenderbuffer");
    GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, mBloomFBWidth, mBloomFBHeight);
    checkGlError("FB 1 - glRenderbufferStorage");
    GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthbufferHandle);
    checkGlError("FB 1 - glFramebufferRenderbuffer");

    result = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
    if (result != GLES20.GL_FRAMEBUFFER_COMPLETE) {
        Log.d(TAG, "Error creating framebufer 1: " + result);
    } else {
        Log.d(TAG, "Created framebufer 1: " + result);
    }

    GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

    tmpFB = ByteBuffer.allocateDirect(4);
    tmpFB.order(ByteOrder.nativeOrder());
    handle = tmpFB.asIntBuffer();
    GLES20.glGenFramebuffers(1, handle);
    framebufferVertHandle = handle.get(0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mBloomVertTextureID);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebufferVertHandle);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, mBloomVertTextureID, 0);

    checkGlError("FB 2");
    tmpRB = ByteBuffer.allocateDirect(4);
    renderbuffers = tmpRB.asIntBuffer();
    GLES20.glGenRenderbuffers(1, renderbuffers);
    checkGlError("FB 2 - glGenRenderbuffers");
    depthbufferVertHandle = renderbuffers.get(0);
    GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthbufferVertHandle);
    checkGlError("FB 2 - glBindRenderbuffer");
    GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, mBloomFBWidth, mBloomFBHeight);
    checkGlError("FB 2 - glRenderbufferStorage");
    GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthbufferVertHandle);
    checkGlError("FB 2 - glFramebufferRenderbuffer");

    result = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
    if (result != GLES20.GL_FRAMEBUFFER_COMPLETE) {
        Log.d(TAG, "Error creating framebufer 2: " + result);
    } else {
        Log.d(TAG, "Created framebufer 2: " + result);
    }

    GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

    mTriangleVerticesVignette = ByteBuffer.allocateDirect(mQuadTriangles.length * FLOAT_SIZE_BYTES).order(ByteOrder.nativeOrder()).asFloatBuffer();
    mTriangleVerticesVignette.put(mQuadTriangles).position(0);
}

渲染到 FB:

    GLES20.glUseProgram(mProgram);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mStemTextureID);
    drawBird();
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mSphereTextureID);
    drawSphere();

    GLES20.glViewport(0, 0, mBloomFBWidth, mBloomFBHeight);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebufferHandle);
    // GLES20.glBindRenderbuffer(GLES20.GL_FRAMEBUFFER, depthbufferHandle);

    GLES20.glClearColor(1.0f, 0.5f, 0.5f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mStemTextureID);
    drawBird();
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mSphereTextureID);
    drawSphere();

    GLES20.glViewport(0, 0, screenWidth, screenHeight);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    // GLES20.glBindRenderbuffer(GLES20.GL_FRAMEBUFFER, 0); 

在 2 个 FB 之间进行乒乓渲染以模糊图像:

    GLES20.glUseProgram(mBloomProgram);
    GLES20.glUniform1i(mBloom_sTexture, 0);
    GLES20.glUniform1f(mBloom_bloomFactor, 0.8f);

    GLES20.glActiveTexture(GL10.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mBloomTextureID);
    GLES20.glViewport(0, 0, mBloomFBWidth, mBloomFBHeight);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebufferVertHandle);
    GLES20.glUniform1f(mBloom_TexelOffsetX, m_fTexelOffset);
    GLES20.glUniform1f(mBloom_TexelOffsetY, 0.0f);
    GLES20.glActiveTexture(GL10.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mBloomTextureID);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    drawBloom();
    GLES20.glViewport(0, 0, screenWidth, screenHeight);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

    GLES20.glActiveTexture(GL10.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mBloomVertTextureID);
    GLES20.glViewport(0, 0, mBloomFBWidth, mBloomFBHeight);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebufferHandle);
    GLES20.glUniform1f(mBloom_TexelOffsetX, 0.0f);
    GLES20.glUniform1f(mBloom_TexelOffsetY, m_fTexelOffset);
    GLES20.glActiveTexture(GL10.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mBloomVertTextureID);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    drawBloom();
    GLES20.glViewport(0, 0, screenWidth, screenHeight);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

    GLES20.glActiveTexture(GL10.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mBloomTextureID);
    GLES20.glViewport(0, 0, mBloomFBWidth, mBloomFBHeight);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebufferVertHandle);
    GLES20.glUniform1f(mBloom_TexelOffsetX, m_fTexelOffset / 2);
    GLES20.glUniform1f(mBloom_TexelOffsetY, m_fTexelOffset / 2);
    GLES20.glActiveTexture(GL10.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mBloomTextureID);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    drawBloom();
    GLES20.glViewport(0, 0, screenWidth, screenHeight);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); 

测试应用程序以重现错误

您可以在此处下载测试 APK:https ://dl.dropboxusercontent.com/u/7197208/LiveWallpaperAnimTest.apk 这是一个动态壁纸应用程序,安装它并选择“测试”动态壁纸(带有玫瑰图标)。

如您所见,在默认的横向方向下,您会看到鸟周围的一些“绽放”效果,这是通过 2 个帧缓冲区之间的乒乓渲染实现的。在任何其他设备方向上,它都不起作用并用清晰的颜色(红色)填充 FB。

附加链接

我也将此问题发布到Mali Developer CenterGoogle Code

http://forums.arm.com/index.php?/topic/16894-nexus-10-render-to-external-rendertarget-works-only-in-landscape/

http://code.google.com/p/android/issues/detail?id=57391

4

1 回答 1

1

Mali 驱动程序支持团队确认这是一个驱动程序错误,并将在下一个驱动程序版本中修复它。作为一种临时解决方法,他们建议glViewportglBindFramebuffer. 此解决方法有效 - 在更改调用顺序后,我设法实现了正确的渲染。

我建议谷歌联系 ARM,以便在固定驱动程序可用后尽快为 Nexus 10 提供一个固定的 OpenGL ES 驱动程序。如果有人愿意让这种情况更快发生,您可以在 Android 错误跟踪器中为问题加注星标:http ://code.google.com/p/android/issues/detail?id=57391

链接到我提交此问题的 Mali 开发者中心论坛: http ://forums.arm.com/index.php?/topic/16894-nexus-10-render-to-external-rendertarget-works-only-in -景观/

由于此驱动程序错误已由 ARM 验证和确认,请前往Android 问题 #57391 加注星标,而不是为这个 SO 问题投票。希望这将迫使谷歌关注问题并发布固件更新,使 Nexus 10 变得更好。这就是我为这个问题分配赏金的原因。

编辑。此错误最终在 Android 4.4 中得到修复。

于 2013-07-13T12:58:43.360 回答