From d26c3f8a032ca10f0ab0a45d916dcd4582b8f439 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 16 Dec 2014 18:51:43 -0500 Subject: [PATCH] handle smooth changes in surface --- core/src/processing/core/PApplet.java | 6 ++++ core/src/processing/core/PGraphicsJava2D.java | 1 + core/src/processing/core/PSurface.java | 2 ++ core/src/processing/core/PSurfaceAWT.java | 4 +++ core/src/processing/opengl/PGL.java | 1 - .../processing/opengl/PGraphicsOpenGL.java | 3 +- core/src/processing/opengl/PSurfaceNEWT.java | 32 +++++++++++++++++-- 7 files changed, 44 insertions(+), 5 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index cef795f0d..893d318ae 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -1791,6 +1791,7 @@ public class PApplet implements PConstants { return; } + int pquality = g.quality; insideDraw = true; g.beginDraw(); if (recorder != null) { @@ -1849,6 +1850,11 @@ public class PApplet implements PConstants { // (only do this once draw() has run, not just setup()) } g.endDraw(); + + if (pquality != g.quality) { + surface.setSmooth(g.quality); + } + if (recorder != null) { recorder.endDraw(); } diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index 46e88033e..a5aa79448 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -1392,6 +1392,7 @@ public class PGraphicsJava2D extends PGraphics { // g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + } diff --git a/core/src/processing/core/PSurface.java b/core/src/processing/core/PSurface.java index 4cab762eb..b32034c51 100644 --- a/core/src/processing/core/PSurface.java +++ b/core/src/processing/core/PSurface.java @@ -103,6 +103,8 @@ public interface PSurface { public void setSize(int width, int height); + public void setSmooth(int level); + public void setFrameRate(float fps); // called on the first frame so that the now-visible drawing surface can diff --git a/core/src/processing/core/PSurfaceAWT.java b/core/src/processing/core/PSurfaceAWT.java index 6e1fd6f97..35c405b07 100644 --- a/core/src/processing/core/PSurfaceAWT.java +++ b/core/src/processing/core/PSurfaceAWT.java @@ -861,6 +861,10 @@ public class PSurfaceAWT implements PSurface { } + public void setSmooth(int level) { + } + + private boolean checkRetina() { if (PApplet.platform == PConstants.MACOSX) { // This should probably be reset each time there's a display change. diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 0b722ae7c..d3c7dcf36 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -351,7 +351,6 @@ public abstract class PGL { } - // public abstract Object getCanvas(); // // diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 16c8c2eaa..5dbc0b0bf 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -3392,6 +3392,7 @@ public class PGraphicsOpenGL extends PGraphics { lastSmoothCall = parent.frameCount; quality = level; + System.out.println(quality); if (quality == 1) { quality = 0; @@ -3399,7 +3400,7 @@ public class PGraphicsOpenGL extends PGraphics { // This will trigger a surface restart next time // requestDraw() is called. - restartPGL(); +// restartPGL(); } } diff --git a/core/src/processing/opengl/PSurfaceNEWT.java b/core/src/processing/opengl/PSurfaceNEWT.java index a10f585a0..9914e9c75 100644 --- a/core/src/processing/opengl/PSurfaceNEWT.java +++ b/core/src/processing/opengl/PSurfaceNEWT.java @@ -8,6 +8,7 @@ import java.awt.Rectangle; //import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.ScalableSurface; import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; @@ -16,6 +17,7 @@ import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; +import com.jogamp.nativewindow.MutableGraphicsConfiguration; import com.jogamp.newt.Display; import com.jogamp.newt.MonitorDevice; import com.jogamp.newt.NewtFactory; @@ -155,15 +157,15 @@ public class PSurfaceNEWT implements PSurface { // caps.setPBuffer(false); // caps.setFBO(false); + pgl.reqNumSamples = graphics.quality; caps.setSampleBuffers(true); - caps.setNumSamples(2); + caps.setNumSamples(pgl.reqNumSamples); caps.setBackgroundOpaque(true); caps.setOnscreen(true); pgl.capabilities = caps; System.err.println("0. create window"); window = GLWindow.create(screen, caps); - sketchWidth = sketch.sketchWidth(); sketchHeight = sketch.sketchHeight(); @@ -418,6 +420,21 @@ public class PSurfaceNEWT implements PSurface { } } + public void setSmooth(int level) { + pgl.reqNumSamples = level; + GLCapabilities caps = new GLCapabilities(profile); + caps.setAlphaBits(PGL.REQUESTED_ALPHA_BITS); + caps.setDepthBits(PGL.REQUESTED_DEPTH_BITS); + caps.setStencilBits(PGL.REQUESTED_STENCIL_BITS); + caps.setSampleBuffers(true); + caps.setNumSamples(pgl.reqNumSamples); + caps.setBackgroundOpaque(true); + caps.setOnscreen(true); + NativeSurface target = window.getNativeSurface(); + MutableGraphicsConfiguration config = (MutableGraphicsConfiguration) target.getGraphicsConfiguration(); + config.setChosenCapabilities(caps); + } + public void setFrameRate(float fps) { if (animator != null) { animator.stop(); @@ -619,11 +636,20 @@ public class PSurfaceNEWT implements PSurface { } else { keyChar = nativeEvent.getKeyChar(); } +// System.out.println("KY: " + nativeEvent.getKeyCode() + " " + nativeEvent.getKeySymbol()); + // From http://jogamp.org/deployment/v2.1.0/javadoc/jogl/javadoc/com/jogamp/newt/event/KeyEvent.html + // public final short getKeySymbol() + // Returns the virtual key symbol reflecting the current keyboard layout. + // public final short getKeyCode() + // Returns the virtual key code using a fixed mapping to the US keyboard layout. + // In contrast to key symbol, key code uses a fixed US keyboard layout and therefore is keyboard layout independent. + // E.g. virtual key code VK_Y denotes the same physical key regardless whether keyboard layout QWERTY or QWERTZ is active. The key symbol of the former is VK_Y, where the latter produces VK_Y. KeyEvent ke = new KeyEvent(nativeEvent, nativeEvent.getWhen(), peAction, peModifiers, keyChar, - nativeEvent.getKeyCode()); +// nativeEvent.getKeyCode()); + nativeEvent.getKeySymbol()); sketch.postEvent(ke); }