diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index e04de7500..324c39ff9 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -636,13 +636,22 @@ public abstract class PGL { // Frame rendering - protected void clearBackground(float r, float g, float b, float a, boolean depth) { - if (depth) { - clearDepth(1); - clear(PGL.DEPTH_BUFFER_BIT); - } + protected void clearBackground(float r, float g, float b, float a, + boolean depth, boolean stencil) { clearColor(r, g, b, a); - clear(PGL.COLOR_BUFFER_BIT); + if (depth && stencil) { + clearDepth(1); + clearStencil(0); + clear(DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT); + } else if (depth) { + clearDepth(1); + clear(DEPTH_BUFFER_BIT | COLOR_BUFFER_BIT); + } else if (stencil) { + clearStencil(0); + clear(STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT); + } else { + clear(PGL.COLOR_BUFFER_BIT); + } if (0 < sketch.frameCount) { clearColor = true; } diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index a1fc96f2b..8ed8d36cd 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -5325,7 +5325,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void backgroundImpl() { flush(); pgl.clearBackground(backgroundR, backgroundG, backgroundB, backgroundA, - !hints[DISABLE_DEPTH_MASK]); + !hints[DISABLE_DEPTH_MASK], true); loaded = false; } @@ -6888,12 +6888,6 @@ public class PGraphicsOpenGL extends PGraphics { normalX = normalY = 0; normalZ = 1; - // Clear depth and stencil buffers. - pgl.depthMask(true); - pgl.clearDepth(1); - pgl.clearStencil(0); - pgl.clear(PGL.DEPTH_BUFFER_BIT | PGL.STENCIL_BUFFER_BIT); - if (hints[DISABLE_DEPTH_MASK]) { pgl.depthMask(false); } else {