diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index e54897e70..dd729c73f 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -132,11 +132,6 @@ public abstract class PGL { * order to make sure the lines are always on top of the fill geometry */ protected static float STROKE_DISPLACEMENT = 0.999f; - // ........................................................ - - // Retina support - - int pixel_scale = 1; // ........................................................ @@ -566,9 +561,10 @@ public abstract class PGL { x = (int)offsetX; y = (int)offsetY; } + float scale = pg.getPixelScale(); drawTexture(TEXTURE_2D, glColorTex.get(frontTex), fboWidth, fboHeight, x, y, pg.width, pg.height, - 0, 0, pixel_scale * pg.width, pixel_scale * pg.height, + 0, 0, (int)(scale * pg.width), (int)(scale * pg.height), 0, 0, pg.width, pg.height); } @@ -663,10 +659,11 @@ public abstract class PGL { x = (int)offsetX; y = (int)offsetY; } + float scale = pg.getPixelScale(); drawTexture(TEXTURE_2D, glColorTex.get(backTex), fboWidth, fboHeight, x, y, pg.width, pg.height, - 0, 0, pixel_scale * pg.width, pixel_scale * pg.height, + 0, 0, (int)(scale * pg.width), (int)(scale * pg.height), 0, 0, pg.width, pg.height); // Swapping front and back textures. @@ -720,12 +717,14 @@ public abstract class PGL { private void createFBOLayer() { String ext = getString(EXTENSIONS); + float scale = pg.getPixelScale(); + if (-1 < ext.indexOf("texture_non_power_of_two")) { - fboWidth = pixel_scale * pg.width; - fboHeight = pixel_scale * pg.height; + fboWidth = (int)(scale * pg.width); + fboHeight = (int)(scale * pg.height); } else { - fboWidth = nextPowerOfTwo(pixel_scale * pg.width); - fboHeight = nextPowerOfTwo(pixel_scale * pg.height); + fboWidth = nextPowerOfTwo((int)(scale * pg.width)); + fboHeight = nextPowerOfTwo((int)(scale * pg.height)); } int maxs = maxSamples(); diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 53358b52b..f67febe8f 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -43,6 +43,9 @@ public class PGraphicsOpenGL extends PGraphics { /** Font cache for texture objects. */ protected WeakHashMap fontMap; + // just to get things running properly, need to + protected PSurfaceJOGL surfaceJOGL; + // ........................................................ // Basic rendering parameters: @@ -668,8 +671,8 @@ public class PGraphicsOpenGL extends PGraphics { @Override public PSurface createSurface() { // ignore - return new PSurfaceJOGL(this); -// return new PSurfaceNEWT(this); + surfaceJOGL = new PSurfaceJOGL(this); + return surfaceJOGL; } @@ -696,6 +699,11 @@ public class PGraphicsOpenGL extends PGraphics { } + public float getPixelScale() { + return surfaceJOGL.getPixelScale(); + } + + ////////////////////////////////////////////////////////////// diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index 29ec5cb88..957a235ce 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -1892,7 +1892,8 @@ public class PJOGL extends PGL { @Override public void viewport(int x, int y, int w, int h) { - gl.glViewport(pixel_scale * x, pixel_scale * y, pixel_scale * w, pixel_scale * h); + float scale = pg.getPixelScale(); + gl.glViewport((int)scale * x, (int)(scale * y), (int)(scale * w), (int)(scale * h)); // gl.glViewport(x, y, w, h); } @@ -2415,7 +2416,8 @@ public class PJOGL extends PGL { @Override public void scissor(int x, int y, int w, int h) { - gl.glScissor(pixel_scale * x, pixel_scale * y, pixel_scale * w, pixel_scale * h); + float scale = pg.getPixelScale(); + gl.glScissor((int)scale * x, (int)(scale * y), (int)(scale * w), (int)(scale * h)); // gl.glScissor(x, y, w, h); } diff --git a/core/src/processing/opengl/PSurfaceJOGL.java b/core/src/processing/opengl/PSurfaceJOGL.java index 99cc20c04..f7d03c4e9 100644 --- a/core/src/processing/opengl/PSurfaceJOGL.java +++ b/core/src/processing/opengl/PSurfaceJOGL.java @@ -62,7 +62,7 @@ public class PSurfaceJOGL implements PSurface { NewtCanvasAWT canvas; - float[] hasSurfacePixelScale = {0, 0}; + float[] currentPixelScale = {0, 0}; public PSurfaceJOGL(PGraphics graphics) { this.graphics = graphics; @@ -226,12 +226,10 @@ public class PSurfaceJOGL implements PSurface { // Retina reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; - pgl.pixel_scale = 2; } else { // Non-retina reqSurfacePixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; -// pgl.pixel_scale = 1; } window.setSurfaceScale(reqSurfacePixelScale); @@ -475,6 +473,11 @@ public class PSurfaceJOGL implements PSurface { } } + public float getPixelScale() { + window.getCurrentSurfaceScale(currentPixelScale); + return currentPixelScale[0]; + } + public Component getComponent() { return canvas; } @@ -543,7 +546,7 @@ public class PSurfaceJOGL implements PSurface { public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) { // final float[] valReqSurfacePixelScale = window.getRequestedSurfaceScale(new float[2]); - window.getCurrentSurfaceScale(hasSurfacePixelScale); + window.getCurrentSurfaceScale(currentPixelScale); // final float[] nativeSurfacePixelScale = window.getMaximumSurfaceScale(new float[2]); // System.err.println("[set PixelScale post]: "+ // valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+ @@ -560,7 +563,7 @@ public class PSurfaceJOGL implements PSurface { // } else { // setSize(w, h); // } - setSize((int)(w/hasSurfacePixelScale[0]), (int)(h/hasSurfacePixelScale[1])); + setSize((int)(w/currentPixelScale[0]), (int)(h/currentPixelScale[1])); } } @@ -688,9 +691,9 @@ public class PSurfaceJOGL implements PSurface { peCount = nativeEvent.getClickCount(); } - window.getCurrentSurfaceScale(hasSurfacePixelScale); - int sx = (int)(nativeEvent.getX()/hasSurfacePixelScale[0]); - int sy = (int)(nativeEvent.getY()/hasSurfacePixelScale[1]); + window.getCurrentSurfaceScale(currentPixelScale); + int sx = (int)(nativeEvent.getX()/currentPixelScale[0]); + int sy = (int)(nativeEvent.getY()/currentPixelScale[1]); if (presentMode) { if (peAction == KeyEvent.RELEASE && 20 < sx && sx < 20 + 100 &&