diff options
author | Sven Gothel <[email protected]> | 2014-06-09 03:58:37 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-06-09 03:58:37 +0200 |
commit | 4686a652d821efe04045333026be79270bc19bfd (patch) | |
tree | 240ac4df0ae58c7461e7bfdfb3b438917041a3af /src/test/com | |
parent | 14ff638b63fc7adaa59f351891f6a38806d7fa5d (diff) |
Bug 741 HiDPI: Add ScalableSurface.getNativeSurfaceScale(..) to compute surface DPI ; Add NEWT Window.getPixelsPerMM(..) to query surface DPI
With HiDPI and surface scale, we need knowledge of the native surface's pixel-scale
matching the monitor's pixel-per-millimeter value.
Preserving the queried native pixel-scale and exposing it via
ScalableSurface.getNativeSurfaceScale(..) to compute surface DPI.
Add NEWT Window.getPixelsPerMM(..) to query surface DPI.
Surface DPI is demonstrated in GraphUI's GPUUISceneGLListener0A .. and TestRulerNEWT01, etc ..
Diffstat (limited to 'src/test/com')
8 files changed, 218 insertions, 129 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java index ad95b3502..2e0be5b79 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java @@ -53,7 +53,6 @@ import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.geom.SVertex; -import com.jogamp.newt.MonitorDevice; import com.jogamp.newt.Window; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.util.MiscUtils; @@ -312,9 +311,7 @@ public class TestTextRendererNEWT00 extends UITestCase { t0 = Platform.currentTimeMillis(); final Window win = (Window)drawable.getUpstreamWidget(); - final MonitorDevice monitor = win.getMainMonitor(); - final float[] pixelsPerMM = new float[2]; - monitor.getPixelsPerMM(pixelsPerMM); + final float[] pixelsPerMM = win.getPixelsPerMM(new float[2]); final float[] dotsPerInch = new float[] { pixelsPerMM[0]*25.4f, pixelsPerMM[1]*25.4f }; dpiH = dotsPerInch[1]; System.err.println(getFontInfo()); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java index f948b9beb..1c4a20bea 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java @@ -145,8 +145,7 @@ public abstract class TextRendererGLELBase implements GLEventListener { final Object upObj = drawable.getUpstreamWidget(); if( upObj instanceof Window ) { - final float[] pixelsPerMM = new float[2]; - ((Window)upObj).getMainMonitor().getPixelsPerMM(pixelsPerMM); + final float[] pixelsPerMM = ((Window)upObj).getPixelsPerMM(new float[2]); dpiH = pixelsPerMM[1]*25.4f; } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java index 89aa4d0ee..76bcfd094 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java @@ -166,7 +166,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB final Object upObj = drawable.getUpstreamWidget(); if( upObj instanceof Window ) { final float[] pixelsPerMM = new float[2]; - ((Window)upObj).getMainMonitor().getPixelsPerMM(pixelsPerMM); + ((Window)upObj).getPixelsPerMM(pixelsPerMM); dpiH = pixelsPerMM[1]*25.4f; } fontNameBox = font.getMetricBounds(fontName, font.getPixelSize(fontSizeFName, dpiH)); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java index 6a1f60de7..fbb29d6ea 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import javax.media.nativewindow.util.Dimension; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLAnimatorControl; @@ -86,7 +87,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { * @see #GPUUISceneGLListener0A(float) * @see #GPUUISceneGLListener0A(float, boolean, boolean) */ - public static final float DefaultNoAADPIThreshold = 180f; + public static final float DefaultNoAADPIThreshold = 200f; private int currentText = 0; @@ -624,12 +625,16 @@ public class GPUUISceneGLListener0A implements GLEventListener { public void init(GLAutoDrawable drawable) { final Object upObj = drawable.getUpstreamWidget(); if( upObj instanceof Window ) { - final float[] pixelsPerMM = new float[2]; - final MonitorDevice mm = ((Window)upObj).getMainMonitor(); - mm.getPixelsPerMM(pixelsPerMM); - dpiH = pixelsPerMM[1]*25.4f; + final Window upWin = (Window)upObj; + final MonitorDevice mm = upWin.getMainMonitor(); + final float[] monitorPixelsPerMM = mm.getPixelsPerMM(new float[2]); + final float monitorDpiH = monitorPixelsPerMM[1]*25.4f; + final float[] surfacePixelsPerMM = upWin.getPixelsPerMM(new float[2]); + dpiH = surfacePixelsPerMM[1]*25.4f; System.err.println("Monitor detected: "+mm); - System.err.println("Using monitor's DPI of "+(pixelsPerMM[0]*25.4f)+" x "+dpiH+" -> "+dpiH); + System.err.println("Monitor dpi: "+monitorDpiH); + System.err.println("Surface scale: native "+new Dimension(upWin.getNativeSurfaceScale(new int[2]))+", current "+new Dimension(upWin.getCurrentSurfaceScale(new int[2]))); + System.err.println("Surface dpi: "+dpiH); } else { System.err.println("Using default DPI of "+dpiH); } @@ -818,7 +823,6 @@ public class GPUUISceneGLListener0A implements GLEventListener { final float dz = 0f; final float dyTop = dh * relTop; - final float dxMiddle = dw * relMiddle; final float dxLeft = dw * relLeft; final float dxRight = dw; diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtCanvasAWTDemo.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtCanvasAWTDemo.java index a80b70830..011b20c35 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtCanvasAWTDemo.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtCanvasAWTDemo.java @@ -4,6 +4,7 @@ import java.awt.Component; import java.awt.Frame; import java.lang.reflect.InvocationTargetException; +import javax.media.nativewindow.ScalableSurface; import javax.media.nativewindow.util.Dimension; import javax.media.nativewindow.util.DimensionImmutable; import javax.media.opengl.GLCapabilities; @@ -29,6 +30,8 @@ public class GPUUISceneNewtCanvasAWTDemo { static boolean GraphMSAAMode = false; static float GraphAutoMode = GPUUISceneGLListener0A.DefaultNoAADPIThreshold; + static int[] reqSurfacePixelScale = new int[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; + static void setComponentSize(final Component comp, final DimensionImmutable new_sz) { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { @@ -80,6 +83,11 @@ public class GPUUISceneNewtCanvasAWTDemo { } else if(args[i].equals("-y")) { i++; y = MiscUtils.atoi(args[i], y); + } else if(args[i].equals("-pixelScale")) { + i++; + final int pS = MiscUtils.atoi(args[i], reqSurfacePixelScale[0]); + reqSurfacePixelScale[0] = pS; + reqSurfacePixelScale[1] = pS; } } } @@ -114,6 +122,8 @@ public class GPUUISceneNewtCanvasAWTDemo { window.setPosition(x, y); window.setSize(width, height); window.setTitle("GraphUI Newt Demo: graph["+Region.getRenderModeString(rmode)+"], msaa "+SceneMSAASamples); + window.setSurfaceScale(reqSurfacePixelScale); + final int[] valReqSurfacePixelScale = window.getRequestedSurfaceScale(new int[2]); GPUUISceneGLListener0A sceneGLListener = 0 < GraphAutoMode ? new GPUUISceneGLListener0A(GraphAutoMode, DEBUG, TRACE) : new GPUUISceneGLListener0A(rmode, DEBUG, TRACE); @@ -142,6 +152,10 @@ public class GPUUISceneNewtCanvasAWTDemo { frame.setVisible(true); } }); + final int[] hasSurfacePixelScale1 = window.getCurrentSurfaceScale(new int[2]); + System.err.println("HiDPI PixelScale: "+reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" (req) -> "+ + valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+ + hasSurfacePixelScale1[0]+"x"+hasSurfacePixelScale1[1]+" (has)"); animator.start(); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java index 3e78360f5..f2fdcb351 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java @@ -122,7 +122,10 @@ public class TestGearsES2NEWT extends UITestCase { private void setTitle(final Window win, final GLCapabilitiesImmutable caps) { final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl"; - win.setTitle("GLWindow["+capsA+"], swapI "+swapInterval+", win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight()); + final float[] sDPI = win.getPixelsPerMM(new float[2]); + sDPI[0] *= 25.4f; + sDPI[1] *= 25.4f; + win.setTitle("GLWindow["+capsA+"], swapI "+swapInterval+", win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight()+", sDPI "+sDPI[0]+" x "+sDPI[1]); } protected void runTestGL(final GLCapabilitiesImmutable caps, boolean undecorated) throws InterruptedException { System.err.println("requested: vsync "+swapInterval+", "+caps); @@ -141,7 +144,6 @@ public class TestGearsES2NEWT extends UITestCase { glWindow.setFullscreen(fullscreen); glWindow.setPointerVisible(mouseVisible); glWindow.confinePointer(mouseConfined); - setTitle(glWindow, caps); final GearsES2 demo = new GearsES2(swapInterval); demo.setPMVUseBackingArray(pmvUseBackingArray); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java index 694efeaf4..08c81c59e 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasAWT.java @@ -181,7 +181,10 @@ public class TestGearsES2NewtCanvasAWT extends UITestCase { final java.awt.Rectangle b = glc.getBounds(); frame.setTitle("NewtCanvasAWT["+capsA+"], swapI "+swapInterval+", win: ["+b.x+"/"+b.y+" "+b.width+"x"+b.height+"], pix: "+glc.getNativeWindow().getSurfaceWidth()+"x"+glc.getNativeWindow().getSurfaceHeight()); } - win.setTitle("GLWindow["+capsA+"], swapI "+swapInterval+", win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight()); + final float[] sDPI = win.getPixelsPerMM(new float[2]); + sDPI[0] *= 25.4f; + sDPI[1] *= 25.4f; + win.setTitle("GLWindow["+capsA+"], swapI "+swapInterval+", win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight()+", sDPI "+sDPI[0]+" x "+sDPI[1]); } // public enum ResizeBy { GLWindow, Component, Frame }; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java index 0384765bf..b9d77ac0c 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java @@ -28,7 +28,10 @@ package com.jogamp.opengl.test.junit.jogl.glsl; import com.jogamp.common.nio.Buffers; -import com.jogamp.newt.MonitorDevice; +import com.jogamp.newt.Window; +import com.jogamp.newt.event.KeyAdapter; +import com.jogamp.newt.event.KeyEvent; +import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.PMVMatrix; import com.jogamp.opengl.util.glsl.ShaderCode; @@ -36,16 +39,18 @@ import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.glsl.ShaderState; import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2; import com.jogamp.opengl.test.junit.util.MiscUtils; -import com.jogamp.opengl.test.junit.util.NEWTGLContext; import com.jogamp.opengl.test.junit.util.UITestCase; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.nio.FloatBuffer; +import javax.media.nativewindow.ScalableSurface; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; import javax.media.opengl.GLUniformData; @@ -56,120 +61,178 @@ import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestRulerNEWT01 extends UITestCase { - static long durationPerTest = 10; // ms + static long durationPerTest = 500; // ms + static int[] reqSurfacePixelScale = new int[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; + static boolean manualTest = false; - @Test - public void test01() throws InterruptedException { - long t0 = System.nanoTime(); - GLProfile.initSingleton(); - long t1 = System.nanoTime(); - // preset .. - final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow( - new GLCapabilities(GLProfile.getGL2ES2()), 640, 480, true); - final GLDrawable drawable = winctx.context.getGLDrawable(); - final GL2ES2 gl = winctx.context.getGL().getGL2ES2(); - System.err.println(winctx.context); - - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - // test code .. - final ShaderState st = new ShaderState(); - - final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, RedSquareES2.class, "shader", - "shader/bin", "default", true); - final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, RedSquareES2.class, "shader", - "shader/bin", "ruler", true); - vp0.defaultShaderCustomization(gl, true, true); - fp0.defaultShaderCustomization(gl, true, true); - - final ShaderProgram sp0 = new ShaderProgram(); - sp0.add(gl, vp0, System.err); - sp0.add(gl, fp0, System.err); - Assert.assertTrue(0 != sp0.program()); - Assert.assertTrue(!sp0.inUse()); - Assert.assertTrue(!sp0.linked()); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - - st.attachShaderProgram(gl, sp0, true); - - final PMVMatrix pmvMatrix = new PMVMatrix(); - final GLUniformData pmvMatrixUniform = new GLUniformData("gcu_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - st.ownUniform(pmvMatrixUniform); - st.uniform(gl, pmvMatrixUniform); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - - final GLUniformData rulerColor= new GLUniformData("gcu_RulerColor", 3, Buffers.newDirectFloatBuffer(3)); - final FloatBuffer rulerColorV = (FloatBuffer) rulerColor.getBuffer(); - rulerColorV.put(0, 0.5f); - rulerColorV.put(1, 0.5f); - rulerColorV.put(2, 0.5f); - st.ownUniform(rulerColor); - st.uniform(gl, rulerColor); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - - Assert.assertNotNull(winctx); - Assert.assertNotNull(winctx.window); - Assert.assertNotNull(winctx.window.getScreen()); - final float[] ppmmStore = { 0f, 0f }; - { - final MonitorDevice monitor = winctx.window.getMainMonitor(); - Assert.assertNotNull(monitor); - System.err.println(monitor); - monitor.getPixelsPerMM(ppmmStore); - } - final GLUniformData rulerPixFreq = new GLUniformData("gcu_RulerPixFreq", 2, Buffers.newDirectFloatBuffer(2)); - final FloatBuffer rulerPixFreqV = (FloatBuffer) rulerPixFreq.getBuffer(); - rulerPixFreqV.put(0, ppmmStore[0] * 10.0f); - rulerPixFreqV.put(1, ppmmStore[1] * 10.0f); - st.ownUniform(rulerPixFreq); - st.uniform(gl, rulerPixFreq); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - System.err.println("Screen pixel/cm "+rulerPixFreqV.get(0)+", "+rulerPixFreqV.get(1)); - - final GLArrayDataServer vertices0 = GLArrayDataServer.createGLSL("gca_Vertices", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); - vertices0.putf(0); vertices0.putf(1); vertices0.putf(0); - vertices0.putf(1); vertices0.putf(1); vertices0.putf(0); - vertices0.putf(0); vertices0.putf(0); vertices0.putf(0); - vertices0.putf(1); vertices0.putf(0); vertices0.putf(0); - vertices0.seal(gl, true); - st.ownAttribute(vertices0, true); - - // misc GL setup - gl.glClearColor(1, 1, 1, 1); - gl.glEnable(GL2ES2.GL_DEPTH_TEST); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - - // reshape - pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); - pmvMatrix.glLoadIdentity(); - pmvMatrix.glOrthof(0f, 1f, 0f, 1f, -10f, 10f); - // pmvMatrix.gluPerspective(45.0F, (float) drawable.getWidth() / (float) drawable.getHeight(), 1.0F, 100.0F); - pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); - pmvMatrix.glLoadIdentity(); - // pmvMatrix.glTranslatef(0, 0, -6); - // pmvMatrix.glRotatef(45f, 1f, 0f, 0f); - st.uniform(gl, pmvMatrixUniform); - gl.glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - - for(int i=0; i<10; i++) { - vertices0.enableBuffer(gl, true); - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); - vertices0.enableBuffer(gl, false); - drawable.swapBuffers(); - Thread.sleep(durationPerTest/10); - } + private void setTitle(final Window win) { + final float[] sDPI = win.getPixelsPerMM(new float[2]); + sDPI[0] *= 25.4f; + sDPI[1] *= 25.4f; + win.setTitle("GLWindow: win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight()+", sDPI "+sDPI[0]+" x "+sDPI[1]); + } + + private void runTestGL() throws InterruptedException { + final GLWindow glWindow = GLWindow.create(new GLCapabilities(GLProfile.getGL2ES2())); + Assert.assertNotNull(glWindow); + glWindow.setSurfaceScale(reqSurfacePixelScale); + final int[] valReqSurfacePixelScale = glWindow.getRequestedSurfaceScale(new int[2]); + glWindow.setSize(640, 480); + + glWindow.addGLEventListener(new GLEventListener() { + final ShaderState st = new ShaderState(); + final PMVMatrix pmvMatrix = new PMVMatrix(); + final GLUniformData pmvMatrixUniform = new GLUniformData("gcu_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); + final GLArrayDataServer vertices0 = GLArrayDataServer.createGLSL("gca_Vertices", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); + final GLUniformData rulerPixFreq = new GLUniformData("gcu_RulerPixFreq", 2, Buffers.newDirectFloatBuffer(2)); + + @Override + public void init(GLAutoDrawable drawable) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, RedSquareES2.class, "shader", + "shader/bin", "default", true); + final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, RedSquareES2.class, "shader", + "shader/bin", "ruler", true); + vp0.defaultShaderCustomization(gl, true, true); + fp0.defaultShaderCustomization(gl, true, true); + + final ShaderProgram sp0 = new ShaderProgram(); + sp0.add(gl, vp0, System.err); + sp0.add(gl, fp0, System.err); + Assert.assertTrue(0 != sp0.program()); + Assert.assertTrue(!sp0.inUse()); + Assert.assertTrue(!sp0.linked()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + st.attachShaderProgram(gl, sp0, true); + + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + st.ownUniform(pmvMatrixUniform); + st.uniform(gl, pmvMatrixUniform); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + final GLUniformData rulerColor= new GLUniformData("gcu_RulerColor", 3, Buffers.newDirectFloatBuffer(3)); + final FloatBuffer rulerColorV = (FloatBuffer) rulerColor.getBuffer(); + rulerColorV.put(0, 0.5f); + rulerColorV.put(1, 0.5f); + rulerColorV.put(2, 0.5f); + st.ownUniform(rulerColor); + st.uniform(gl, rulerColor); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + st.ownUniform(rulerPixFreq); + + vertices0.putf(0); vertices0.putf(1); vertices0.putf(0); + vertices0.putf(1); vertices0.putf(1); vertices0.putf(0); + vertices0.putf(0); vertices0.putf(0); vertices0.putf(0); + vertices0.putf(1); vertices0.putf(0); vertices0.putf(0); + vertices0.seal(gl, true); + st.ownAttribute(vertices0, true); + + // misc GL setup + gl.glClearColor(1, 1, 1, 1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + } - long t2 = System.nanoTime(); + @Override + public void dispose(GLAutoDrawable drawable) { + } + + @Override + public void display(GLAutoDrawable drawable) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + vertices0.enableBuffer(gl, true); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); + vertices0.enableBuffer(gl, false); + } + + @Override + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glOrthof(0f, 1f, 0f, 1f, -10f, 10f); + // pmvMatrix.gluPerspective(45.0F, (float) drawable.getWidth() / (float) drawable.getHeight(), 1.0F, 100.0F); + pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + // pmvMatrix.glTranslatef(0, 0, -6); + // pmvMatrix.glRotatef(45f, 1f, 0f, 0f); + st.uniform(gl, pmvMatrixUniform); + + final float[] ppmmStore = glWindow.getPixelsPerMM(new float[2]); + final FloatBuffer rulerPixFreqV = (FloatBuffer) rulerPixFreq.getBuffer(); + rulerPixFreqV.put(0, ppmmStore[0] * 10.0f); + rulerPixFreqV.put(1, ppmmStore[1] * 10.0f); + st.uniform(gl, rulerPixFreq); + System.err.println("Screen pixel/cm "+rulerPixFreqV.get(0)+", "+rulerPixFreqV.get(1)); + } + + }); + final SnapshotGLEventListener snap = new SnapshotGLEventListener(); + glWindow.addGLEventListener(snap); + glWindow.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(final KeyEvent e) { + if( e.isAutoRepeat() ) { + return; + } + if(e.getKeyChar()=='x') { + final int[] hadSurfacePixelScale = glWindow.getCurrentSurfaceScale(new int[2]); + final int[] reqSurfacePixelScale; + if( hadSurfacePixelScale[0] == ScalableSurface.IDENTITY_PIXELSCALE ) { + reqSurfacePixelScale = new int[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; + } else { + reqSurfacePixelScale = new int[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; + } + System.err.println("[set PixelScale pre]: had "+hadSurfacePixelScale[0]+"x"+hadSurfacePixelScale[1]+" -> req "+reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]); + snap.setMakeSnapshot(); + glWindow.setSurfaceScale(reqSurfacePixelScale); + final int[] valReqSurfacePixelScale = glWindow.getRequestedSurfaceScale(new int[2]); + final int[] hasSurfacePixelScale = glWindow.getCurrentSurfaceScale(new int[2]); + final int[] nativeSurfacePixelScale = glWindow.getNativeSurfaceScale(new int[2]); + System.err.println("[set PixelScale post]: "+hadSurfacePixelScale[0]+"x"+hadSurfacePixelScale[1]+" (had) -> "+ + reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" (req) -> "+ + valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+ + hasSurfacePixelScale[0]+"x"+hasSurfacePixelScale[1]+" (has), "+ + nativeSurfacePixelScale[0]+"x"+nativeSurfacePixelScale[1]+" (native)"); + setTitle(glWindow); + } + } + }); + + glWindow.setVisible(true); - NEWTGLContext.destroyWindow(winctx); + final int[] hasSurfacePixelScale1 = glWindow.getCurrentSurfaceScale(new int[2]); + System.err.println("HiDPI PixelScale: "+reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" (req) -> "+ + valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+ + hasSurfacePixelScale1[0]+"x"+hasSurfacePixelScale1[1]+" (has)"); + setTitle(glWindow); - long t3 = System.nanoTime(); + snap.setMakeSnapshot(); + glWindow.display(); - System.err.println("t1-t0: "+ (t1-t0)/1e6 +"ms"); - System.err.println("t3-t0: "+ (t3-t0)/1e6 +"ms"); - System.err.println("t3-t2: "+ (t3-t2)/1e6 +"ms"); + Thread.sleep(durationPerTest); + + glWindow.destroy(); + + } + + @Test + public void test01_PSA() throws InterruptedException { + runTestGL(); + } + + @Test + public void test99_PS1() throws InterruptedException, InvocationTargetException { + if(manualTest) return; + reqSurfacePixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE; + reqSurfacePixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE; + runTestGL(); } public static void main(String args[]) throws IOException { @@ -177,6 +240,13 @@ public class TestRulerNEWT01 extends UITestCase { for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest); + } else if(args[i].equals("-pixelScale")) { + i++; + final int pS = MiscUtils.atoi(args[i], reqSurfacePixelScale[0]); + reqSurfacePixelScale[0] = pS; + reqSurfacePixelScale[1] = pS; + } else if(args[i].equals("-manual")) { + manualTest = true; } } String tstname = TestRulerNEWT01.class.getName(); |