extra logic to make sure that the depth buffer is always clear at the

beginning of a new frame
This commit is contained in:
codeanticode
2016-10-12 16:25:54 -04:00
parent a1dcc32044
commit 8ad3c11f93
2 changed files with 42 additions and 0 deletions
+40
View File
@@ -272,6 +272,13 @@ public abstract class PGL {
protected boolean clearColor = false;
protected boolean pclearColor;
protected boolean clearDepth = false;
protected boolean pclearDepth;
protected boolean clearStencil = false;
protected boolean pclearStencil;
// ........................................................
// Error messages
@@ -636,6 +643,23 @@ public abstract class PGL {
// Frame rendering
protected void clearDepthStencil() {
if (!pclearDepth && !pclearStencil) {
depthMask(true);
clearDepth(1);
clearStencil(0);
clear(DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT);
} else if (!pclearDepth) {
depthMask(true);
clearDepth(1);
clear(DEPTH_BUFFER_BIT);
} else if (!pclearStencil) {
clearStencil(0);
clear(STENCIL_BUFFER_BIT);
}
}
protected void clearBackground(float r, float g, float b, float a,
boolean depth, boolean stencil) {
clearColor(r, g, b, a);
@@ -643,12 +667,22 @@ public abstract class PGL {
clearDepth(1);
clearStencil(0);
clear(DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT);
if (0 < sketch.frameCount) {
clearDepth = true;
clearStencil = true;
}
} else if (depth) {
clearDepth(1);
clear(DEPTH_BUFFER_BIT | COLOR_BUFFER_BIT);
if (0 < sketch.frameCount) {
clearDepth = true;
}
} else if (stencil) {
clearStencil(0);
clear(STENCIL_BUFFER_BIT | COLOR_BUFFER_BIT);
if (0 < sketch.frameCount) {
clearStencil = true;
}
} else {
clear(PGL.COLOR_BUFFER_BIT);
}
@@ -669,6 +703,12 @@ public abstract class PGL {
pclearColor = clearColor;
clearColor = false;
pclearDepth = clearDepth;
clearColor = false;
pclearStencil = clearStencil;
clearStencil = false;
if (SINGLE_BUFFERED && sketch.frameCount == 1) {
restoreFirstFrame();
}
@@ -1645,6 +1645,8 @@ public class PGraphicsOpenGL extends PGraphics {
pgl.activeTexture(PGL.TEXTURE0);
pgl.clearDepthStencil();
if (hints[DISABLE_DEPTH_MASK]) {
pgl.depthMask(false);
} else {