1 /** 2 * Copyright 2010 JogAmp Community. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, are 5 * permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * 24 * The views and conclusions contained in the software and documentation are those of the 25 * authors and should not be interpreted as representing official policies, either expressed 26 * or implied, of JogAmp Community. 27 */ 28 29 package com.jogamp.opengl.test.junit.jogl.acore; 30 31 import java.io.IOException; 32 33 import com.jogamp.newt.opengl.GLWindow; 34 35 import com.jogamp.nativewindow.util.InsetsImmutable; 36 import com.jogamp.opengl.GLCapabilities; 37 import com.jogamp.opengl.GLProfile; 38 import com.jogamp.opengl.util.Animator; 39 40 import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears; 41 import com.jogamp.opengl.test.junit.util.AWTRobotUtil; 42 import com.jogamp.opengl.test.junit.util.UITestCase; 43 44 import org.junit.Assert; 45 import org.junit.BeforeClass; 46 import org.junit.Test; 47 import org.junit.FixMethodOrder; 48 import org.junit.runners.MethodSorters; 49 50 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 51 public class TestSharedContextListNEWT2 extends UITestCase { 52 static GLProfile glp; 53 static GLCapabilities caps; 54 static int width, height; 55 GLWindow sharedDrawable; 56 Gears sharedGears; 57 58 @BeforeClass initClass()59 public static void initClass() { 60 if(GLProfile.isAvailable(GLProfile.GL2)) { 61 glp = GLProfile.get(GLProfile.GL2); 62 Assert.assertNotNull(glp); 63 caps = new GLCapabilities(glp); 64 Assert.assertNotNull(caps); 65 width = 256; 66 height = 256; 67 } else { 68 setTestSupported(false); 69 } 70 } 71 initShared()72 private void initShared() { 73 sharedDrawable = GLWindow.create(caps); 74 Assert.assertNotNull(sharedDrawable); 75 sharedGears = new Gears(0); 76 Assert.assertNotNull(sharedGears); 77 sharedDrawable.addGLEventListener(sharedGears); 78 sharedDrawable.setSize(width, height); 79 sharedDrawable.setVisible(true); 80 // init and render one frame, which will setup the Gears display lists 81 sharedDrawable.display(); 82 } 83 releaseShared()84 private void releaseShared() { 85 Assert.assertNotNull(sharedDrawable); 86 sharedDrawable.destroy(); 87 sharedDrawable = null; 88 } 89 runTestGL(final Animator animator, final int x, final int y, final boolean useShared, final boolean vsync)90 protected GLWindow runTestGL(final Animator animator, final int x, final int y, final boolean useShared, final boolean vsync) throws InterruptedException { 91 final GLWindow glWindow = GLWindow.create(caps); 92 93 Assert.assertNotNull(glWindow); 94 glWindow.setTitle("Shared Gears NEWT Test: "+x+"/"+y+" shared "+useShared); 95 if(useShared) { 96 glWindow.setSharedAutoDrawable(sharedDrawable); 97 } 98 99 glWindow.setSize(width, height); 100 101 final Gears gears = new Gears(vsync ? 1 : 0); 102 if(useShared) { 103 gears.setSharedGears(sharedGears); 104 } 105 glWindow.addGLEventListener(gears); 106 107 animator.add(glWindow); 108 animator.start(); 109 glWindow.setVisible(true); 110 111 Assert.assertTrue(AWTRobotUtil.waitForRealized(glWindow, true)); 112 Assert.assertTrue(AWTRobotUtil.waitForVisible(glWindow, true)); 113 glWindow.setPosition(x, y); 114 115 return glWindow; 116 } 117 118 @Test(timeout=10000) test01()119 public void test01() throws InterruptedException { 120 initShared(); 121 122 final GLWindow f1 = runTestGL(new Animator(), 0, 0, true, false); 123 final InsetsImmutable insets = f1.getInsets(); 124 final GLWindow f2 = runTestGL(new Animator(), f1.getX()+width+insets.getTotalWidth(), 125 f1.getY()+0, true, false); 126 final GLWindow f3 = runTestGL(new Animator(), f1.getX()+0, 127 f1.getY()+height+insets.getTotalHeight(), true, false); 128 129 try { 130 Thread.sleep(duration); 131 } catch(final Exception e) { 132 e.printStackTrace(); 133 } 134 135 f1.destroy(); 136 f2.destroy(); 137 f3.destroy(); 138 139 // f1.getAnimator().stop(); 140 // f2.getAnimator().stop(); 141 // f3.getAnimator().stop(); 142 143 releaseShared(); 144 } 145 146 static long duration = 2000; // ms 147 main(final String args[])148 public static void main(final String args[]) throws IOException { 149 for(int i=0; i<args.length; i++) { 150 if(args[i].equals("-time")) { 151 i++; 152 try { 153 duration = Integer.parseInt(args[i]); 154 } catch (final Exception ex) { ex.printStackTrace(); } 155 } 156 } 157 /** 158 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); 159 System.err.println("Press enter to continue"); 160 System.err.println(stdin.readLine()); */ 161 org.junit.runner.JUnitCore.main(TestSharedContextListNEWT2.class.getName()); 162 } 163 } 164