diff options
author | Sven Gothel <[email protected]> | 2014-07-30 20:13:34 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-07-30 20:13:34 +0200 |
commit | ff5dba28610b4f680c9320e9e52669ed54d4de43 (patch) | |
tree | 916cc30ac361c3c4ca6a1d7ed81f7e28d040721f /src/test/com/jogamp | |
parent | adf8e6e40aa9513036864489642cfef252804d08 (diff) |
Bug 830 - Add Heuristics for to query whether GLDrawableUtil.swapGLContextAndAllGLEventListener is safe (Doesn't work w/ pre MSAA onscreen drawable)
GLDrawableUtil.isSwapGLContextSafe(..) allows user to query whether 'we think' it's safe
to utilize swapping of GLContext between GLAutoDrawable instances.
Currently known unsafe cases are:
- between on- and offscreen and one of the following:
- MSAA involved, or
- STEREO involved
Enhanced unit tests in this regard:
- TestGLContextDrawableSwitch02AWT
- using GLContextDrawableSwitchBase0
- TestGLContextDrawableSwitch02NEWT
- using GLContextDrawableSwitchBase0
Utilized safe query for setupPrint(..) action in:
- AWT GLCanvas
- AWT GLJPanel
- NewtCanvasAWT
Diffstat (limited to 'src/test/com/jogamp')
8 files changed, 385 insertions, 93 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/GLContextDrawableSwitchBase0.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/GLContextDrawableSwitchBase0.java new file mode 100644 index 000000000..49d16a80a --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/GLContextDrawableSwitchBase0.java @@ -0,0 +1,254 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * 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 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * 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.glels; + +import java.lang.reflect.InvocationTargetException; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLProfile; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLDrawableUtil; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.QuitAdapter; +import com.jogamp.opengl.test.junit.util.UITestCase; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +/** + * Test re-association (switching) of GLWindow /GLDrawables, + * from GLWindow/GLOffscreenAutoDrawable to an GLOffscreenAutoDrawable and back. + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public abstract class GLContextDrawableSwitchBase0 extends UITestCase { + static int width, height; + static boolean testEvenUnsafeSwapGLContext = false; + + static GLCapabilities getCaps(final String profile) { + if( !GLProfile.isAvailable(profile) ) { + System.err.println("Profile "+profile+" n/a"); + return null; + } + return new GLCapabilities(GLProfile.get(profile)); + } + + @BeforeClass + public static void initClass() { + width = 256; + height = 256; + } + + public abstract GLAutoDrawable createGLAutoDrawable(final QuitAdapter quitAdapter, final GLCapabilitiesImmutable caps, final int width, final int height) throws InterruptedException, InvocationTargetException; + public abstract void destroyGLAutoDrawable(final GLAutoDrawable glad) throws InterruptedException, InvocationTargetException; + + @Test(timeout=30000) + public void test01aSwitch2Onscreen2OnscreenGL2ES2_Def() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + testImpl(reqGLCaps, true); + } + + @Test(timeout=30000) + public void test01bSwitch2Onscreen2OffscreenGL2ES2_Def() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + testImpl(reqGLCaps, false); + } + + @Test(timeout=30000) + public void test01cSwitch2Offscreen2OffscreenGL2ES2_Def() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + reqGLCaps.setOnscreen(false); + testImpl(reqGLCaps, false); + } + + @Test(timeout=30000) + public void test01dSwitch2Offscreen2OnscreenGL2ES2_Def() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + reqGLCaps.setOnscreen(false); + testImpl(reqGLCaps, true); + } + + @Test(timeout=30000) + public void test02aSwitch2Onscreen2OnscreenGL2ES2_MSAA() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + reqGLCaps.setNumSamples(4); + reqGLCaps.setSampleBuffers(true); + testImpl(reqGLCaps, true); + } + + @Test(timeout=30000) + public void test02bSwitch2Onscreen2OffscreenGL2ES2_MSAA() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + reqGLCaps.setNumSamples(4); + reqGLCaps.setSampleBuffers(true); + testImpl(reqGLCaps, false); + } + + @Test(timeout=30000) + public void test02cSwitch2Offscreen2OffscreenGL2ES2_MSAA() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + reqGLCaps.setOnscreen(false); + reqGLCaps.setNumSamples(4); + reqGLCaps.setSampleBuffers(true); + testImpl(reqGLCaps, false); + } + + @Test(timeout=30000) + public void test02dSwitch2Offscreen2OnscreenGL2ES2_MSAA() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + reqGLCaps.setOnscreen(false); + reqGLCaps.setNumSamples(4); + reqGLCaps.setSampleBuffers(true); + testImpl(reqGLCaps, true); + } + + @Test(timeout=30000) + public void test03aSwitch2Onscreen2OnscreenGL2ES2_Accu() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + reqGLCaps.setAccumRedBits(1); + reqGLCaps.setAccumGreenBits(1); + reqGLCaps.setAccumBlueBits(1); + testImpl(reqGLCaps, true); + } + + @Test(timeout=30000) + public void test03bSwitch2Onscreen2OffscreenGL2ES2_Accu() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + reqGLCaps.setAccumRedBits(1); + reqGLCaps.setAccumGreenBits(1); + reqGLCaps.setAccumBlueBits(1); + testImpl(reqGLCaps, false); + } + + @Test(timeout=30000) + public void test03cSwitch2Offscreen2OffscreenGL2ES2_Accu() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + reqGLCaps.setOnscreen(false); + reqGLCaps.setAccumRedBits(1); + reqGLCaps.setAccumGreenBits(1); + reqGLCaps.setAccumBlueBits(1); + testImpl(reqGLCaps, false); + } + + @Test(timeout=30000) + public void test03dSwitch2Offscreen2OnscreenGL2ES2_Accu() throws InterruptedException, InvocationTargetException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + reqGLCaps.setOnscreen(false); + reqGLCaps.setAccumRedBits(1); + reqGLCaps.setAccumGreenBits(1); + reqGLCaps.setAccumBlueBits(1); + testImpl(reqGLCaps, true); + } + + private void testImpl(final GLCapabilitiesImmutable srcCaps, final boolean dstOnscreen) throws InterruptedException, InvocationTargetException { + final QuitAdapter quitAdapter = new QuitAdapter(); + final GLAutoDrawable gladSource = createGLAutoDrawable(quitAdapter, srcCaps, width, height); + + final GLCapabilitiesImmutable srcCapsChosen = gladSource.getChosenGLCapabilities(); + + final GLCapabilities dstCaps = (GLCapabilities) srcCapsChosen.cloneMutable(); + dstCaps.setOnscreen(dstOnscreen); + + final boolean isSwapGLContextSafe = GLDrawableUtil.isSwapGLContextSafe(srcCapsChosen, dstCaps); + System.err.println("Source Caps Requested: "+srcCaps); + System.err.println("Source Caps Chosen : "+srcCapsChosen); + System.err.println("Dest Caps Requested: "+dstCaps); + System.err.println("Is SwapGLContext safe: "+isSwapGLContextSafe); + + if( !isSwapGLContextSafe && !testEvenUnsafeSwapGLContext ) { + System.err.println("Supressing unsafe tests ..."); + destroyGLAutoDrawable(gladSource); + return; + } + + final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); + final GearsES2 gears = new GearsES2(1); + gears.setVerbose(false); + gladSource.addGLEventListener(gears); + gladSource.addGLEventListener(snapshotGLEventListener); + snapshotGLEventListener.setMakeSnapshot(); + + final Animator animator = new Animator(); + animator.add(gladSource); + animator.start(); + + int s = 0; + final long t0 = System.currentTimeMillis(); + long t1 = t0; + + final GLAutoDrawable gladDest = createGLAutoDrawable(quitAdapter, dstCaps, width, height); + RuntimeException caught = null; + try { + while( !quitAdapter.shouldQuit() && ( t1 - t0 ) < duration ) { + if( ( t1 - t0 ) / period > s) { + s++; + System.err.println(s+" - switch - START "+ ( t1 - t0 )); + + // switch context _and_ the demo synchronously + GLDrawableUtil.swapGLContextAndAllGLEventListener(gladSource, gladDest); + snapshotGLEventListener.setMakeSnapshot(); + + System.err.println(s+" - switch - END "+ ( t1 - t0 )); + } + Thread.sleep(100); + t1 = System.currentTimeMillis(); + } + } catch (final RuntimeException t) { + caught = t; + } + + animator.stop(); + destroyGLAutoDrawable(gladDest); + destroyGLAutoDrawable(gladSource); + + if( null != caught ) { + throw caught; + } + } + + // default timing for 2 switches + static long duration = 2900; // ms + static long period = 1000; // ms +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/GLContextDrawableSwitchBase.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/GLContextDrawableSwitchBase1.java index b19dc38f2..0e7ea3e83 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/GLContextDrawableSwitchBase.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/GLContextDrawableSwitchBase1.java @@ -68,7 +68,7 @@ import org.junit.BeforeClass; * See Bug 665 - https://jogamp.org/bugzilla/show_bug.cgi?id=665. * </p> */ -public abstract class GLContextDrawableSwitchBase extends UITestCase { +public abstract class GLContextDrawableSwitchBase1 extends UITestCase { static protected enum GLADType { GLCanvasOnscreen, GLCanvasOffscreen, GLWindow, GLOffscreen }; // default period for 1 GLAD cycle diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestBug722GLContextDrawableSwitchNewt2AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestBug722GLContextDrawableSwitchNewt2AWT.java index 512ebc974..e961fe32d 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestBug722GLContextDrawableSwitchNewt2AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestBug722GLContextDrawableSwitchNewt2AWT.java @@ -54,7 +54,7 @@ import org.junit.runners.MethodSorters; * </p> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestBug722GLContextDrawableSwitchNewt2AWT extends GLContextDrawableSwitchBase { +public class TestBug722GLContextDrawableSwitchNewt2AWT extends GLContextDrawableSwitchBase1 { static int loops = 10; static long duration2 = 100; // ms diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch02AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch02AWT.java index d665c1a87..d9f2d0e18 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch02AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch02AWT.java @@ -29,6 +29,7 @@ package com.jogamp.opengl.test.junit.jogl.acore.glels; import java.awt.BorderLayout; +import java.awt.Component; import java.awt.Dimension; import java.awt.Frame; import java.io.IOException; @@ -38,20 +39,15 @@ import com.jogamp.newt.event.TraceWindowAdapter; import com.jogamp.newt.event.awt.AWTWindowAdapter; import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLDrawableFactory; -import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLCanvas; -import com.jogamp.opengl.util.Animator; -import com.jogamp.opengl.util.GLDrawableUtil; -import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import jogamp.nativewindow.awt.AWTMisc; + import com.jogamp.opengl.test.junit.util.QuitAdapter; -import com.jogamp.opengl.test.junit.util.UITestCase; import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @@ -60,26 +56,15 @@ import org.junit.runners.MethodSorters; * from GLCanvas to an GLOffscreenAutoDrawable and back. */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestGLContextDrawableSwitch02AWT extends UITestCase { - static int width, height; - - static GLCapabilities getCaps(final String profile) { - if( !GLProfile.isAvailable(profile) ) { - System.err.println("Profile "+profile+" n/a"); - return null; - } - return new GLCapabilities(GLProfile.get(profile)); - } +public class TestGLContextDrawableSwitch02AWT extends GLContextDrawableSwitchBase0 { - @BeforeClass - public static void initClass() { - width = 256; - height = 256; - } - - private GLAutoDrawable createGLAutoDrawable(final Frame frame, final GLCapabilities caps, final int width, final int height) throws InterruptedException, InvocationTargetException { + @Override + public GLAutoDrawable createGLAutoDrawable(final QuitAdapter quitAdapter, final GLCapabilitiesImmutable caps, final int width, final int height) throws InterruptedException, InvocationTargetException { final GLAutoDrawable glad; if( caps.isOnscreen() ) { + final Frame frame = new Frame("Gears AWT Test"); + Assert.assertNotNull(frame); + final GLCanvas glCanvas = new GLCanvas(caps); Assert.assertNotNull(glCanvas); final Dimension glc_sz = new Dimension(width, height); @@ -88,6 +73,8 @@ public class TestGLContextDrawableSwitch02AWT extends UITestCase { glCanvas.setSize(glc_sz); glad = glCanvas; + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas).addTo(frame); + frame.setLayout(new BorderLayout()); frame.add(glCanvas, BorderLayout.CENTER); javax.swing.SwingUtilities.invokeAndWait(new Runnable() { @@ -95,7 +82,6 @@ public class TestGLContextDrawableSwitch02AWT extends UITestCase { frame.pack(); frame.setVisible(true); }}); - } else { final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile()); glad = factory.createOffscreenAutoDrawable(null, caps, null, width, height); @@ -104,70 +90,20 @@ public class TestGLContextDrawableSwitch02AWT extends UITestCase { return glad; } - @Test(timeout=30000) - public void testSwitch2AWTGLCanvas2OffscreenGL2ES2() throws InterruptedException, InvocationTargetException { - final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); - if(null == reqGLCaps) return; - testSwitch2AWTGLCanvas2OffscreenImpl(reqGLCaps); - } - - private void testSwitch2AWTGLCanvas2OffscreenImpl(final GLCapabilities capsOnscreen) throws InterruptedException, InvocationTargetException { - final GLCapabilities capsOffscreen = (GLCapabilities) capsOnscreen.clone(); - capsOffscreen.setOnscreen(false); - - final Frame frame = new Frame("Gears AWT Test"); - Assert.assertNotNull(frame); - - final GLAutoDrawable glCanvas = createGLAutoDrawable(frame, capsOnscreen, width, height); - - final QuitAdapter quitAdapter = new QuitAdapter(); - new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas).addTo(frame); - - final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); - final GearsES2 gears = new GearsES2(1); - glCanvas.addGLEventListener(gears); - glCanvas.addGLEventListener(snapshotGLEventListener); - snapshotGLEventListener.setMakeSnapshot(); - - final Animator animator = new Animator(); - animator.add(glCanvas); - animator.start(); - - int s = 0; - final long t0 = System.currentTimeMillis(); - long t1 = t0; - - final GLAutoDrawable glOffscreen = createGLAutoDrawable(null, capsOffscreen, width, height); - while( !quitAdapter.shouldQuit() && ( t1 - t0 ) < duration ) { - if( ( t1 - t0 ) / period > s) { - s++; - System.err.println(s+" - switch - START "+ ( t1 - t0 )); - - // switch context _and_ the demo synchronously - GLDrawableUtil.swapGLContextAndAllGLEventListener(glCanvas, glOffscreen); - snapshotGLEventListener.setMakeSnapshot(); - - System.err.println(s+" - switch - END "+ ( t1 - t0 )); - } - Thread.sleep(100); - t1 = System.currentTimeMillis(); + @Override + public void destroyGLAutoDrawable(final GLAutoDrawable glad) throws InterruptedException, InvocationTargetException { + if( glad.getChosenGLCapabilities().isOnscreen() ) { + final Frame frame = AWTMisc.getFrame((Component)glad); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + final Frame _frame = frame; + _frame.dispose(); + }}); + } else { + glad.destroy(); } - - animator.stop(); - // glCanvas.destroy(); - glOffscreen.destroy(); - - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - final Frame _frame = frame; - _frame.dispose(); - }}); } - // default timing for 2 switches - static long duration = 2900; // ms - static long period = 1000; // ms - public static void main(final String args[]) throws IOException { for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { @@ -180,6 +116,8 @@ public class TestGLContextDrawableSwitch02AWT extends UITestCase { try { period = Integer.parseInt(args[i]); } catch (final Exception ex) { ex.printStackTrace(); } + } else if(args[i].equals("-testUnsafe")) { + testEvenUnsafeSwapGLContext = true; } } /** diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch02NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch02NEWT.java new file mode 100644 index 000000000..c8a78d05f --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch02NEWT.java @@ -0,0 +1,100 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * 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 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * 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.glels; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +import com.jogamp.newt.opengl.GLWindow; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLDrawableFactory; + +import com.jogamp.opengl.test.junit.util.QuitAdapter; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +/** + * Test re-association (switching) of GLWindow /GLDrawables, + * from GLWindow/GLOffscreenAutoDrawable to an GLOffscreenAutoDrawable and back. + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestGLContextDrawableSwitch02NEWT extends GLContextDrawableSwitchBase0 { + @Override + public GLAutoDrawable createGLAutoDrawable(final QuitAdapter quitAdapter, final GLCapabilitiesImmutable caps, final int width, final int height) throws InterruptedException, InvocationTargetException { + final GLAutoDrawable glad; + if( caps.isOnscreen() ) { + final GLWindow glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + glad = glWindow; + + if( null != quitAdapter ) { + glWindow.addWindowListener(quitAdapter); + } + + glWindow.setVisible(true); + } else { + final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile()); + glad = factory.createOffscreenAutoDrawable(null, caps, null, width, height); + Assert.assertNotNull(glad); + } + return glad; + } + + @Override + public void destroyGLAutoDrawable(final GLAutoDrawable glad) throws InterruptedException, InvocationTargetException { + glad.destroy(); + } + + public static void main(final String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (final Exception ex) { ex.printStackTrace(); } + } else if(args[i].equals("-period")) { + i++; + try { + period = Integer.parseInt(args[i]); + } catch (final Exception ex) { ex.printStackTrace(); } + } else if(args[i].equals("-testUnsafe")) { + testEvenUnsafeSwapGLContext = true; + } + } + /** + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + System.err.println("Press enter to continue"); + System.err.println(stdin.readLine()); */ + org.junit.runner.JUnitCore.main(TestGLContextDrawableSwitch02NEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch11NewtAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch11NewtAWT.java index 9697869bc..f1c08c889 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch11NewtAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch11NewtAWT.java @@ -60,7 +60,7 @@ import org.junit.runners.MethodSorters; * </p> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestGLContextDrawableSwitch11NewtAWT extends GLContextDrawableSwitchBase { +public class TestGLContextDrawableSwitch11NewtAWT extends GLContextDrawableSwitchBase1 { @Test(timeout=30000) public void test21GLWindowGL2ES2() throws InterruptedException { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch12AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch12AWT.java index 4ad0b1dc5..795e53768 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch12AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch12AWT.java @@ -61,7 +61,7 @@ import org.junit.runners.MethodSorters; * </p> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestGLContextDrawableSwitch12AWT extends GLContextDrawableSwitchBase { +public class TestGLContextDrawableSwitch12AWT extends GLContextDrawableSwitchBase1 { @Test(timeout=30000) public void test01GLCanvasOnscreenGL2ES2() throws InterruptedException { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch21Newt2AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch13Newt2AWT.java index eaf3d37d4..27d5ff80a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch21Newt2AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch13Newt2AWT.java @@ -73,7 +73,7 @@ import org.junit.runners.MethodSorters; * </p> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestGLContextDrawableSwitch21Newt2AWT extends GLContextDrawableSwitchBase { +public class TestGLContextDrawableSwitch13Newt2AWT extends GLContextDrawableSwitchBase1 { @Test(timeout=30000) public void test01GLCanvasOnScrn2GLWindowGL2ES2() throws InterruptedException { @@ -190,6 +190,6 @@ public class TestGLContextDrawableSwitch21Newt2AWT extends GLContextDrawableSwit BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.err.println("Press enter to continue"); System.err.println(stdin.readLine()); */ - org.junit.runner.JUnitCore.main(TestGLContextDrawableSwitch21Newt2AWT.class.getName()); + org.junit.runner.JUnitCore.main(TestGLContextDrawableSwitch13Newt2AWT.class.getName()); } } |