added check for continuous use of smooth/noSmooth

This commit is contained in:
codeanticode
2012-06-25 14:02:10 +00:00
parent 583a40bfba
commit 9ad3fdd351
2 changed files with 56 additions and 2 deletions
@@ -375,6 +375,11 @@ public class PGraphicsOpenGL extends PGraphics {
/** Used to indicate an OpenGL surface recreation */
protected boolean restoreSurface = false;
/** Used to detect continuous use of the smooth/noSmooth functions */
protected boolean smoothDisabled = false;
protected int smoothCallCount = 0;
protected int lastSmoothCall = -10;
/** Type of pixels operation. */
static protected final int OP_NONE = 0;
static protected final int OP_READ = 1;
@@ -3096,8 +3101,10 @@ public class PGraphicsOpenGL extends PGraphics {
smooth(2);
}
public void smooth(int level) {
if (smoothDisabled) return;
smooth = true;
if (maxSamples < level) {
@@ -3108,6 +3115,15 @@ public class PGraphicsOpenGL extends PGraphics {
}
if (quality != level) {
smoothCallCount++;
if (parent.frameCount - lastSmoothCall < 30 && 5 < smoothCallCount) {
smoothDisabled = true;
PGraphics.showWarning("The smooth/noSmooth functions are being called too often.\n" +
"This results in screen flickering, so they will be disabled\n" +
"for the rest of the sketch's execution.");
}
lastSmoothCall = parent.frameCount;
quality = level;
if (quality == 1) {
quality = 0;
@@ -3120,9 +3136,20 @@ public class PGraphicsOpenGL extends PGraphics {
public void noSmooth() {
if (smoothDisabled) return;
smooth = false;
if (1 < quality) {
smoothCallCount++;
if (parent.frameCount - lastSmoothCall < 30 && 5 < smoothCallCount) {
smoothDisabled = true;
PGraphics.showWarning("The smooth/noSmooth functions are being called too often.\n" +
"This results in screen flickering, so they will be disabled\n" +
"for the rest of the sketch's execution.");
}
lastSmoothCall = parent.frameCount;
quality = 0;
// This will trigger a surface restart next time
// requestDraw() is called.
@@ -375,6 +375,11 @@ public class PGraphicsOpenGL extends PGraphics {
/** Used to indicate an OpenGL surface recreation */
protected boolean restoreSurface = false;
/** Used to detect continuous use of the smooth/noSmooth functions */
protected boolean smoothDisabled = false;
protected int smoothCallCount = 0;
protected int lastSmoothCall = -10;
/** Type of pixels operation. */
static protected final int OP_NONE = 0;
static protected final int OP_READ = 1;
@@ -3096,8 +3101,10 @@ public class PGraphicsOpenGL extends PGraphics {
smooth(2);
}
public void smooth(int level) {
if (smoothDisabled) return;
smooth = true;
if (maxSamples < level) {
@@ -3108,6 +3115,15 @@ public class PGraphicsOpenGL extends PGraphics {
}
if (quality != level) {
smoothCallCount++;
if (parent.frameCount - lastSmoothCall < 30 && 5 < smoothCallCount) {
smoothDisabled = true;
PGraphics.showWarning("The smooth/noSmooth functions are being called too often.\n" +
"This results in screen flickering, so they will be disabled\n" +
"for the rest of the sketch's execution.");
}
lastSmoothCall = parent.frameCount;
quality = level;
if (quality == 1) {
quality = 0;
@@ -3120,9 +3136,20 @@ public class PGraphicsOpenGL extends PGraphics {
public void noSmooth() {
if (smoothDisabled) return;
smooth = false;
if (1 < quality) {
smoothCallCount++;
if (parent.frameCount - lastSmoothCall < 30 && 5 < smoothCallCount) {
smoothDisabled = true;
PGraphics.showWarning("The smooth/noSmooth functions are being called too often.\n" +
"This results in screen flickering, so they will be disabled\n" +
"for the rest of the sketch's execution.");
}
lastSmoothCall = parent.frameCount;
quality = 0;
// This will trigger a surface restart next time
// requestDraw() is called.