mirror of
https://github.com/processing/processing4.git
synced 2026-05-31 12:37:14 +02:00
handle smooth changes in surface
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -1392,6 +1392,7 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
|
||||
// g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
|
||||
// RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -351,7 +351,6 @@ public abstract class PGL {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// public abstract Object getCanvas();
|
||||
//
|
||||
//
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user