diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 124464ce6..0a6bde31c 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -559,24 +559,17 @@ public class PGL { } - protected void setFrameRate(float framerate) { - if (targetFps != framerate) { - if (60 < framerate) { + protected void setFps(float fps) { + if (!setFps || targetFps != fps) { + if (60 < fps) { // Disables v-sync gl.setSwapInterval(0); - } else if (30 < framerate) { + } else if (30 < fps) { gl.setSwapInterval(1); } else { gl.setSwapInterval(2); } - if ((60 < framerate && targetFps <= 60) || - (framerate <= 60 && 60 < targetFps)) { - // Enabling/disabling v-sync, we force a - // surface reinitialization to avoid screen - // no-paint issue observed on MacOSX. - pg.initialized = false; - } - targetFps = currentFps = framerate; + targetFps = currentFps = fps; setFps = true; } } @@ -596,7 +589,6 @@ public class PGL { pg.parent.remove(canvasNEWT); } sinkFBO = backFBO = frontFBO = null; - setFps = false; } // Setting up the desired GL capabilities; @@ -670,6 +662,8 @@ public class PGL { fboLayerCreated = false; fboLayerInUse = false; firstFrame = true; + + setFps = false; } @@ -700,9 +694,8 @@ public class PGL { protected void update() { - if (!setFps) { - setFrameRate(targetFps); - } + if (!setFps) setFps(targetFps); + if (USE_JOGL_FBOLAYER) return; if (!fboLayerCreated) { diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index b1e66782f..8f2fb3e8a 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -574,7 +574,7 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void setFrameRate(float frameRate) { - pgl.setFrameRate(frameRate); + pgl.setFps(frameRate); } diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java index 9305b8167..feb5400d0 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java @@ -489,9 +489,16 @@ public class PGL extends processing.opengl.PGL { } - protected void setFrameRate(float framerate) { - if (targetFps != framerate) { - targetFps = currentFps = framerate; + protected void setFps(float fps) { + if (!setFps || targetFps != fps) { + if (60 < fps) { + // Disables v-sync + Display.setVSyncEnabled(false); + Display.sync((int)fps); + } else { + Display.setVSyncEnabled(true); + } + targetFps = currentFps = fps; setFps = true; } } @@ -537,7 +544,6 @@ public class PGL extends processing.opengl.PGL { float b = ((argb) & 0xff) / 255.0f; Display.setInitialBackground(r, g, b); Display.setParent(canvas); - Display.setVSyncEnabled(true); Display.create(format); // Might be useful later to specify the context attributes. @@ -563,6 +569,8 @@ public class PGL extends processing.opengl.PGL { fboLayerInUse = false; firstFrame = true; needToClearBuffers = true; + + setFps = false; } @@ -583,7 +591,9 @@ public class PGL extends processing.opengl.PGL { } - protected void update() { + protected void update() { + if (!setFps) setFps(targetFps); + if (!fboLayerCreated) { if (!hasFBOs()) { throw new RuntimeException("Framebuffer objects are not supported by this hardware (or driver)");