Skip to content

Commit a1dcc32

Browse files
committed
coalesce glClear calls, fixes #4694
1 parent 853478a commit a1dcc32

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

core/src/processing/opengl/PGL.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -636,13 +636,22 @@ public boolean insideStopButton(float x, float y) {
636636
// Frame rendering
637637

638638

639-
protected void clearBackground(float r, float g, float b, float a, boolean depth) {
640-
if (depth) {
639+
protected void clearBackground(float r, float g, float b, float a,
640+
boolean depth, boolean stencil) {
641+
clearColor(r, g, b, a);
642+
if (depth && stencil) {
643+
clearDepth(1);
644+
clearStencil(0);
645+
clear(DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT);
646+
} else if (depth) {
641647
clearDepth(1);
642-
clear(PGL.DEPTH_BUFFER_BIT);
648+
clear(DEPTH_BUFFER_BIT | COLOR_BUFFER_BIT);
649+
} else if (stencil) {
650+
clearStencil(0);
651+
clear(STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT);
652+
} else {
653+
clear(PGL.COLOR_BUFFER_BIT);
643654
}
644-
clearColor(r, g, b, a);
645-
clear(PGL.COLOR_BUFFER_BIT);
646655
if (0 < sketch.frameCount) {
647656
clearColor = true;
648657
}

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5325,7 +5325,7 @@ protected void backgroundImpl(PImage image) {
53255325
protected void backgroundImpl() {
53265326
flush();
53275327
pgl.clearBackground(backgroundR, backgroundG, backgroundB, backgroundA,
5328-
!hints[DISABLE_DEPTH_MASK]);
5328+
!hints[DISABLE_DEPTH_MASK], true);
53295329
loaded = false;
53305330
}
53315331

@@ -6888,12 +6888,6 @@ protected void setGLSettings() {
68886888
normalX = normalY = 0;
68896889
normalZ = 1;
68906890

6891-
// Clear depth and stencil buffers.
6892-
pgl.depthMask(true);
6893-
pgl.clearDepth(1);
6894-
pgl.clearStencil(0);
6895-
pgl.clear(PGL.DEPTH_BUFFER_BIT | PGL.STENCIL_BUFFER_BIT);
6896-
68976891
if (hints[DISABLE_DEPTH_MASK]) {
68986892
pgl.depthMask(false);
68996893
} else {

0 commit comments

Comments
 (0)