Skip to content

Commit 2ab6b31

Browse files
committed
very early support for Retina in the OpenGL renderers
1 parent 5a56f15 commit 2ab6b31

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

core/src/processing/opengl/PJOGL.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.concurrent.CountDownLatch;
1414
import java.util.concurrent.TimeUnit;
1515

16+
import javax.media.nativewindow.ScalableSurface;
1617
import javax.media.opengl.GL;
1718
import javax.media.opengl.GL2;
1819
import javax.media.opengl.GL2ES1;
@@ -57,6 +58,9 @@ public class PJOGL extends PGL {
5758
// OpenGL profile to use (2, 3 or 4)
5859
public static int PROFILE = 2;
5960

61+
// Enables/disables Retina support on OSX
62+
public static boolean RETINA = false;
63+
6064
// The two windowing toolkits available to use in JOGL:
6165
public static final int AWT = 0; // http://jogamp.org/wiki/index.php/Using_JOGL_in_AWT_SWT_and_Swing
6266
public static final int NEWT = 1; // http://jogamp.org/jogl/doc/NEWT-Overview.html
@@ -150,15 +154,9 @@ public class PJOGL extends PGL {
150154
/** The AWT-OpenGL canvas */
151155
protected GLCanvas canvasAWT;
152156

153-
/** The shared AWT-OpenGL canvas */
154-
// protected static GLCanvas sharedCanvasAWT;
155-
156157
/** The NEWT window */
157158
protected GLWindow windowNEWT;
158159

159-
/** The shared NEWT window */
160-
// protected static GLWindow sharedWindowNEWT;
161-
162160
/** The NEWT-OpenGL canvas */
163161
protected NewtCanvasAWT canvasNEWT;
164162

@@ -192,6 +190,12 @@ public class PJOGL extends PGL {
192190

193191
// ........................................................
194192

193+
// Retina support
194+
195+
int retf = 1;
196+
197+
// ........................................................
198+
195199
// Utility arrays to copy projection/modelview matrices to GL
196200

197201
protected float[] projMatrix;
@@ -281,12 +285,10 @@ protected void initSurface(int antialias) {
281285
if (canvasAWT != null || canvasNEWT != null) {
282286
// Restarting...
283287
if (canvasAWT != null) {
284-
// sharedCanvasAWT = null;
285288
canvasAWT.removeGLEventListener(listener);
286289
pg.parent.removeListeners(canvasAWT);
287290
pg.parent.remove(canvasAWT);
288291
} else if (canvasNEWT != null) {
289-
// sharedWindowNEWT = null;
290292
windowNEWT.removeGLEventListener(listener);
291293
pg.parent.remove(canvasNEWT);
292294
}
@@ -334,11 +336,16 @@ protected void initSurface(int antialias) {
334336

335337
if (WINDOW_TOOLKIT == AWT) {
336338
canvasAWT = new GLCanvas(caps);
337-
// if (sharedCanvasAWT == null) {
338-
// sharedCanvasAWT = canvasAWT;
339-
// } else {
340-
// canvasAWT.setSharedAutoDrawable(sharedCanvasAWT);
341-
// }
339+
340+
if (RETINA) {
341+
canvasAWT.setSurfaceScale(new int[] { ScalableSurface.AUTOMAX_PIXELSCALE,
342+
ScalableSurface.AUTOMAX_PIXELSCALE });
343+
retf = 2;
344+
} else {
345+
canvasAWT.setSurfaceScale(new int[] { ScalableSurface.IDENTITY_PIXELSCALE,
346+
ScalableSurface.IDENTITY_PIXELSCALE });
347+
}
348+
342349
canvasAWT.setBounds(0, 0, pg.width, pg.height);
343350
canvasAWT.setBackground(new Color(pg.backgroundColor, true));
344351
canvasAWT.setFocusable(true);
@@ -347,15 +354,12 @@ protected void initSurface(int antialias) {
347354
pg.parent.add(canvasAWT, BorderLayout.CENTER);
348355
canvasAWT.requestFocusInWindow();
349356

357+
358+
350359
canvas = canvasAWT;
351360
canvasNEWT = null;
352361
} else if (WINDOW_TOOLKIT == NEWT) {
353362
windowNEWT = GLWindow.create(caps);
354-
// if (sharedWindowNEWT == null) {
355-
// sharedWindowNEWT = windowNEWT;
356-
// } else {
357-
// windowNEWT.setSharedAutoDrawable(sharedWindowNEWT);
358-
// }
359363
canvasNEWT = new NewtCanvasAWT(windowNEWT);
360364
canvasNEWT.setBounds(0, 0, pg.width, pg.height);
361365
canvasNEWT.setBackground(new Color(pg.backgroundColor, true));
@@ -365,6 +369,9 @@ protected void initSurface(int antialias) {
365369
pg.parent.add(canvasNEWT, BorderLayout.CENTER);
366370
canvasNEWT.requestFocusInWindow();
367371

372+
int[] reqSurfacePixelScale = new int[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE };
373+
windowNEWT.setSurfaceScale(reqSurfacePixelScale);
374+
368375
canvas = canvasNEWT;
369376
canvasAWT = null;
370377
}
@@ -852,9 +859,8 @@ public void display(GLAutoDrawable glDrawable) {
852859
} else {
853860
// w/out multisampling, rendering is done on the back buffer.
854861
frontFBO = fboDrawable.getFBObject(GL.GL_FRONT);
855-
856-
backTexAttach = fboDrawable.getTextureBuffer(GL.GL_BACK);
857-
frontTexAttach = fboDrawable.getTextureBuffer(GL.GL_FRONT);
862+
backTexAttach = (FBObject.TextureAttachment) backFBO.getColorbuffer(0);
863+
frontTexAttach = (FBObject.TextureAttachment) frontFBO.getColorbuffer(0);
858864
}
859865
}
860866
}
@@ -1776,7 +1782,7 @@ public void depthRangef(float n, float f) {
17761782

17771783
@Override
17781784
public void viewport(int x, int y, int w, int h) {
1779-
gl.glViewport(x, y, w, h);
1785+
gl.glViewport(retf * x, retf * y, retf * w, retf * h);
17801786
}
17811787

17821788
//////////////////////////////////////////////////////////////////////////////
@@ -2298,7 +2304,7 @@ public String getProgramInfoLog(int program) {
22982304

22992305
@Override
23002306
public void scissor(int x, int y, int w, int h) {
2301-
gl.glScissor(x, y, w, h);
2307+
gl.glScissor(retf * x, retf * y, retf * w, retf * h);
23022308
}
23032309

23042310
@Override

0 commit comments

Comments
 (0)