gpt4 book ai didi

android - Nexus 10 - 渲染到外部渲染目标仅适用于横向

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:16:22 24 4
gpt4 key购买 nike

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

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

虽然这在任何设备上都运行良好(即使在旧的 Motorola Milestone 上),但 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

最佳答案

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

一旦固定驱动程序可用,我已建议 Google 联系 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-landscape/

由于此驱动bug已被ARM验证确认,请您去star Android issue #57391而不是投票给这个 SO 问题。希望这会迫使谷歌关注问题并发布固件更新,让 Nexus 10 变得更好。这就是我为这个问题分配赏金的原因。

编辑。这个错误终于在 Android 4.4 中得到修复。

关于android - Nexus 10 - 渲染到外部渲染目标仅适用于横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17403197/

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