From 12d7496c90ffa0ff2a28be22d7c29bf7b91ec360 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 3 Aug 2014 10:12:25 -0400 Subject: [PATCH] very early support for Retina in the OpenGL renderers --- core/src/processing/opengl/PJOGL.java | 52 +++++++++++++++------------ 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index 9aa70d2d1..1ecb147cb 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -13,6 +13,7 @@ import java.nio.IntBuffer; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import javax.media.nativewindow.ScalableSurface; import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.GL2ES1; @@ -57,6 +58,9 @@ public class PJOGL extends PGL { // OpenGL profile to use (2, 3 or 4) public static int PROFILE = 2; + // Enables/disables Retina support on OSX + public static boolean RETINA = false; + // The two windowing toolkits available to use in JOGL: public static final int AWT = 0; // http://jogamp.org/wiki/index.php/Using_JOGL_in_AWT_SWT_and_Swing public static final int NEWT = 1; // http://jogamp.org/jogl/doc/NEWT-Overview.html @@ -150,15 +154,9 @@ public class PJOGL extends PGL { /** The AWT-OpenGL canvas */ protected GLCanvas canvasAWT; - /** The shared AWT-OpenGL canvas */ -// protected static GLCanvas sharedCanvasAWT; - /** The NEWT window */ protected GLWindow windowNEWT; - /** The shared NEWT window */ -// protected static GLWindow sharedWindowNEWT; - /** The NEWT-OpenGL canvas */ protected NewtCanvasAWT canvasNEWT; @@ -192,6 +190,12 @@ public class PJOGL extends PGL { // ........................................................ + // Retina support + + int retf = 1; + + // ........................................................ + // Utility arrays to copy projection/modelview matrices to GL protected float[] projMatrix; @@ -281,12 +285,10 @@ public class PJOGL extends PGL { if (canvasAWT != null || canvasNEWT != null) { // Restarting... if (canvasAWT != null) { -// sharedCanvasAWT = null; canvasAWT.removeGLEventListener(listener); pg.parent.removeListeners(canvasAWT); pg.parent.remove(canvasAWT); } else if (canvasNEWT != null) { -// sharedWindowNEWT = null; windowNEWT.removeGLEventListener(listener); pg.parent.remove(canvasNEWT); } @@ -334,11 +336,16 @@ public class PJOGL extends PGL { if (WINDOW_TOOLKIT == AWT) { canvasAWT = new GLCanvas(caps); -// if (sharedCanvasAWT == null) { -// sharedCanvasAWT = canvasAWT; -// } else { -// canvasAWT.setSharedAutoDrawable(sharedCanvasAWT); -// } + + if (RETINA) { + canvasAWT.setSurfaceScale(new int[] { ScalableSurface.AUTOMAX_PIXELSCALE, + ScalableSurface.AUTOMAX_PIXELSCALE }); + retf = 2; + } else { + canvasAWT.setSurfaceScale(new int[] { ScalableSurface.IDENTITY_PIXELSCALE, + ScalableSurface.IDENTITY_PIXELSCALE }); + } + canvasAWT.setBounds(0, 0, pg.width, pg.height); canvasAWT.setBackground(new Color(pg.backgroundColor, true)); canvasAWT.setFocusable(true); @@ -347,15 +354,12 @@ public class PJOGL extends PGL { pg.parent.add(canvasAWT, BorderLayout.CENTER); canvasAWT.requestFocusInWindow(); + + canvas = canvasAWT; canvasNEWT = null; } else if (WINDOW_TOOLKIT == NEWT) { windowNEWT = GLWindow.create(caps); -// if (sharedWindowNEWT == null) { -// sharedWindowNEWT = windowNEWT; -// } else { -// windowNEWT.setSharedAutoDrawable(sharedWindowNEWT); -// } canvasNEWT = new NewtCanvasAWT(windowNEWT); canvasNEWT.setBounds(0, 0, pg.width, pg.height); canvasNEWT.setBackground(new Color(pg.backgroundColor, true)); @@ -365,6 +369,9 @@ public class PJOGL extends PGL { pg.parent.add(canvasNEWT, BorderLayout.CENTER); canvasNEWT.requestFocusInWindow(); + int[] reqSurfacePixelScale = new int[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; + windowNEWT.setSurfaceScale(reqSurfacePixelScale); + canvas = canvasNEWT; canvasAWT = null; } @@ -852,9 +859,8 @@ public class PJOGL extends PGL { } else { // w/out multisampling, rendering is done on the back buffer. frontFBO = fboDrawable.getFBObject(GL.GL_FRONT); - - backTexAttach = fboDrawable.getTextureBuffer(GL.GL_BACK); - frontTexAttach = fboDrawable.getTextureBuffer(GL.GL_FRONT); + backTexAttach = (FBObject.TextureAttachment) backFBO.getColorbuffer(0); + frontTexAttach = (FBObject.TextureAttachment) frontFBO.getColorbuffer(0); } } } @@ -1776,7 +1782,7 @@ public class PJOGL extends PGL { @Override public void viewport(int x, int y, int w, int h) { - gl.glViewport(x, y, w, h); + gl.glViewport(retf * x, retf * y, retf * w, retf * h); } ////////////////////////////////////////////////////////////////////////////// @@ -2298,7 +2304,7 @@ public class PJOGL extends PGL { @Override public void scissor(int x, int y, int w, int h) { - gl.glScissor(x, y, w, h); + gl.glScissor(retf * x, retf * y, retf * w, retf * h); } @Override