From e0c085413d848c9af458c510654fb06d4248f02f Mon Sep 17 00:00:00 2001 From: codeanticode Date: Thu, 22 Mar 2012 17:56:22 +0000 Subject: [PATCH] Revised clear-buffer logic --- android/core/src/processing/core/PGL.java | 31 ++++++------------- .../processing/core/PGraphicsAndroid3D.java | 10 ++++-- .../processing/opengl/PGraphicsOpenGL.java | 10 ++++-- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/android/core/src/processing/core/PGL.java b/android/core/src/processing/core/PGL.java index 1bb38d2dc..6daa63997 100644 --- a/android/core/src/processing/core/PGL.java +++ b/android/core/src/processing/core/PGL.java @@ -440,28 +440,14 @@ public class PGL { // Simplest scenario: clear mode means we clear both the color and depth buffers. // No need for saving front color buffer, etc. GLES20.glClearColor(0, 0, 0, 0); - GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); - } else { + GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); + } + + if (!clear) { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo[0]); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, textures[frontTex], 0); - - int status = glCheckFramebufferStatus(PGL.GL_FRAMEBUFFER); - if (status != PGL.GL_FRAMEBUFFER_COMPLETE) { - if (status == PGL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) { - throw new RuntimeException("PFramebuffer: GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT (" + Integer.toHexString(status) + ")"); - } else if (status == PGL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) { - throw new RuntimeException("PFramebuffer: GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT (" + Integer.toHexString(status) + ")"); - } else if (status == PGL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS) { - throw new RuntimeException("PFramebuffer: GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS (" + Integer.toHexString(status) + ")"); - } else if (status == PGL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS) { - throw new RuntimeException("PFramebuffer: GL_FRAMEBUFFER_INCOMPLETE_FORMATS (" + Integer.toHexString(status) + ")"); - } else if (status == PGL.GL_FRAMEBUFFER_UNSUPPORTED) { - throw new RuntimeException("PFramebuffer: GL_FRAMEBUFFER_UNSUPPORTED" + Integer.toHexString(status)); - } else { - throw new RuntimeException("PFramebuffer: unknown framebuffer error (" + Integer.toHexString(status) + ")"); - } - } - + validateFramebuffer(); + // We need to save the color buffer after finishing with the rendering of this frame, // to use is as the background for the next frame ("incremental drawing"). GLES20.glClearColor(0, 0, 0, 0); @@ -469,12 +455,15 @@ public class PGL { if (firstOnscreenFrame) { // No need to draw back color buffer because we are in the first frame. GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); - firstOnscreenFrame = false; } else { // Render previous draw texture as background. drawTexture(GLES20.GL_TEXTURE_2D, textures[backTex], texWidth, texHeight, 0, 0, pg.width, pg.height, 0, 0, pg.width, pg.height); } } + + if (firstOnscreenFrame) { + firstOnscreenFrame = false; + } } diff --git a/android/core/src/processing/core/PGraphicsAndroid3D.java b/android/core/src/processing/core/PGraphicsAndroid3D.java index 347ba3578..5324e2d22 100644 --- a/android/core/src/processing/core/PGraphicsAndroid3D.java +++ b/android/core/src/processing/core/PGraphicsAndroid3D.java @@ -1748,6 +1748,8 @@ public class PGraphicsAndroid3D extends PGraphics { manipulatingCamera = false; + clearColorBuffer = false; + if (fbStack == null) { fbStack = new Stack(); @@ -4352,7 +4354,9 @@ public class PGraphicsAndroid3D extends PGraphics { protected void backgroundImpl(PImage image) { backgroundImpl(); set(0, 0, image); - clearColorBuffer = true; + if (0 < parent.frameCount) { + clearColorBuffer = true; + } } @@ -4371,7 +4375,9 @@ public class PGraphicsAndroid3D extends PGraphics { pgl.glClearColor(backgroundR, backgroundG, backgroundB, 1); pgl.glClear(PGL.GL_COLOR_BUFFER_BIT); - clearColorBuffer = true; + if (0 < parent.frameCount) { + clearColorBuffer = true; + } } diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index be58f55e4..054ba335e 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -1754,6 +1754,8 @@ public class PGraphicsOpenGL extends PGraphics { manipulatingCamera = false; + clearColorBuffer = false; + if (fbStack == null) { fbStack = new Stack(); @@ -4358,7 +4360,9 @@ public class PGraphicsOpenGL extends PGraphics { protected void backgroundImpl(PImage image) { backgroundImpl(); set(0, 0, image); - clearColorBuffer = true; + if (0 < parent.frameCount) { + clearColorBuffer = true; + } } @@ -4377,7 +4381,9 @@ public class PGraphicsOpenGL extends PGraphics { pgl.glClearColor(backgroundR, backgroundG, backgroundB, 1); pgl.glClear(PGL.GL_COLOR_BUFFER_BIT); - clearColorBuffer = true; + if (0 < parent.frameCount) { + clearColorBuffer = true; + } }