From 3b122b9f674f36c326f769176860cffec76d3b95 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 20 Jun 2012 18:29:05 +0000 Subject: [PATCH] splitting the glClear() calls for each buffer (color, stencil, depth) --- .../src/processing/opengl/FrameBuffer.java | 6 +++++- android/core/src/processing/opengl/PGL.java | 10 ++++++++++ .../src/processing/opengl/PGraphicsOpenGL.java | 18 +++++++++++++----- .../src/processing/opengl/FrameBuffer.java | 6 +++++- .../opengl/src/processing/opengl/PGL.java | 18 ++++++++++++++++-- .../src/processing/opengl/PGraphicsOpenGL.java | 18 +++++++++++++----- 6 files changed, 62 insertions(+), 14 deletions(-) diff --git a/android/core/src/processing/opengl/FrameBuffer.java b/android/core/src/processing/opengl/FrameBuffer.java index d59acec18..75e95fd4b 100644 --- a/android/core/src/processing/opengl/FrameBuffer.java +++ b/android/core/src/processing/opengl/FrameBuffer.java @@ -166,8 +166,12 @@ public class FrameBuffer implements PConstants { public void clear() { pg.pushFramebuffer(); pg.setFramebuffer(this); + pgl.glClearDepth(1); + pgl.glClear(PGL.GL_DEPTH_BUFFER_BIT); + pgl.glClearStencil(0); + pgl.glClear(PGL.GL_STENCIL_BUFFER_BIT); pgl.glClearColor(0, 0, 0, 0); - pgl.glClear(PGL.GL_COLOR_BUFFER_BIT | PGL.GL_DEPTH_BUFFER_BIT | PGL.GL_STENCIL_BUFFER_BIT); + pgl.glClear(PGL.GL_COLOR_BUFFER_BIT); pg.popFramebuffer(); } diff --git a/android/core/src/processing/opengl/PGL.java b/android/core/src/processing/opengl/PGL.java index 7bc5826a4..c73b0787d 100644 --- a/android/core/src/processing/opengl/PGL.java +++ b/android/core/src/processing/opengl/PGL.java @@ -1092,6 +1092,16 @@ public class PGL { } + public void glClearDepth(float d) { + GLES20.glClearDepthf(d); + } + + + public void glClearStencil(int s) { + GLES20.glClearStencil(s); + } + + public void glClearColor(float r, float g, float b, float a) { GLES20.glClearColor(r, g, b, a); } diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index 31f1f4153..f741386e8 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -1425,6 +1425,7 @@ public class PGraphicsOpenGL extends PGraphics { if (primarySurface) { pgl.updatePrimary(); + pgl.glDrawBuffer(PGL.GL_BACK); } else { if (!pgl.initialized) { initOffscreen(); @@ -1555,8 +1556,10 @@ public class PGraphicsOpenGL extends PGraphics { // Clear depth and stencil buffers. pgl.glDepthMask(true); - pgl.glClearColor(0, 0, 0, 0); - pgl.glClear(PGL.GL_DEPTH_BUFFER_BIT | PGL.GL_STENCIL_BUFFER_BIT); + pgl.glClearDepth(1); + pgl.glClear(PGL.GL_DEPTH_BUFFER_BIT); + pgl.glClearStencil(0); + pgl.glClear(PGL.GL_STENCIL_BUFFER_BIT); if (primarySurface) { pgl.beginOnscreenDraw(clearColorBuffer); @@ -1703,6 +1706,8 @@ public class PGraphicsOpenGL extends PGraphics { } else { pgl.glDepthMask(true); } + + pgl.glDrawBuffer(PGL.GL_BACK); } @@ -4642,9 +4647,9 @@ public class PGraphicsOpenGL extends PGraphics { protected void backgroundImpl() { flush(); - + pgl.glDepthMask(true); - pgl.glClearColor(0, 0, 0, 0); + pgl.glClearDepth(1); pgl.glClear(PGL.GL_DEPTH_BUFFER_BIT); if (hints[DISABLE_DEPTH_MASK]) { pgl.glDepthMask(false); @@ -4652,11 +4657,14 @@ public class PGraphicsOpenGL extends PGraphics { pgl.glDepthMask(true); } + pgl.glClearStencil(0); + pgl.glClear(PGL.GL_STENCIL_BUFFER_BIT); + pgl.glClearColor(backgroundR, backgroundG, backgroundB, backgroundA); pgl.glClear(PGL.GL_COLOR_BUFFER_BIT); if (0 < parent.frameCount) { clearColorBuffer = true; - } + } } diff --git a/java/libraries/opengl/src/processing/opengl/FrameBuffer.java b/java/libraries/opengl/src/processing/opengl/FrameBuffer.java index d59acec18..75e95fd4b 100644 --- a/java/libraries/opengl/src/processing/opengl/FrameBuffer.java +++ b/java/libraries/opengl/src/processing/opengl/FrameBuffer.java @@ -166,8 +166,12 @@ public class FrameBuffer implements PConstants { public void clear() { pg.pushFramebuffer(); pg.setFramebuffer(this); + pgl.glClearDepth(1); + pgl.glClear(PGL.GL_DEPTH_BUFFER_BIT); + pgl.glClearStencil(0); + pgl.glClear(PGL.GL_STENCIL_BUFFER_BIT); pgl.glClearColor(0, 0, 0, 0); - pgl.glClear(PGL.GL_COLOR_BUFFER_BIT | PGL.GL_DEPTH_BUFFER_BIT | PGL.GL_STENCIL_BUFFER_BIT); + pgl.glClear(PGL.GL_COLOR_BUFFER_BIT); pg.popFramebuffer(); } diff --git a/java/libraries/opengl/src/processing/opengl/PGL.java b/java/libraries/opengl/src/processing/opengl/PGL.java index 8de64093e..16922f577 100644 --- a/java/libraries/opengl/src/processing/opengl/PGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGL.java @@ -709,8 +709,12 @@ public class PGL { gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); // And finally write the color texture to the screen. - gl.glClearColor(0, 0, 0, 0); - gl.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT); + glClearDepth(1); + glClear(GL_DEPTH_BUFFER_BIT); + glClearStencil(0); + glClear(GL_STENCIL_BUFFER_BIT); + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT); drawTexture(GL.GL_TEXTURE_2D, colorTex[0], fboWidth, fboHeight, 0, 0, pg.width, pg.height, 0, 0, pg.width, pg.height); PGraphicsOpenGL.screenFramebuffer.glFboID = colorFBO[0]; @@ -1277,7 +1281,17 @@ public class PGL { } } + + public void glClearDepth(float d) { + gl.glClearDepthf(d); + } + + public void glClearStencil(int s) { + gl.glClearStencil(s); + } + + public void glClearColor(float r, float g, float b, float a) { gl.glClearColor(r, g, b, a); } diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index 31f1f4153..f741386e8 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -1425,6 +1425,7 @@ public class PGraphicsOpenGL extends PGraphics { if (primarySurface) { pgl.updatePrimary(); + pgl.glDrawBuffer(PGL.GL_BACK); } else { if (!pgl.initialized) { initOffscreen(); @@ -1555,8 +1556,10 @@ public class PGraphicsOpenGL extends PGraphics { // Clear depth and stencil buffers. pgl.glDepthMask(true); - pgl.glClearColor(0, 0, 0, 0); - pgl.glClear(PGL.GL_DEPTH_BUFFER_BIT | PGL.GL_STENCIL_BUFFER_BIT); + pgl.glClearDepth(1); + pgl.glClear(PGL.GL_DEPTH_BUFFER_BIT); + pgl.glClearStencil(0); + pgl.glClear(PGL.GL_STENCIL_BUFFER_BIT); if (primarySurface) { pgl.beginOnscreenDraw(clearColorBuffer); @@ -1703,6 +1706,8 @@ public class PGraphicsOpenGL extends PGraphics { } else { pgl.glDepthMask(true); } + + pgl.glDrawBuffer(PGL.GL_BACK); } @@ -4642,9 +4647,9 @@ public class PGraphicsOpenGL extends PGraphics { protected void backgroundImpl() { flush(); - + pgl.glDepthMask(true); - pgl.glClearColor(0, 0, 0, 0); + pgl.glClearDepth(1); pgl.glClear(PGL.GL_DEPTH_BUFFER_BIT); if (hints[DISABLE_DEPTH_MASK]) { pgl.glDepthMask(false); @@ -4652,11 +4657,14 @@ public class PGraphicsOpenGL extends PGraphics { pgl.glDepthMask(true); } + pgl.glClearStencil(0); + pgl.glClear(PGL.GL_STENCIL_BUFFER_BIT); + pgl.glClearColor(backgroundR, backgroundG, backgroundB, backgroundA); pgl.glClear(PGL.GL_COLOR_BUFFER_BIT); if (0 < parent.frameCount) { clearColorBuffer = true; - } + } }