From c18cfb233bd1c930831d1971c81b3af8a9b6b419 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 25 Jun 2012 20:25:40 +0000 Subject: [PATCH] using screen FBO also when quality < 2 --- .../processing/opengl/PGraphicsOpenGL.java | 2 ++ .../core/src/processing/opengl/Texture.java | 2 +- .../opengl/src/processing/opengl/PGL.java | 25 +++++++++++++++---- .../processing/opengl/PGraphicsOpenGL.java | 2 ++ .../opengl/src/processing/opengl/Texture.java | 2 +- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index f842a4a39..5dc7c24db 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -4868,6 +4868,8 @@ public class PGraphicsOpenGL extends PGraphics { readPixels(); if (primarySurface) { + // Copy pixels to the texture associated to the primary surface + // so both are in sync. loadTextureImpl(POINT, false); pixelsToTexture(); } diff --git a/android/core/src/processing/opengl/Texture.java b/android/core/src/processing/opengl/Texture.java index 3196fc62d..763e84d64 100644 --- a/android/core/src/processing/opengl/Texture.java +++ b/android/core/src/processing/opengl/Texture.java @@ -272,7 +272,7 @@ public class Texture implements PConstants { return; } if (pixels.length != w * h) { - PGraphics.showWarning("The pixels array has the wrong length. It should be " + w * h); + PGraphics.showWarning("The pixels array has a length of " + pixels.length + ", but it should be " + w * h); return; } diff --git a/java/libraries/opengl/src/processing/opengl/PGL.java b/java/libraries/opengl/src/processing/opengl/PGL.java index e397c2178..d50c418e5 100644 --- a/java/libraries/opengl/src/processing/opengl/PGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGL.java @@ -361,6 +361,7 @@ public class PGL { public static final boolean ENABLE_OSX_SCREEN_FBO = true; public static final int MIN_OSX_VER_FOR_SCREEN_FBO = 6; + public static final int MIN_SAMPLES_FOR_SCREEN_FBO = 1; protected boolean needScreenFBO = false; protected int fboWidth, fboHeight; protected int numSamples; @@ -511,10 +512,13 @@ public class PGL { String[] parts = version.split("\\."); if (2 <= parts.length) { int num = Integer.parseInt(parts[1]); - if (MIN_OSX_VER_FOR_SCREEN_FBO <= num && 1 < pg.quality) { - // We are on OSX Lion or newer, where JOGL doesn't properly - // support multisampling. As a temporary hack, we handle our - // own multisampled FBO for onscreen rendering with anti-aliasing. + if (MIN_OSX_VER_FOR_SCREEN_FBO <= num && + MIN_SAMPLES_FOR_SCREEN_FBO <= qualityToSamples(pg.quality)) { + // Using an FBO for screen drawing works better than the + // screen framebuffer. + // This fixes the problem of antialiasing on Lion or newer, + // the flickering associated to glReadPixels calls on + // 10.6+, and it is in fact faster. needScreenFBO = true; } } @@ -602,7 +606,7 @@ public class PGL { } if (needScreenFBO && colorFBO[0] == 0) { - numSamples = pg.quality; + numSamples = qualityToSamples(pg.quality); String ext = gl.glGetString(GL.GL_EXTENSIONS); if (-1 < ext.indexOf("texture_non_power_of_two")) { @@ -723,7 +727,18 @@ public class PGL { gl.glDeleteRenderbuffers(1, packedDepthStencil, 0); } + + protected int qualityToSamples(int quality) { + if (quality <= 1) { + return 1; + } else { + // Number of samples is always an even number: + int n = 2 * (quality / 2); + return n; + } + } + /////////////////////////////////////////////////////////////////////////////////// // Frame rendering diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index f842a4a39..5dc7c24db 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -4868,6 +4868,8 @@ public class PGraphicsOpenGL extends PGraphics { readPixels(); if (primarySurface) { + // Copy pixels to the texture associated to the primary surface + // so both are in sync. loadTextureImpl(POINT, false); pixelsToTexture(); } diff --git a/java/libraries/opengl/src/processing/opengl/Texture.java b/java/libraries/opengl/src/processing/opengl/Texture.java index 3196fc62d..763e84d64 100644 --- a/java/libraries/opengl/src/processing/opengl/Texture.java +++ b/java/libraries/opengl/src/processing/opengl/Texture.java @@ -272,7 +272,7 @@ public class Texture implements PConstants { return; } if (pixels.length != w * h) { - PGraphics.showWarning("The pixels array has the wrong length. It should be " + w * h); + PGraphics.showWarning("The pixels array has a length of " + pixels.length + ", but it should be " + w * h); return; }