JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestRemoteGLWindows01NEWT.java
Go to the documentation of this file.
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
29package com.jogamp.opengl.test.junit.newt;
30
31import org.junit.Assert;
32import org.junit.Assume;
33import org.junit.Test;
34import org.junit.FixMethodOrder;
35import org.junit.runners.MethodSorters;
36
37import com.jogamp.opengl.*;
38
39import com.jogamp.opengl.util.Animator;
40
41import com.jogamp.newt.*;
42import com.jogamp.newt.opengl.*;
43import java.io.IOException;
44
45import com.jogamp.opengl.test.junit.util.UITestCase;
46import com.jogamp.opengl.test.junit.jogl.demos.es1.GearsES1;
47
48import com.jogamp.nativewindow.AbstractGraphicsDevice;
49import com.jogamp.nativewindow.NativeWindowException;
50
51@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53 static int width = 640, height = 480;
54 static long durationPerTest = 100; // ms
55 static String remoteDisplay = "localhost:0.0";
56
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
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
91 public void testRemoteWindow01() throws InterruptedException {
92 final Animator animator = new Animator(0 /* w/o AWT */);
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
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
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}
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
abstract AbstractGraphicsDevice getGraphicsDevice()
Return the AbstractGraphicsDevice used for depending resources lifecycle, i.e.
abstract void createNative()
Manual trigger the native creation, if it is not done yet.
static Display createDisplay(final String name)
Create a Display entity.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
Definition: Screen.java:58
abstract Display getDisplay()
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static String glAvailabilityToString(final AbstractGraphicsDevice device)
Definition: GLProfile.java:333
static GLProfile getGL2ES1(final AbstractGraphicsDevice device)
Returns the GL2ES1 profile implementation, hence compatible w/ GL2ES1.
Definition: GLProfile.java:883
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2ES1
The intersection of the desktop GL2 and embedded ES1 profile.
Definition: GLProfile.java:591
static void initProfiles(final AbstractGraphicsDevice device)
Trigger eager initialization of GLProfiles for the given device, in case it isn't done yet.
Definition: GLProfile.java:264
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final boolean isVBO()
Determines whether the data is server side (VBO) and enabled, or a client side array (false).
A interface describing a graphics device in a toolkit-independent manner.
String getConnection()
Returns the semantic GraphicsDevice connection.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.