Merge branch 'master' of github.com:processing/processing

This commit is contained in:
Ben Fry
2015-06-07 15:10:04 -04:00
+110 -155
View File
@@ -48,7 +48,6 @@ public class PSurfaceJOGL implements PSurface {
PJOGL pgl;
GLWindow window;
// Frame frame;
FPSAnimator animator;
Rectangle screenRect;
@@ -71,6 +70,11 @@ public class PSurfaceJOGL implements PSurface {
float[] currentPixelScale = {0, 0};
boolean presentMode = false;
float offsetX;
float offsetY;
public PSurfaceJOGL(PGraphics graphics) {
this.graphics = graphics;
this.pgl = (PJOGL) ((PGraphicsOpenGL)graphics).pgl;
@@ -96,148 +100,13 @@ public class PSurfaceJOGL implements PSurface {
int deviceIndex, boolean fullScreen,
boolean spanDisplays) {*/
this.sketch = sketch;
setIconImages();
initIcons();
initScreen();
initGL();
window = GLWindow.create(screen, pgl.capabilities);
if (displayDevice == null) {
displayDevice = window.getMainMonitor();
}
int displayNum = sketch.sketchDisplay();
if (displayNum > 0) { // if -1, use the default device
if (displayNum <= monitors.size()) {
displayDevice = monitors.get(displayNum - 1);
} else {
System.err.format("Display %d does not exist, " +
"using the default display instead.", displayNum);
for (int i = 0; i < monitors.size(); i++) {
System.err.format("Display %d is %s\n", i+1, monitors.get(i));
}
}
}
boolean spanDisplays = sketch.sketchDisplay() == PConstants.SPAN;
screenRect = spanDisplays ?
new Rectangle(0, 0, screen.getWidth(), screen.getHeight()) :
new Rectangle(0, 0,
displayDevice.getViewportInWindowUnits().getWidth(),
displayDevice.getViewportInWindowUnits().getHeight());
sketch.displayWidth = screenRect.width;
sketch.displayHeight = screenRect.height;
if (spanDisplays) {
sketchWidth = screenRect.width;
sketchHeight = screenRect.height;
}
boolean fullScreen = sketch.sketchFullScreen();
if (fullScreen) {
sketchWidth = sketch.sketchWidth();
sketchHeight = sketch.sketchHeight();
}
// Sketch has already requested to be the same as the screen's
// width and height, so let's roll with full screen mode.
if (screenRect.width == sketchWidth &&
screenRect.height == sketchHeight) {
fullScreen = true;
}
if (fullScreen) {
presentMode = sketchWidth < screenRect.width && sketchHeight < screenRect.height;
}
// System.err.println("0. create window");
float[] reqSurfacePixelScale;
if (graphics.is2X()) {
// Retina
reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE,
ScalableSurface.AUTOMAX_PIXELSCALE };
} else {
// Non-retina
reqSurfacePixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE,
ScalableSurface.IDENTITY_PIXELSCALE };
}
window.setSurfaceScale(reqSurfacePixelScale);
// window..setBackground(new Color(backgroundColor, true));
// sketch.width = sketch.sketchWidth();
// sketch.height = sketch.sketchHeight();
window.setSize(sketchWidth, sketchHeight);
//graphics.setSize(sketch.width, sketch.height);
// int screenWidth = screen.getWidth();
// int screenHeight = screen.getHeight();
// window..setBackground(new Color(backgroundColor, true));
// window.setSize(sketchWidth, sketchHeight);
// sketch.width = sketch.sketchWidth();
// sketch.height = sketch.sketchHeight();
// graphics.setSize(sketch.width, sketch.height);
// System.out.println("deviceIndex: " + deviceIndex);
// System.out.println(displayDevice);
// System.out.println("Screen res " + screenWidth + "x" + screenHeight);
// This example could be useful:
// com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01cNEWT
sketchX = displayDevice.getViewportInWindowUnits().getX();
sketchY = displayDevice.getViewportInWindowUnits().getY();
if (fullScreen) {
PApplet.hideMenuBar();
window.setTopLevelPosition(sketchX, sketchY);
if (spanDisplays) {
window.setFullscreen(monitors);
} else {
window.setFullscreen(true);
}
}
initWindow();
initListeners();
initAnimator();
/*
window.addWindowListener(new WindowAdapter() {
@Override
public void windowDestroyNotify(final WindowEvent e) {
PSurfaceJOGL.this.sketch.dispose();
PSurfaceJOGL.this.sketch.exitActual();
}
});
*/
window.setVisible(true);
// System.err.println("4. set visible");
/*
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
window.setVisible(true);
System.err.println("1. set visible");
}});
} catch (Exception ex) {
// error setting the window visible, should quit...
}
*/
// frame = new DummyFrame();
// return frame;
}
@@ -331,8 +200,7 @@ public class PSurfaceJOGL implements PSurface {
} else if (graphics.smooth == 1) {
pgl.reqNumSamples = 2;
} else {
// int n = graphics.smooth - 2)
pgl.reqNumSamples = 4;
pgl.reqNumSamples = 2 * graphics.smooth;
}
caps.setSampleBuffers(true);
caps.setNumSamples(pgl.reqNumSamples);
@@ -342,6 +210,81 @@ public class PSurfaceJOGL implements PSurface {
}
protected void initWindow() {
window = GLWindow.create(screen, pgl.capabilities);
if (displayDevice == null) {
displayDevice = window.getMainMonitor();
}
int displayNum = sketch.sketchDisplay();
if (displayNum > 0) { // if -1, use the default device
if (displayNum <= monitors.size()) {
displayDevice = monitors.get(displayNum - 1);
} else {
System.err.format("Display %d does not exist, " +
"using the default display instead.", displayNum);
for (int i = 0; i < monitors.size(); i++) {
System.err.format("Display %d is %s\n", i+1, monitors.get(i));
}
}
}
boolean spanDisplays = sketch.sketchDisplay() == PConstants.SPAN;
screenRect = spanDisplays ?
new Rectangle(0, 0, screen.getWidth(), screen.getHeight()) :
new Rectangle(0, 0,
displayDevice.getViewportInWindowUnits().getWidth(),
displayDevice.getViewportInWindowUnits().getHeight());
// Set the displayWidth/Height variables inside PApplet, so that they're
// usable and can even be returned by the sketchWidth()/Height() methods.
sketch.displayWidth = screenRect.width;
sketch.displayHeight = screenRect.height;
sketchWidth = sketch.sketchWidth();
sketchHeight = sketch.sketchHeight();
boolean fullScreen = sketch.sketchFullScreen();
// Sketch has already requested to be the same as the screen's
// width and height, so let's roll with full screen mode.
if (screenRect.width == sketchWidth &&
screenRect.height == sketchHeight) {
fullScreen = true;
// sketch.fullScreen = true; // hmm
}
if (fullScreen || spanDisplays) {
sketchWidth = screenRect.width;
sketchHeight = screenRect.height;
}
float[] reqSurfacePixelScale;
if (graphics.is2X()) {
// Retina
reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE,
ScalableSurface.AUTOMAX_PIXELSCALE };
} else {
// Non-retina
reqSurfacePixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE,
ScalableSurface.IDENTITY_PIXELSCALE };
}
window.setSurfaceScale(reqSurfacePixelScale);
window.setSize(sketchWidth, sketchHeight);
setSize(sketchWidth, sketchHeight);
sketchX = displayDevice.getViewportInWindowUnits().getX();
sketchY = displayDevice.getViewportInWindowUnits().getY();
if (fullScreen) {
PApplet.hideMenuBar();
window.setTopLevelPosition(sketchX, sketchY);
if (spanDisplays) {
window.setFullscreen(monitors);
} else {
window.setFullscreen(true);
}
}
}
protected void initListeners() {
NEWTMouseListener mouseListener = new NEWTMouseListener();
window.addMouseListener(mouseListener);
@@ -493,23 +436,29 @@ public class PSurfaceJOGL implements PSurface {
// sketchWidth, sketchHeight);
}
boolean presentMode = false;
float offsetX;
float offsetY;
public void placePresent(int stopColor) {
if (presentMode) {
// if (presentMode) {
// System.err.println("Present mode");
// System.err.println("WILL USE FBO");
presentMode = pgl.presentMode = true;
offsetX = pgl.offsetX = 0.5f * (screenRect.width - sketchWidth);
offsetY = pgl.offsetY = 0.5f * (screenRect.height - sketchHeight);
pgl.requestFBOLayer();
}
presentMode = pgl.presentMode = true;
offsetX = pgl.offsetX = 0.5f * (screenRect.width - sketchWidth);
offsetY = pgl.offsetY = 0.5f * (screenRect.height - sketchHeight);
pgl.requestFBOLayer();
window.setSize(screenRect.width, screenRect.height);
PApplet.hideMenuBar();
window.setTopLevelPosition(0, 0);
window.setFullscreen(true);
// }
}
protected void setIconImages() {
//int[] sizes = { 16, 32, 48, 64 };
protected void initIcons() {
final int[] sizes = { 16, 32, 48, 64, 128, 256, 512 };
String[] iconImages = new String[sizes.length];
for (int i = 0; i < sizes.length; i++) {
@@ -568,18 +517,24 @@ public class PSurfaceJOGL implements PSurface {
}
public void setSize(int width, int height) {
if (animator.isAnimating()) {
if (width == sketch.width && height == sketch.height) {
return;
}
// if (animator.isAnimating()) {
// System.err.println("3. set size");
if (!presentMode) {
sketch.width = width;
sketch.height = height;
sketchWidth = width;
sketchHeight = height;
graphics.setSize(width, height);
}
sketchWidth = width;
sketchHeight = height;
}
// }
}
public float getPixelScale() {