Jesteśmy rozwija żywo tapety z OpenGL ES 2.0 na Nexus 10.Nexus 10 - renderowanie do zewnętrznego rendertarget działa tylko w krajobrazie
żywo tapety wykorzystuje 2 małe (128x128) do bufora ramki zewnętrzne renderowania ping-ponga między nimi aby rozmazać obraz.
Podczas gdy działa to doskonale na każdym urządzeniu (nawet w starszym Motorola Milestone), istnieje dziwny problem z Nexusem 10. Działa to tylko wtedy, gdy urządzenie znajduje się w orientacji poziomej. Jeśli urządzenie jest obracane w dowolnej innej pozycji (90, 180 lub 270 stopni), bufory ramki mają tylko wyraźny kolor. Ustawiłem glClearColor
na czerwony, aby było wyraźnie widoczne, że te bufory ramki są wyczyszczone, ale nic nie jest w nich renderowane.
Testowałem go na procesorach Tegra 2, Tegra 3, Adreno 200, Adreno 320, 2 PowerVR i działa dobrze.
Wygląda to na dziwny błąd sterownika, ale może to być także specyfika sterownika Mali. Proszę o poradę.
Fragmenty kodu.
Init bufora ramki:
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);
}
oddać 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);
renderowania Ping-pong między 2 FB aby rozmyć obraz:
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);
aplikację testową do odtworzenia błędu
Możesz pobrać test APK tutaj: https://dl.dropboxusercontent.com/u/7197208/LiveWallpaperAnimTest.apk Jest to aplikacja na żywo tapety, zainstalować i wybierz "Test" na żywo tapety (ma ikonę z różą).
Jak widać, w domyślnej orientacji poziomej zobaczysz efekt "rozkwitu" wokół ptaka, który jest implementowany przez renderowanie ping-ponga pomiędzy dwoma buforami ramki. W dowolnym innym ustawieniu urządzenia nie działa i wypełnia FB jasnym kolorem (czerwonym).
Dodatkowe odnośniki
mam również wysłane na ten problem Mali Developer Center i Google Code:
http://code.google.com/p/android/issues/detail?id=57391