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.newt; 30 31 import org.junit.Assert; 32 import org.junit.Assume; 33 import org.junit.Test; 34 import org.junit.FixMethodOrder; 35 import org.junit.runners.MethodSorters; 36 37 import com.jogamp.opengl.*; 38 39 import com.jogamp.opengl.util.Animator; 40 41 import com.jogamp.newt.*; 42 import com.jogamp.newt.opengl.*; 43 import java.io.IOException; 44 45 import com.jogamp.opengl.test.junit.util.UITestCase; 46 import com.jogamp.opengl.test.junit.jogl.demos.es1.GearsES1; 47 48 import com.jogamp.nativewindow.AbstractGraphicsDevice; 49 import com.jogamp.nativewindow.NativeWindowException; 50 51 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 52 public class TestRemoteGLWindows01NEWT extends UITestCase { 53 static int width = 640, height = 480; 54 static long durationPerTest = 100; // ms 55 static String remoteDisplay = "localhost:0.0"; 56 createWindow(final Screen screen, final GLCapabilities caps, final GLEventListener demo)57 static GLWindow createWindow(final Screen screen, final GLCapabilities caps, final GLEventListener demo) 58 throws InterruptedException 59 { 60 Assert.assertNotNull(caps); 61 // 62 // Create native windowing resources .. X11/Win/OSX 63 // 64 GLWindow glWindow; 65 if(null!=screen) { 66 glWindow = GLWindow.create(screen, caps); 67 Assert.assertNotNull(glWindow); 68 } else { 69 glWindow = GLWindow.create(caps); 70 Assert.assertNotNull(glWindow); 71 } 72 73 glWindow.addGLEventListener(demo); 74 75 glWindow.setSize(512, 512); 76 glWindow.setVisible(true); 77 Assert.assertEquals(true,glWindow.isVisible()); 78 Assert.assertEquals(true,glWindow.isNativeValid()); 79 80 return glWindow; 81 } 82 destroyWindow(final GLWindow glWindow)83 static void destroyWindow(final GLWindow glWindow) { 84 if(null!=glWindow) { 85 glWindow.destroy(); 86 Assert.assertEquals(false,glWindow.isNativeValid()); 87 } 88 } 89 90 @Test testRemoteWindow01()91 public void testRemoteWindow01() throws InterruptedException { 92 final Animator animator = new Animator(); 93 final GLProfile glpLocal = GLProfile.getGL2ES1(); 94 Assert.assertNotNull(glpLocal); 95 final GLCapabilities capsLocal = new GLCapabilities(glpLocal); 96 Assert.assertNotNull(capsLocal); 97 final GearsES1 demoLocal = new GearsES1(1); 98 final GLWindow windowLocal = createWindow(null, capsLocal, demoLocal); // local with vsync 99 Assert.assertEquals(true,windowLocal.isNativeValid()); 100 Assert.assertEquals(true,windowLocal.isVisible()); 101 final AbstractGraphicsDevice device1 = windowLocal.getScreen().getDisplay().getGraphicsDevice(); 102 103 System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1)); 104 105 animator.add(windowLocal); 106 107 // Remote Display/Device/Screen/Window .. 108 // Eager initialization of NEWT Display -> AbstractGraphicsDevice -> GLProfile (device) 109 Display displayRemote; // remote display 110 AbstractGraphicsDevice deviceRemote; 111 Screen screenRemote; 112 GLWindow windowRemote; 113 GearsES1 demoRemote = null; 114 try { 115 displayRemote = NewtFactory.createDisplay(remoteDisplay); // remote display 116 displayRemote.createNative(); 117 System.err.println(displayRemote); 118 deviceRemote = displayRemote.getGraphicsDevice(); 119 System.err.println(deviceRemote); 120 GLProfile.initProfiles(deviceRemote); // just to make sure 121 System.err.println(); 122 System.err.println("GLProfiles window2: "+deviceRemote.getConnection()+": "+GLProfile.glAvailabilityToString(deviceRemote)); 123 final GLProfile glpRemote = GLProfile.get(deviceRemote, GLProfile.GL2ES1); 124 Assert.assertNotNull(glpRemote); 125 final GLCapabilities capsRemote = new GLCapabilities(glpRemote); 126 Assert.assertNotNull(capsRemote); 127 screenRemote = NewtFactory.createScreen(displayRemote, 0); // screen 0 128 demoRemote = new GearsES1(0); 129 windowRemote = createWindow(screenRemote, capsRemote, demoRemote); // remote, no vsync 130 } catch (final NativeWindowException nwe) { 131 System.err.println(nwe); 132 Assume.assumeNoException(nwe); 133 destroyWindow(windowLocal); 134 return; 135 } 136 137 Assert.assertEquals(true,windowRemote.isNativeValid()); 138 Assert.assertEquals(true,windowRemote.isVisible()); 139 140 animator.add(windowRemote); 141 animator.setUpdateFPSFrames(1, null); 142 animator.start(); 143 144 while(animator.getTotalFPSDuration()<durationPerTest) { 145 Thread.sleep(100); 146 } 147 if(null!=demoRemote) { 148 System.err.println("demoLocal VBO: "+demoLocal.getGear1().backFace.isVBO()); 149 System.err.println("demoRemote VBO: "+demoRemote.getGear1().backFace.isVBO()); 150 } 151 152 destroyWindow(windowLocal); 153 destroyWindow(windowRemote); 154 } 155 atoi(final String a)156 static int atoi(final String a) { 157 int i=0; 158 try { 159 i = Integer.parseInt(a); 160 } catch (final Exception ex) { ex.printStackTrace(); } 161 return i; 162 } 163 main(final String args[])164 public static void main(final String args[]) throws IOException { 165 for(int i=0; i<args.length; i++) { 166 if(args[i].equals("-time")) { 167 durationPerTest = atoi(args[++i]); 168 } else if(args[i].equals("-display")) { 169 remoteDisplay = args[++i]; 170 } 171 } 172 System.out.println("durationPerTest: "+durationPerTest); 173 System.out.println("display: "+remoteDisplay); 174 final String tstname = TestRemoteGLWindows01NEWT.class.getName(); 175 org.junit.runner.JUnitCore.main(tstname); 176 } 177 178 } 179