JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestAnimatorGLWindow01NEWT.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.anim;
30
31import java.lang.reflect.InvocationTargetException;
32
33import com.jogamp.opengl.GLCapabilities;
34
35import com.jogamp.newt.opengl.GLWindow;
36import com.jogamp.opengl.util.Animator;
37import com.jogamp.opengl.test.junit.util.NewtTestUtil;
38import com.jogamp.opengl.test.junit.util.GLTestUtil;
39import com.jogamp.opengl.test.junit.util.UITestCase;
40import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
41
42import org.junit.Assert;
43import org.junit.Test;
44import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
46
47@FixMethodOrder(MethodSorters.NAME_ASCENDING)
49 static final int width = 400;
50 static final int height = 400;
51
52 protected GLWindow createGLWindow(final GLCapabilities caps, final int x, final int y, final GearsES2 gears) throws InterruptedException {
53 final GLWindow glWindow = GLWindow.create(caps);
54 Assert.assertNotNull(glWindow);
55 glWindow.addGLEventListener(gears);
56 glWindow.setPosition(x, y);
57 glWindow.setSize(width, height);
58 glWindow.setTitle("GLWindow: "+x+"/"+y);
59 return glWindow;
60 }
61
62 static void pauseAnimator(final Animator animator, final boolean pause) {
63 if(pause) {
64 animator.pause();
65 Assert.assertEquals(true, animator.isStarted());
66 Assert.assertEquals(true, animator.isPaused());
67 Assert.assertEquals(false, animator.isAnimating());
68 } else {
69 animator.resume();
70 Assert.assertEquals(true, animator.isStarted());
71 Assert.assertEquals(false, animator.isPaused());
72 Assert.assertEquals(true, animator.isAnimating());
73 }
74 }
75 static void stopAnimator(final Animator animator) {
76 animator.stop();
77 Assert.assertEquals(false, animator.isStarted());
78 Assert.assertEquals(false, animator.isPaused());
79 Assert.assertEquals(false, animator.isAnimating());
80 }
81
82 @Test
83 public void test01SyncedOneAnimator() throws InterruptedException, InvocationTargetException {
84 final GLCapabilities caps = new GLCapabilities(null);
85 final Animator animator = new Animator(0 /* w/o AWT */);
86 animator.start();
87 Assert.assertEquals(true, animator.isStarted());
88 Assert.assertEquals(true, animator.isPaused());
89 Assert.assertEquals(false, animator.isAnimating());
90
91 final GearsES2 g1 = new GearsES2(0);
92 final GLWindow c1 = createGLWindow(caps, 0, 0, g1);
93 animator.add(c1);
94 Assert.assertEquals(true, animator.isStarted());
95 Assert.assertEquals(false, animator.isPaused());
96 Assert.assertEquals(true, animator.isAnimating());
97
98 final GearsES2 g2 = new GearsES2(0);
99 final GLWindow c2 = createGLWindow(caps, c1.getX()+width,
100 c1.getY()+0, g2);
101 animator.add(c2);
102
103 final GearsES2 g3 = new GearsES2(0);
104 final GLWindow c3 = createGLWindow(caps, c1.getX()+0,
105 c1.getY()+height, g3);
106 animator.add(c3);
107
108 c1.setVisible(true);
109 c2.setVisible(true);
110 c3.setVisible(true);
111
112 Assert.assertTrue(NewtTestUtil.waitForRealized(c1, true, null));
113 Assert.assertTrue(NewtTestUtil.waitForVisible(c1, true, null));
114 Assert.assertTrue(GLTestUtil.waitForContextCreated(c1, true, null));
115 Assert.assertTrue("Gears1 not initialized", g1.waitForInit(true));
116
117 Assert.assertTrue(NewtTestUtil.waitForRealized(c2, true, null));
118 Assert.assertTrue(NewtTestUtil.waitForVisible(c2, true, null));
119 Assert.assertTrue(GLTestUtil.waitForContextCreated(c2, true, null));
120 Assert.assertTrue("Gears2 not initialized", g2.waitForInit(true));
121
122 Assert.assertTrue(NewtTestUtil.waitForRealized(c3, true, null));
123 Assert.assertTrue(NewtTestUtil.waitForVisible(c3, true, null));
124 Assert.assertTrue(GLTestUtil.waitForContextCreated(c3, true, null));
125 Assert.assertTrue("Gears3 not initialized", g3.waitForInit(true));
126
127 try {
128 Thread.sleep(duration/3);
129 } catch(final Exception e) {
130 e.printStackTrace();
131 }
132
133 pauseAnimator(animator, true);
134
135 try {
136 Thread.sleep(duration/3);
137 } catch(final Exception e) {
138 e.printStackTrace();
139 }
140
141 pauseAnimator(animator, false);
142
143 try {
144 Thread.sleep(duration/3);
145 } catch(final Exception e) {
146 e.printStackTrace();
147 }
148
149 // Stopped animator allows native windowing system 'repaint' event
150 // to trigger GLAD 'display'
151 stopAnimator(animator);
152
153 c1.destroy();
154 c2.destroy();
155 c3.destroy();
156
157 Assert.assertTrue(NewtTestUtil.waitForRealized(c1, false, null));
158 Assert.assertTrue(NewtTestUtil.waitForRealized(c2, false, null));
159 Assert.assertTrue(NewtTestUtil.waitForRealized(c3, false, null));
160 }
161
162 @Test
163 public void test02AsyncEachAnimator() throws InterruptedException, InvocationTargetException {
164 final GLCapabilities caps = new GLCapabilities(null);
165 final Animator a1 = new Animator(0 /* w/o AWT */);
166 final GearsES2 g1 = new GearsES2(0);
167 final GLWindow c1 = createGLWindow(caps, 0, 0, g1);
168 a1.add(c1);
169 a1.start();
170 Assert.assertEquals(true, a1.isStarted());
171 Assert.assertEquals(false, a1.isPaused());
172 Assert.assertEquals(true, a1.isAnimating());
173 c1.setVisible(true);
174
175 final Animator a2 = new Animator(0 /* w/o AWT */);
176 final GearsES2 g2 = new GearsES2(0);
177 final GLWindow c2 = createGLWindow(caps, c1.getX()+width, c1.getY()+0, g2);
178 a2.add(c2);
179 a2.start();
180 Assert.assertEquals(true, a2.isStarted());
181 Assert.assertEquals(false, a2.isPaused());
182 Assert.assertEquals(true, a2.isAnimating());
183 c2.setVisible(true);
184
185 final Animator a3 = new Animator(0 /* w/o AWT */);
186 final GearsES2 g3 = new GearsES2(0);
187 final GLWindow c3 = createGLWindow(caps, c1.getX()+0, c1.getY()+height, g3);
188 a3.add(c3);
189 a3.start();
190 Assert.assertEquals(true, a3.isStarted());
191 Assert.assertEquals(false, a3.isPaused());
192 Assert.assertEquals(true, a3.isAnimating());
193 c3.setVisible(true);
194
195 Assert.assertTrue(NewtTestUtil.waitForRealized(c1, true, null));
196 Assert.assertTrue(NewtTestUtil.waitForVisible(c1, true, null));
197 Assert.assertTrue(GLTestUtil.waitForContextCreated(c1, true, null));
198 Assert.assertTrue("Gears1 not initialized", g1.waitForInit(true));
199
200 Assert.assertTrue(NewtTestUtil.waitForRealized(c2, true, null));
201 Assert.assertTrue(NewtTestUtil.waitForVisible(c2, true, null));
202 Assert.assertTrue(GLTestUtil.waitForContextCreated(c2, true, null));
203 Assert.assertTrue("Gears2 not initialized", g2.waitForInit(true));
204
205 Assert.assertTrue(NewtTestUtil.waitForRealized(c3, true, null));
206 Assert.assertTrue(NewtTestUtil.waitForVisible(c3, true, null));
207 Assert.assertTrue(GLTestUtil.waitForContextCreated(c3, true, null));
208 Assert.assertTrue("Gears3 not initialized", g3.waitForInit(true));
209
210 try {
211 Thread.sleep(duration/3);
212 } catch(final Exception e) {
213 e.printStackTrace();
214 }
215
216 pauseAnimator(a1, true);
217 pauseAnimator(a2, true);
218 pauseAnimator(a3, true);
219
220 try {
221 Thread.sleep(duration/3);
222 } catch(final Exception e) {
223 e.printStackTrace();
224 }
225
226 pauseAnimator(a1, false);
227 pauseAnimator(a2, false);
228 pauseAnimator(a3, false);
229
230 try {
231 Thread.sleep(duration/3);
232 } catch(final Exception e) {
233 e.printStackTrace();
234 }
235
236 // Stopped animator allows native windowing system 'repaint' event
237 // to trigger GLAD 'display'
238 stopAnimator(a1);
239 stopAnimator(a2);
240 stopAnimator(a3);
241
242 c1.destroy();
243 c2.destroy();
244 c3.destroy();
245
246 Assert.assertTrue(NewtTestUtil.waitForRealized(c1, false, null));
247 Assert.assertTrue(NewtTestUtil.waitForRealized(c2, false, null));
248 Assert.assertTrue(NewtTestUtil.waitForRealized(c3, false, null));
249 }
250
251 static long duration = 3*500; // ms
252
253 public static void main(final String args[]) {
254 for(int i=0; i<args.length; i++) {
255 if(args[i].equals("-time")) {
256 i++;
257 try {
258 duration = Integer.parseInt(args[i]);
259 } catch (final Exception ex) { ex.printStackTrace(); }
260 }
261 }
262 /**
263 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
264 System.err.println("Press enter to continue");
265 System.err.println(stdin.readLine()); */
266 org.junit.runner.JUnitCore.main(TestAnimatorGLWindow01NEWT.class.getName());
267 }
268}
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 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.
GLWindow createGLWindow(final GLCapabilities caps, final int x, final int y, final GearsES2 gears)
boolean waitForInit(final boolean initialized)
Definition: GearsES2.java:187
static boolean waitForContextCreated(final GLAutoDrawable autoDrawable, final boolean created, final Runnable waitAction)
Definition: GLTestUtil.java:42
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final Window win, final boolean visible, final Runnable waitAction)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean pause()
Pauses this animator.
Definition: Animator.java:382
final synchronized boolean resume()
Resumes animation if paused.
Definition: Animator.java:397
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean isPaused()
Indicates whether this animator is started and either manually paused or paused automatically due to ...
Definition: Animator.java:326
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.