JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestSharedContextListNEWT2.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.jogl.acore;
30
31import java.io.IOException;
32
33import com.jogamp.newt.opengl.GLWindow;
34
35import com.jogamp.nativewindow.util.InsetsImmutable;
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLProfile;
38import com.jogamp.opengl.util.Animator;
39
40import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
41import com.jogamp.opengl.test.junit.util.NewtTestUtil;
42import com.jogamp.opengl.test.junit.util.UITestCase;
43
44import org.junit.Assert;
45import org.junit.BeforeClass;
46import org.junit.Test;
47import org.junit.FixMethodOrder;
48import org.junit.runners.MethodSorters;
49
50@FixMethodOrder(MethodSorters.NAME_ASCENDING)
52 static GLProfile glp;
53 static GLCapabilities caps;
54 static int width, height;
55 GLWindow sharedDrawable;
56 Gears sharedGears;
57
58 @BeforeClass
59 public static void initClass() {
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
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
84 private void releaseShared() {
85 Assert.assertNotNull(sharedDrawable);
86 sharedDrawable.destroy();
87 sharedDrawable = null;
88 }
89
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(NewtTestUtil.waitForRealized(glWindow, true, null));
112 Assert.assertTrue(NewtTestUtil.waitForVisible(glWindow, true, null));
113 glWindow.setPosition(x, y);
114
115 return glWindow;
116 }
117
118 @Test(timeout=10000)
119 public void test01() throws InterruptedException {
120 initShared();
121
122 final GLWindow f1 = runTestGL(new Animator(0 /* w/o AWT */), 0, 0, true, false);
123 final InsetsImmutable insets = f1.getInsets();
124 final GLWindow f2 = runTestGL(new Animator(0 /* w/o AWT */), f1.getX()+width+insets.getTotalWidth(),
125 f1.getY()+0, true, false);
126 final GLWindow f3 = runTestGL(new Animator(0 /* w/o AWT */), 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
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}
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
Definition: GLWindow.java:525
final void setTitle(final String title)
Definition: GLWindow.java:297
final int getX()
Returns the current x position of this window, relative to it's parent.
Definition: GLWindow.java:436
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
Definition: GLWindow.java:441
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 InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
Definition: GLWindow.java:431
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 boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
Definition: GLProfile.java:305
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
Definition: GLProfile.java:579
GLWindow runTestGL(final Animator animator, final int x, final int y, final boolean useShared, final boolean vsync)
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
Definition: Gears.java:34
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final Window win, final boolean visible, final Runnable waitAction)
Immutable insets representing rectangular window decoration insets on all four edges in window units.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.