From 56d60b36798fa8dae48bf2aa5e2de6f3178ab0d1 Mon Sep 17 00:00:00 2001
From: Sven Gothel
* Finally a {@link GLAutoDrawableDelegate} is created with the just created {@link GLDrawable} and {@link GLContext}. - * It is being used to run the {@link GLEventListener}. - *
+ * It is being used to run the {@link GLEventListener}. + * */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { @@ -83,7 +83,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { } return new GLCapabilities(GLProfile.get(profile)); } - + void doTest(GLCapabilitiesImmutable reqGLCaps, GLEventListener demo) throws InterruptedException { System.out.println("Requested GL Caps: "+reqGLCaps); final GLDrawableFactory factory = GLDrawableFactory.getFactory(reqGLCaps.getGLProfile()); @@ -91,7 +91,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { System.out.println("Expected GL Caps: "+expGLCaps); // // Create native windowing resources .. X11/Win/OSX - // + // final Window window = NewtFactory.createWindow(reqGLCaps); Assert.assertNotNull(window); window.setSize(widthStep*szStep, heightStep*szStep); @@ -99,7 +99,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { Assert.assertTrue(AWTRobotUtil.waitForVisible(window, true)); Assert.assertTrue(AWTRobotUtil.waitForRealized(window, true)); System.out.println("Window: "+window.getClass().getName()); - + // Check caps of NativeWindow config w/o GL final CapabilitiesImmutable chosenCaps = window.getGraphicsConfiguration().getChosenCapabilities(); System.out.println("Window Caps Pre_GL: "+chosenCaps); @@ -109,13 +109,13 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { Assert.assertTrue(chosenCaps.getRedBits()>5); // - // Create native OpenGL resources .. XGL/WGL/CGL .. + // Create native OpenGL resources .. XGL/WGL/CGL .. // equivalent to GLAutoDrawable methods: setVisible(true) - // + // final GLDrawable drawable = factory.createGLDrawable(window); Assert.assertNotNull(drawable); System.out.println("Drawable Pre-GL(0): "+drawable.getClass().getName()+", "+drawable.getNativeSurface().getClass().getName()); - + // drawable.setRealized(true); Assert.assertTrue(drawable.isRealized()); @@ -123,13 +123,13 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { System.out.println("Window Caps PostGL : "+window.getGraphicsConfiguration().getChosenCapabilities()); System.out.println("Drawable Post-GL(1): "+drawable.getClass().getName()+", "+drawable.getNativeSurface().getClass().getName()); - // Note: FBO Drawable realization happens at 1st context.makeCurrent(), + // Note: FBO Drawable realization happens at 1st context.makeCurrent(), // and hence only then it's caps can _fully_ reflect expectations, // i.e. depth, stencil and MSAA will be valid only after makeCurrent(), // where on-/offscreen state after setRealized(true) // See GLFBODrawable API doc in this regard! - - + + final GLCapabilitiesImmutable chosenGLCaps01 = drawable.getChosenGLCapabilities(); System.out.println("Chosen GL Caps(1): "+chosenGLCaps01); Assert.assertNotNull(chosenGLCaps01); @@ -137,13 +137,13 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps01.isFBO()); Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps01.isPBuffer()); Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps01.isBitmap()); - + final GLContext context = drawable.createContext(null); Assert.assertNotNull(context); int res = context.makeCurrent(); Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW==res || GLContext.CONTEXT_CURRENT==res); context.release(); - + // Check caps of GLDrawable after realization final GLCapabilitiesImmutable chosenGLCaps02 = drawable.getChosenGLCapabilities(); System.out.println("Chosen GL Caps(2): "+chosenGLCaps02); @@ -158,12 +158,12 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps02.isFBO()); Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps02.isPBuffer()); Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps02.isBitmap()); - /** Single/Double buffer cannot be checked since result may vary .. + /** Single/Double buffer cannot be checked since result may vary .. if(chosenGLCaps.isOnscreen() || chosenGLCaps.isFBO()) { // dbl buffer may be disabled w/ offscreen pbuffer and bitmap Assert.assertEquals(expGLCaps.getDoubleBuffered(), chosenGLCaps.getDoubleBuffered()); } */ - + final GLAutoDrawableDelegate glad = new GLAutoDrawableDelegate(drawable, context, window, false, null) { @Override protected void destroyImplInLock() { @@ -171,12 +171,12 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { window.destroy(); // destroys the actual window, incl. the device } }; - + window.setWindowDestroyNotifyAction( new Runnable() { public void run() { glad.windowDestroyNotifyOp(); } } ); - + window.addWindowListener(new WindowAdapter() { @Override public void windowRepaint(WindowUpdateEvent e) { @@ -190,38 +190,45 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { }); glad.addGLEventListener(demo); - + final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); glad.addGLEventListener(snapshotGLEventListener); - + glad.display(); // initial resize/display - + // 1 - szStep = 2 - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + final int[] expSurfaceSize = glad.getNativeSurface().convertToPixelUnits(new int[] { widthStep*szStep, heightStep*szStep }); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 2, 3 (resize + display) szStep = 1; window.setSize(widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 4, 5 (resize + display) szStep = 4; window.setSize(widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + Thread.sleep(50); - + glad.destroy(); - System.out.println("Fin Drawable: "+drawable); + System.out.println("Fin Drawable: "+drawable); System.out.println("Fin Window: "+window); } @@ -236,7 +243,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { System.err.println(JoglVersion.getDefaultOpenGLInfo(f.getDefaultDevice(), null, true).toString()); } } - + @Test public void testGL2OnScreenSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -244,14 +251,14 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); if(null == reqGLCaps) return; doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenAutoDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -269,7 +276,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -278,7 +285,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setFBO(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenPbufferDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -287,7 +294,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setPBuffer(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenPbufferSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -297,7 +304,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenBitmapSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -307,7 +314,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new Gears(1)); } - + @Test public void testES2OnScreenSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -315,14 +322,14 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OnScreenDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); if(null == reqGLCaps) return; doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenAutoDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -340,7 +347,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenFBODblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -349,7 +356,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setFBO(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenPbufferDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -358,7 +365,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setPBuffer(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenPbufferSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -368,19 +375,19 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + /** Not implemented ! @Test public void testES2OffScreenBitmapDblBuf() throws InterruptedException { if(!checkProfile(GLProfile.GLES2)) { return; } - final GLCapabilities reqGLCaps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); + final GLCapabilities reqGLCaps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); reqGLCaps.setOnscreen(false); reqGLCaps.setBitmap(true); doTest(reqGLCaps, new GearsES2(1)); } */ - + public static void main(String args[]) throws IOException { org.junit.runner.JUnitCore.main(TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT.java index 888572444..2d231fb6d 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,12 +20,12 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.jogl.acore; import java.awt.Dimension; @@ -74,7 +74,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { } return new GLCapabilities(GLProfile.get(profile)); } - + static void setGLCanvasSize(final Frame frame, final GLCanvas glc, final int width, final int height) { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { @@ -89,13 +89,13 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } } - + static interface MyGLEventListener extends GLEventListener { void setMakeSnapshot(); } - + void doTest(GLCapabilitiesImmutable reqGLCaps, GLEventListener demo) throws InterruptedException { if(reqGLCaps.isOnscreen() && JAWTUtil.isOffscreenLayerRequired()) { System.err.println("onscreen layer n/a"); @@ -120,8 +120,8 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { glad.setSize(glc_sz); final Frame frame = new Frame(getSimpleTestName(".")); Assert.assertNotNull(frame); - frame.add(glad); - + frame.add(glad); + try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -132,11 +132,11 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { throwable.printStackTrace(); Assume.assumeNoException( throwable ); } - + Assert.assertTrue(AWTRobotUtil.waitForVisible(glad, true)); Assert.assertTrue(AWTRobotUtil.waitForRealized(glad, true)); System.out.println("Window: "+glad.getClass().getName()); - + // Check caps of NativeWindow config w/o GL final CapabilitiesImmutable chosenCaps = glad.getChosenGLCapabilities(); System.out.println("Window Caps Pre_GL: "+chosenCaps); @@ -146,20 +146,20 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { Assert.assertTrue(chosenCaps.getRedBits()>5); glad.display(); // force native context creation - + // - // Create native OpenGL resources .. XGL/WGL/CGL .. + // Create native OpenGL resources .. XGL/WGL/CGL .. // equivalent to GLAutoDrawable methods: setVisible(true) - // + // { final GLDrawable actualDrawable = glad.getDelegatedDrawable(); Assert.assertNotNull(actualDrawable); System.out.println("Drawable Pre-GL(0): "+actualDrawable.getClass().getName()+", "+actualDrawable.getNativeSurface().getClass().getName()); } - + System.out.println("Window Caps PostGL : "+glad.getChosenGLCapabilities()); System.out.println("Drawable Post-GL(1): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName()); - + // Check caps of GLDrawable after realization final GLCapabilitiesImmutable chosenGLCaps = glad.getChosenGLCapabilities(); System.out.println("Chosen GL Caps(1): "+chosenGLCaps); @@ -172,7 +172,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps.isFBO()); Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps.isPBuffer()); Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps.isBitmap()); - /** Single/Double buffer cannot be checked since result may vary .. + /** Single/Double buffer cannot be checked since result may vary .. if(chosenGLCaps.isOnscreen() || chosenGLCaps.isFBO()) { // dbl buffer may be disabled w/ offscreen pbuffer and bitmap Assert.assertEquals(expGLCaps.getDoubleBuffered(), chosenGLCaps.getDoubleBuffered()); @@ -184,43 +184,50 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { Assert.assertNotNull(context); Assert.assertTrue(context.isCreated()); } - + System.out.println("Chosen GL Caps(2): "+glad.getChosenGLCapabilities()); System.out.println("Drawable Post-GL(2): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName()); - + glad.addGLEventListener(demo); - + final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); glad.addGLEventListener(snapshotGLEventListener); - + glad.display(); // initial resize/display - + // 1 - szStep = 2 - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + final int[] expSurfaceSize = glad.getNativeSurface().convertToPixelUnits(new int[] { widthStep*szStep, heightStep*szStep }); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 2, 3 (resize + display) szStep = 1; setGLCanvasSize(frame, glad, widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); glad.display(); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 4, 5 (resize + display) szStep = 4; setGLCanvasSize(frame, glad, widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); glad.display(); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + Thread.sleep(50); - + try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -231,7 +238,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } System.out.println("Fin: "+glad); } @@ -246,14 +253,14 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { System.err.println(JoglVersion.getDefaultOpenGLInfo(f.getDefaultDevice(), null, true).toString()); } } - + @Test public void testGL2OnScreenDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); if(null == reqGLCaps) return; doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufStencil() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -261,7 +268,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setStencilBits(1); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -270,7 +277,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -280,7 +287,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenAutoDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -298,7 +305,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setStencilBits(1); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -309,7 +316,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -321,7 +328,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenPbuffer() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -330,7 +337,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setPBuffer(true); doTest(reqGLCaps, new GearsES2(1)); } - + public static void main(String args[]) throws IOException { for(int i=0; i- * The NEWT {@link GLAutoDrawable} is being used to run the {@link GLEventListener}. - *
+ * The NEWT {@link GLAutoDrawable} is being used to run the {@link GLEventListener}. + * */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase { @@ -79,7 +79,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase } return new GLCapabilities(GLProfile.get(profile)); } - + static void setComponentSize(final Frame frame, final Component comp, final int width, final int height) { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { @@ -94,13 +94,13 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } } - + static interface MyGLEventListener extends GLEventListener { void setMakeSnapshot(); } - + void doTest(boolean offscreenLayer, GLCapabilitiesImmutable reqGLCaps, GLEventListener demo) throws InterruptedException { if(!offscreenLayer && JAWTUtil.isOffscreenLayerRequired()) { System.err.println("onscreen layer n/a"); @@ -112,16 +112,16 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase } System.out.println("Requested GL Caps: "+reqGLCaps); final GLDrawableFactory factory = GLDrawableFactory.getFactory(reqGLCaps.getGLProfile()); - final AbstractGraphicsDevice device = factory.getDefaultDevice(); + final AbstractGraphicsDevice device = factory.getDefaultDevice(); final GLCapabilitiesImmutable expGLCaps = offscreenLayer ? GLGraphicsConfigurationUtil.fixOffscreenGLCapabilities(reqGLCaps, factory, device) : GLGraphicsConfigurationUtil.fixGLCapabilities(reqGLCaps, factory, device); System.out.println("Expected GL Caps: "+expGLCaps); - + final GLWindow glad = GLWindow.create(reqGLCaps); Assert.assertNotNull(glad); - + final NewtCanvasAWT nca = new NewtCanvasAWT(glad); Assert.assertNotNull(nca); Dimension size0 = new Dimension(widthStep*szStep, heightStep*szStep); @@ -129,11 +129,11 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase nca.setPreferredSize(size0); nca.setMinimumSize(size0); nca.setSize(size0); - + final Frame frame = new Frame(getSimpleTestName(".")); Assert.assertNotNull(frame); - frame.add(nca); - + frame.add(nca); + try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -144,11 +144,11 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase throwable.printStackTrace(); Assume.assumeNoException( throwable ); } - + Assert.assertTrue(AWTRobotUtil.waitForVisible(glad, true)); Assert.assertTrue(AWTRobotUtil.waitForRealized(glad, true)); System.out.println("Window: "+glad.getClass().getName()); - + // Check caps of NativeWindow config w/o GL final CapabilitiesImmutable chosenCaps = glad.getChosenGLCapabilities(); System.out.println("Window Caps Pre_GL: "+chosenCaps); @@ -158,20 +158,20 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase Assert.assertTrue(chosenCaps.getRedBits()>5); glad.display(); // force native context creation - + // - // Create native OpenGL resources .. XGL/WGL/CGL .. + // Create native OpenGL resources .. XGL/WGL/CGL .. // equivalent to GLAutoDrawable methods: setVisible(true) - // + // { final GLDrawable actualDrawable = glad.getDelegatedDrawable(); Assert.assertNotNull(actualDrawable); System.out.println("Drawable Pre-GL(0): "+actualDrawable.getClass().getName()+", "+actualDrawable.getNativeSurface().getClass().getName()); } - + System.out.println("Window Caps PostGL : "+glad.getChosenGLCapabilities()); System.out.println("Drawable Post-GL(1): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName()); - + // Check caps of GLDrawable after realization final GLCapabilitiesImmutable chosenGLCaps = glad.getChosenGLCapabilities(); System.out.println("Chosen GL Caps(1): "+chosenGLCaps); @@ -184,7 +184,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps.isFBO()); Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps.isPBuffer()); Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps.isBitmap()); - /** Single/Double buffer cannot be checked since result may vary .. + /** Single/Double buffer cannot be checked since result may vary .. if(chosenGLCaps.isOnscreen() || chosenGLCaps.isFBO()) { // dbl buffer may be disabled w/ offscreen pbuffer and bitmap Assert.assertEquals(expGLCaps.getDoubleBuffered(), chosenGLCaps.getDoubleBuffered()); @@ -196,43 +196,50 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase Assert.assertNotNull(context); Assert.assertTrue(context.isCreated()); } - + System.out.println("Chosen GL Caps(2): "+glad.getChosenGLCapabilities()); System.out.println("Drawable Post-GL(2): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName()); - + glad.addGLEventListener(demo); - + final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); glad.addGLEventListener(snapshotGLEventListener); - + glad.display(); // initial resize/display - + // 1 - szStep = 2 - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + final int[] expSurfaceSize = glad.getNativeSurface().convertToPixelUnits(new int[] { widthStep*szStep, heightStep*szStep }); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 2, 3 (resize + display) szStep = 1; setComponentSize(frame, nca, widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); glad.display(); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 4, 5 (resize + display) szStep = 4; setComponentSize(frame, nca, widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); glad.display(); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + Thread.sleep(50); - + try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -243,7 +250,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } glad.destroy(); System.out.println("Fin: "+nca); System.out.println("Fin: "+glad); @@ -260,14 +267,14 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase System.err.println(JoglVersion.getDefaultOpenGLInfo(f.getDefaultDevice(), null, true).toString()); } } - + @Test public void testGL2OnScreenDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); if(null == reqGLCaps) return; doTest(false, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufStencil() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -275,7 +282,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setStencilBits(1); doTest(false, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -284,7 +291,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setNumSamples(4); doTest(false, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -294,7 +301,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setNumSamples(4); doTest(false, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenLayerAutoDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -311,7 +318,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setStencilBits(1); doTest(true, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -322,7 +329,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setNumSamples(4); doTest(true, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -334,7 +341,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setNumSamples(4); doTest(true, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenPbuffer() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -343,7 +350,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setOnscreen(true); // get native NEWT Window, not OffscreenWindow doTest(true, reqGLCaps, new GearsES2(1)); } - + public static void main(String args[]) throws IOException { org.junit.runner.JUnitCore.main(TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGPUMemSec01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGPUMemSec01NEWT.java index 93713c783..173df57f6 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGPUMemSec01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGPUMemSec01NEWT.java @@ -54,12 +54,12 @@ public class TestGPUMemSec01NEWT extends UITestCase { return "0x"+Integer.toHexString(i); } static String exceptionMsg(String pre, int format, int type, int components, int width, int height, int rl1, int rl4, int rl8) { - return pre + + return pre + ": fmt "+hexString(format)+", type "+hexString(type)+", comps "+components+ ", "+width+"x"+height+ - ", rowlenA1 "+rl1+", rowlenA4 "+rl4+", rowlenA8 "+rl8; + ", rowlenA1 "+rl1+", rowlenA4 "+rl4+", rowlenA8 "+rl8; } - + static NEWTGLContext.WindowContext createCurrentGLOffscreenWindow(GLProfile glp, int width, int height) throws GLException, InterruptedException { final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOffscreenWindow( new GLCapabilities(glp), width, height, true); @@ -68,34 +68,34 @@ public class TestGPUMemSec01NEWT extends UITestCase { // System.err.println("Pre GL Error: 0x"+Integer.toHexString(gl.glGetError())); // System.err.println(winctx.drawable); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - + // misc GL setup gl.glClearColor(1, 1, 1, 1); gl.glEnable(GL.GL_DEPTH_TEST); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - gl.glViewport(0, 0, width, height); + gl.glViewport(0, 0, width, height); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - + return winctx; } - + static int readPixelsCheck(GL gl, int format, int type, int components, int width, int height) throws InterruptedException { int expectedExceptions = 0; - - final int rowlenA1 = width * components; - - final int rowlenA4 = ( ( width * components + 3 ) / 4 ) * 4 ; + + final int rowlenA1 = width * components; + + final int rowlenA4 = ( ( width * components + 3 ) / 4 ) * 4 ; Assert.assertTrue(rowlenA4 % 4 == 0); final int rowlenA8 = ( ( width * components + 7 ) / 8 ) * 8 ; Assert.assertTrue(rowlenA8 % 8 == 0); - + GLPixelStorageModes psm = new GLPixelStorageModes(); psm.setPackAlignment(gl, 1); - + Exception ee = null; - + // ok size ! try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1); @@ -105,11 +105,11 @@ public class TestGPUMemSec01NEWT extends UITestCase { ee = e; } Assert.assertNull( - exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 1)", + exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 1)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); ee = null; - - + + // too small -10 ! try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1-10); @@ -118,16 +118,16 @@ public class TestGPUMemSec01NEWT extends UITestCase { } catch(IndexOutOfBoundsException e) { ee = e; System.err.println( - exceptionMsg("OK Expected IndexOutOfBoundsException (size-10 bytes)", + exceptionMsg("OK Expected IndexOutOfBoundsException (size-10 bytes)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+ ": "+ee.getMessage()); - expectedExceptions++; + expectedExceptions++; } Assert.assertNotNull( - exceptionMsg("Expected IndexOutOfBoundsException (size-10 bytes)", + exceptionMsg("Expected IndexOutOfBoundsException (size-10 bytes)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); ee = null; - + // too small size/4 ! try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1/4); @@ -136,21 +136,21 @@ public class TestGPUMemSec01NEWT extends UITestCase { } catch(IndexOutOfBoundsException e) { ee = e; System.err.println( - exceptionMsg("OK Expected IndexOutOfBoundsException (size/4 bytes)", + exceptionMsg("OK Expected IndexOutOfBoundsException (size/4 bytes)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+ ": "+ee.getMessage()); - expectedExceptions++; + expectedExceptions++; } Assert.assertNotNull( - exceptionMsg("Expected IndexOutOfBoundsException (size/4 bytes)", + exceptionMsg("Expected IndexOutOfBoundsException (size/4 bytes)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); ee = null; // // Alignment test - // + // psm.setPackAlignment(gl, 4); - + // ok size ! try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA4); @@ -160,10 +160,10 @@ public class TestGPUMemSec01NEWT extends UITestCase { ee = e; } Assert.assertNull( - exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 4)", + exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 4)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); ee = null; - + // too small if rowlenA1%4 > 0 try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1); @@ -173,7 +173,7 @@ public class TestGPUMemSec01NEWT extends UITestCase { ee = e; if(rowlenA1%4>0) { System.err.println( - exceptionMsg("OK Expected IndexOutOfBoundsException (alignment 4)", + exceptionMsg("OK Expected IndexOutOfBoundsException (alignment 4)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+ ": "+ee.getMessage()); expectedExceptions++; @@ -181,17 +181,17 @@ public class TestGPUMemSec01NEWT extends UITestCase { } if(rowlenA1%4>0) { Assert.assertNotNull( - exceptionMsg("Expected IndexOutOfBoundsException (alignment 4)", + exceptionMsg("Expected IndexOutOfBoundsException (alignment 4)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); } else { Assert.assertNull( - exceptionMsg("Unexpected IndexOutOfBoundsException (alignment 4)", - format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); + exceptionMsg("Unexpected IndexOutOfBoundsException (alignment 4)", + format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); } ee = null; - + psm.setPackAlignment(gl, 8); - + // ok size ! try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA8); @@ -201,10 +201,10 @@ public class TestGPUMemSec01NEWT extends UITestCase { ee = e; } Assert.assertNull( - exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 8)", + exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 8)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); ee = null; - + // too small if rowlenA1%8 > 0 try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1); @@ -214,7 +214,7 @@ public class TestGPUMemSec01NEWT extends UITestCase { ee = e; if(rowlenA1%8>0) { System.err.println( - exceptionMsg("OK Expected IndexOutOfBoundsException (alignment 8)", + exceptionMsg("OK Expected IndexOutOfBoundsException (alignment 8)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+ ": "+ee.getMessage()); expectedExceptions++; @@ -222,37 +222,37 @@ public class TestGPUMemSec01NEWT extends UITestCase { } if(rowlenA1%8>0) { Assert.assertNotNull( - exceptionMsg("Expected IndexOutOfBoundsException (alignment 8)", + exceptionMsg("Expected IndexOutOfBoundsException (alignment 8)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); } else { Assert.assertNull( - exceptionMsg("Unexpected IndexOutOfBoundsException (alignment 8)", - format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); + exceptionMsg("Unexpected IndexOutOfBoundsException (alignment 8)", + format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); } ee = null; - - psm.restore(gl); - - return expectedExceptions; + + psm.restore(gl); + + return expectedExceptions; } - + @Test public void testReadPixelsGL_640x480xRGBAxUB() throws InterruptedException { GLProfile glp = GLProfile.getDefault(); final int width = 640; final int height= 480; - + // preset .. final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, width, height); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL gl = winctx.context.getGL(); - + // 2 x too small - 0 x alignment Assert.assertEquals(2, readPixelsCheck(gl, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, 4, width, height)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } @@ -263,21 +263,21 @@ public class TestGPUMemSec01NEWT extends UITestCase { final int wheight= 480; final int rwidth = 99; final int rheight= 100; - + // preset .. final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, wwidth, wheight); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL gl = winctx.context.getGL(); - + // 2 x too small - 1 x alignment Assert.assertEquals(3, readPixelsCheck(gl, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, 4, rwidth, rheight)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } - + @Test public void testReadPixelsGL2GL3_640x480xRGBxUB() throws InterruptedException { GLProfile glp = GLProfile.getGL2ES2(); @@ -287,21 +287,21 @@ public class TestGPUMemSec01NEWT extends UITestCase { } final int width = 640; final int height= 480; - + // preset .. final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, width, height); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL gl = winctx.context.getGL(); - + // 2 x too small - 0 x alignment Assert.assertEquals(2, readPixelsCheck(gl, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, 3, width, height)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } - + @Test public void testReadPixelsGL2GL3_99x100xRGBxUB() throws InterruptedException { GLProfile glp = GLProfile.getGL2ES2(); @@ -313,21 +313,21 @@ public class TestGPUMemSec01NEWT extends UITestCase { final int wheight= 480; final int rwidth = 99; final int rheight= 100; - + // preset .. final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, wwidth, wheight); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL gl = winctx.context.getGL(); - + // 2 x too small - 2 x alignment Assert.assertEquals(4, readPixelsCheck(gl, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, 3, rwidth, rheight)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } - + @Test public void testReadPixelsGL2GL3_640x480xREDxUB() throws InterruptedException { GLProfile glp = GLProfile.getGL2ES2(); @@ -342,13 +342,13 @@ public class TestGPUMemSec01NEWT extends UITestCase { final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, width, height); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL2GL3 gl = winctx.context.getGL().getGL2GL3(); - + // 2 x too small - 0 x alignment Assert.assertEquals(2, readPixelsCheck(gl, GL2ES2.GL_RED, GL.GL_UNSIGNED_BYTE, 1, width, height)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } @@ -368,19 +368,19 @@ public class TestGPUMemSec01NEWT extends UITestCase { final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, wwidth, wheight); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL2GL3 gl = winctx.context.getGL().getGL2GL3(); - + // 2 x too small - 2 x alignment Assert.assertEquals(4, readPixelsCheck(gl, GL2ES2.GL_RED, GL.GL_UNSIGNED_BYTE, 1, rwidth, rheight)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } - + public static void main(String args[]) throws IOException { String tstname = TestGPUMemSec01NEWT.class.getName(); org.junit.runner.JUnitCore.main(tstname); - } + } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/ManualHiDPIBufferedImage01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/ManualHiDPIBufferedImage01AWT.java new file mode 100644 index 000000000..0b67cfe46 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/ManualHiDPIBufferedImage01AWT.java @@ -0,0 +1,71 @@ +package com.jogamp.opengl.test.junit.jogl.awt; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.lang.reflect.InvocationTargetException; + +import javax.swing.JCheckBox; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +/** + * Manual test for BufferedImage behavior w/ OSX HiDPI pixel scale usage. + */ +public class ManualHiDPIBufferedImage01AWT { + + static final int width = 200; + static final int height = 100; + + public static void main(String[] args) throws InterruptedException, InvocationTargetException { + final JFrame frame = new JFrame(); + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + final Image image1 = getImage(getCheckBox("High-DPI (no)", false), width, height, 1); + final Image image2 = getImage(getCheckBox("High-DPI (yes)", true), width, height, 2); + System.err.println("Image1: "+image1); + System.err.println("Image2: "+image2); + + @SuppressWarnings("serial") + final Canvas canvas = new Canvas() { + @Override + public void paint(Graphics g) { + super.paint(g); + g.drawImage(image1, 0, 0, width, height, this); + g.drawImage(image2, 0, height + 5, width, height, this); + } + }; + frame.getContentPane().add(getCheckBox("High-DPI (ref)", false), BorderLayout.NORTH); + frame.getContentPane().add(canvas, BorderLayout.CENTER); + + frame.setBounds((1440-400)/2, 100, 400, 400); + frame.validate(); + frame.setVisible(true); + } + }); + } + + static JCheckBox getCheckBox(String text, boolean selected) { + JCheckBox checkBox = new JCheckBox(text); + checkBox.setSelected(selected); + checkBox.setSize(new Dimension(width, height)); + return checkBox; + } + + static Image getImage(JComponent component, int width, int height, int scale) { + final BufferedImage image = new BufferedImage(width*scale, height*scale, BufferedImage.TYPE_INT_ARGB); + final Graphics g = image.getGraphics(); + ((Graphics2D) g).scale(scale, scale); + component.paint(g); + g.dispose(); + + return image; + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java index 116d5d245..42c1234da 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java @@ -561,7 +561,7 @@ public class MovieCube implements GLEventListener { anim.stop(); } }); - window.setSurfaceSize(width, height); + window.setSize(width, height); window.setVisible(true); System.err.println("Chosen: "+window.getChosenGLCapabilities()); anim.start(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java index 1997739e3..7b6dd162a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java @@ -1050,7 +1050,7 @@ public class MovieSimple implements GLEventListener { mss[i].mPlayer.addEventListener(myGLMediaEventListener); windows[i].setTitle("Player "+i); - windows[i].setSurfaceSize(width, height); + windows[i].setSize(width, height); windows[i].setVisible(true); anim.add(windows[i]); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java index 96a120c62..d9839c057 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,17 +20,18 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ - + package com.jogamp.opengl.test.junit.jogl.demos.es2.awt; import javax.media.opengl.*; import com.jogamp.opengl.util.Animator; + import javax.media.opengl.awt.GLCanvas; import com.jogamp.common.os.Platform; @@ -38,7 +39,6 @@ import com.jogamp.newt.event.awt.AWTKeyAdapter; import com.jogamp.newt.event.awt.AWTWindowAdapter; import com.jogamp.newt.event.TraceKeyAdapter; import com.jogamp.newt.event.TraceWindowAdapter; - import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import com.jogamp.opengl.test.junit.util.AWTRobotUtil; import com.jogamp.opengl.test.junit.util.MiscUtils; @@ -53,6 +53,8 @@ import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Frame; import java.awt.TextArea; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -70,12 +72,13 @@ import org.junit.runners.MethodSorters; public class TestGearsES2AWT extends UITestCase { public enum FrameLayout { None, TextOnBottom, BorderCenterSurrounded, DoubleBorderCenterSurrounded }; public enum ResizeBy { Component, Frame }; - - static long duration = 500; // ms - static int width, height; + + static long duration = 500; // ms + static int width = 640, height = 480; + static int xpos = 10, ypos = 10; static FrameLayout frameLayout = FrameLayout.None; static ResizeBy resizeBy = ResizeBy.Component; - + static boolean forceES2 = false; static boolean forceGL3 = false; static boolean mainRun = false; @@ -94,8 +97,6 @@ public class TestGearsES2AWT extends UITestCase { @BeforeClass public static void initClass() { - width = 640; - height = 480; try { EventQueue.invokeAndWait(new Runnable() { public void run() { @@ -125,7 +126,7 @@ public class TestGearsES2AWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } } static void setFrameSize(final Frame frame, final boolean frameLayout, final java.awt.Dimension new_sz) { try { @@ -139,9 +140,9 @@ public class TestGearsES2AWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } } - + static void setSize(final ResizeBy resizeBy, final Frame frame, final boolean frameLayout, final Component comp, final java.awt.Dimension new_sz) { switch( resizeBy ) { case Component: @@ -150,17 +151,24 @@ public class TestGearsES2AWT extends UITestCase { case Frame: setFrameSize(frame, frameLayout, new_sz); break; - } + } + } + + private void setTitle(final Frame frame, final GLCanvas glc, final GLCapabilitiesImmutable caps) { + final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl"; + final java.awt.Rectangle b = glc.getBounds(); + frame.setTitle("GLCanvas["+capsA+"], swapI "+swapInterval+", win: ["+b.x+"/"+b.y+" "+b.width+"x"+b.height+"], pix: "+glc.getSurfaceWidth()+"x"+glc.getSurfaceHeight()); } - - protected void runTestGL(GLCapabilities caps, final ResizeBy resizeBy, FrameLayout frameLayout) throws InterruptedException, InvocationTargetException { + + protected void runTestGL(final GLCapabilities caps, final ResizeBy resizeBy, FrameLayout frameLayout) throws InterruptedException, InvocationTargetException { final Frame frame = new Frame("GearsES2 AWT Test"); Assert.assertNotNull(frame); final GLCanvas glCanvas = new GLCanvas(caps); Assert.assertNotNull(glCanvas); setSize(resizeBy, frame, false, glCanvas, new Dimension(width, height)); - + frame.setLocation(xpos, ypos); + switch( frameLayout) { case None: frame.add(glCanvas); @@ -174,7 +182,7 @@ public class TestGearsES2AWT extends UITestCase { frame.setLayout(new BorderLayout()); frame.add(ta, BorderLayout.SOUTH); frame.add(glCanvas, BorderLayout.CENTER); - break; + break; case BorderCenterSurrounded: frame.setLayout(new BorderLayout()); frame.add(new Button("NORTH"), BorderLayout.NORTH); @@ -191,7 +199,7 @@ public class TestGearsES2AWT extends UITestCase { c.add(new Button("east"), BorderLayout.EAST); c.add(new Button("west"), BorderLayout.WEST); c.add(glCanvas, BorderLayout.CENTER); - + frame.setLayout(new BorderLayout()); frame.add(new Button("NORTH"), BorderLayout.NORTH); frame.add(new Button("SOUTH"), BorderLayout.SOUTH); @@ -200,11 +208,29 @@ public class TestGearsES2AWT extends UITestCase { frame.add(c, BorderLayout.CENTER); break; } - frame.setTitle("Gears AWT Test (translucent "+!caps.isBackgroundOpaque()+"), swapInterval "+swapInterval); + setTitle(frame, glCanvas, caps); + + frame.addComponentListener(new ComponentListener() { + @Override + public void componentResized(ComponentEvent e) { + setTitle(frame, glCanvas, caps); + } + + @Override + public void componentMoved(ComponentEvent e) { + setTitle(frame, glCanvas, caps); + } + + @Override + public void componentShown(ComponentEvent e) { } + + @Override + public void componentHidden(ComponentEvent e) { } + }); final GearsES2 demo = new GearsES2(swapInterval); glCanvas.addGLEventListener(demo); - + final SnapshotGLEventListener snap = new SnapshotGLEventListener(); glCanvas.addGLEventListener(snap); @@ -222,13 +248,13 @@ public class TestGearsES2AWT extends UITestCase { if( ResizeBy.Frame == resizeBy ) { frame.validate(); } else { - frame.pack(); - } + frame.pack(); + } frame.setVisible(true); - }}); + }}); Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); - Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true)); - + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true)); + if( useAnimator ) { animator.start(); Assert.assertTrue(animator.isStarted()); @@ -236,19 +262,19 @@ public class TestGearsES2AWT extends UITestCase { Assert.assertEquals(exclusiveContext ? awtEDT : null, glCanvas.getExclusiveContextThread()); animator.setUpdateFPSFrames(60, System.err); } - + System.err.println("canvas pos/siz: "+glCanvas.getX()+"/"+glCanvas.getY()+" "+glCanvas.getSurfaceWidth()+"x"+glCanvas.getSurfaceHeight()); snap.setMakeSnapshot(); - + if( null != rwsize ) { - Thread.sleep(500); // 500ms delay + Thread.sleep(500); // 500ms delay setSize(resizeBy, frame, true, glCanvas, rwsize); System.err.println("window resize pos/siz: "+glCanvas.getX()+"/"+glCanvas.getY()+" "+glCanvas.getSurfaceWidth()+"x"+glCanvas.getSurfaceHeight()); } - + snap.setMakeSnapshot(); - + final long t0 = System.currentTimeMillis(); long t1 = t0; while(!quitAdapter.shouldQuit() && t1 - t0 < duration) { @@ -258,7 +284,7 @@ public class TestGearsES2AWT extends UITestCase { Assert.assertNotNull(frame); Assert.assertNotNull(glCanvas); - + if( useAnimator ) { Assert.assertNotNull(animator); Assert.assertEquals(exclusiveContext ? awtEDT : null, glCanvas.getExclusiveContextThread()); @@ -317,7 +343,7 @@ public class TestGearsES2AWT extends UITestCase { @Test public void test02_GLES2() throws InterruptedException, InvocationTargetException { if(mainRun) return; - + if( !GLProfile.isAvailable(GLProfile.GLES2) ) { System.err.println("GLES2 n/a"); return; @@ -326,11 +352,11 @@ public class TestGearsES2AWT extends UITestCase { final GLCapabilities caps = new GLCapabilities( glp ); runTestGL(caps, resizeBy, frameLayout); } - + @Test public void test03_GL3() throws InterruptedException, InvocationTargetException { if(mainRun) return; - + if( !GLProfile.isAvailable(GLProfile.GL3) ) { System.err.println("GL3 n/a"); return; @@ -339,16 +365,28 @@ public class TestGearsES2AWT extends UITestCase { final GLCapabilities caps = new GLCapabilities( glp ); runTestGL(caps, resizeBy, frameLayout); } - + public static void main(String args[]) { boolean waitForKey = false; int rw=-1, rh=-1; - + mainRun = true; for(int i=0; i@@ -62,16 +66,19 @@ import javax.media.nativewindow.util.Dimension; *
* Documents remedy B) for NV RANDR/GL bug *
- * + * * @see TestScreenMode01dNEWT#cleanupGL() */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestScreenMode01aNEWT extends UITestCase { static GLProfile glp; static int width, height; - - static int waitTimeShort = 2000; - static int waitTimeLong = 2000; + + static long waitTimeShort = 2000; + static long duration = 2000; + + static int mm_width = 800; + static int mm_height = 600; @BeforeClass public static void initClass() { @@ -85,7 +92,7 @@ public class TestScreenMode01aNEWT extends UITestCase { public static void releaseClass() throws InterruptedException { Thread.sleep(waitTimeShort); } - + static Window createWindow(Screen screen, GLCapabilities caps, String name, int x, int y, int width, int height) { Assert.assertNotNull(caps); @@ -106,7 +113,7 @@ public class TestScreenMode01aNEWT extends UITestCase { Assert.assertTrue(AWTRobotUtil.waitForRealized(window, false)); } } - + @Test public void testScreenModeChange01() throws InterruptedException { Thread.sleep(waitTimeShort); @@ -118,7 +125,16 @@ public class TestScreenMode01aNEWT extends UITestCase { final Screen screen = NewtFactory.createScreen(display, 0); // screen 0 Assert.assertNotNull(screen); final Window window0 = createWindow(screen, caps, "win0", 0, 0, width, height); - Assert.assertNotNull(window0); + Assert.assertNotNull(window0); + + final MonitorDevice monitor = screen.getMonitorDevices().get(0); + + Rectangle window0WindowBounds = window0.getBounds(); + Rectangle window0SurfaceBounds = window0.getSurfaceBounds(); + System.err.println("Test.0: Window bounds : "+window0WindowBounds+" [wu] within "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.0: Window bounds : "+window0SurfaceBounds+" [pixels]"); + System.err.println("Test.0: Screen viewport : "+screen.getViewport()+" [pixels], "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.0: Monitor viewport : "+monitor.getViewport()+" [pixels], "+monitor.getViewportInWindowUnits()+" [wu]"); final List