mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 21:59:20 +01:00
very early support for Retina in the OpenGL renderers
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user