JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestShutdownCompleteNEWT.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.opengl.GLCapabilities;
34import com.jogamp.opengl.GLProfile;
35
36import org.junit.AfterClass;
37import org.junit.Assert;
38import org.junit.Test;
39import org.junit.FixMethodOrder;
40import org.junit.runners.MethodSorters;
41
42import com.jogamp.common.os.Platform;
43import com.jogamp.junit.util.JunitTracer;
44import com.jogamp.nativewindow.AbstractGraphicsDevice;
45import com.jogamp.newt.opengl.GLWindow;
46import com.jogamp.opengl.JoglVersion;
47import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
48import com.jogamp.opengl.test.junit.util.UITestCase;
49import com.jogamp.opengl.util.Animator;
50
51@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53
54 static long duration = 300; // ms
55
56 protected void runTestGL(final boolean onscreen) throws InterruptedException {
58 caps.setOnscreen(onscreen);
59 caps.setPBuffer(!onscreen);
60
61 final GLWindow glWindow = GLWindow.create(caps);
62 Assert.assertNotNull(glWindow);
63 glWindow.setTitle("Gears NEWT Test");
64
65 glWindow.addGLEventListener(new GearsES2());
66
67 final Animator animator = new Animator(glWindow);
68
69 glWindow.setSize(256, 256);
70 glWindow.setVisible(true);
71 animator.setUpdateFPSFrames(60, System.err);
72 animator.start();
73 Assert.assertEquals(true, animator.isAnimating());
74 Assert.assertEquals(true, glWindow.isVisible());
75 Assert.assertEquals(true, glWindow.isNativeValid());
76 Assert.assertEquals(true, glWindow.isRealized());
77
78 while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
79 Thread.sleep(100);
80 }
81
82 animator.stop();
83 glWindow.destroy();
84 }
85
86 @AfterClass
87 public static void afterAll() {
88 if(waitForKey) {
89 JunitTracer.waitForKey("Exit");
90 }
91 }
92
93 protected void oneLife(final boolean glInfo) throws InterruptedException {
94 if(waitForEach) {
95 JunitTracer.waitForKey("Start One Life");
96 }
97 final long t0 = Platform.currentTimeMillis();
99 final long t1 = Platform.currentTimeMillis();
100
101 // Test minimum requirement, having a default device with profile
102 {
103 final GLProfile glp = GLProfile.getDefault();
104 System.out.println("GLProfile.getDefault(): "+glp);
105
107 final GLProfile glp2 = GLProfile.getDefault(gd);
108 System.out.println("GLProfile.getDefaultDevice(): "+gd);
109 System.out.println("GLProfile.getDefault(gd): "+glp2);
110 Assert.assertEquals(glp, glp2);
111 }
112
113 if(!initOnly) {
114 runTestGL(true);
115 }
116 final long t2 = Platform.currentTimeMillis();
117 if(glInfo) {
118 System.err.println(JoglVersion.getDefaultOpenGLInfo(null, null, false).toString());
119 }
120 final long t3 = Platform.currentTimeMillis();
122 final long t4 = Platform.currentTimeMillis();
123 System.err.println("Total: "+ (t4-t0) +"ms");
124 System.err.println(" GLProfile.initSingleton(): "+ (t1-t0) +"ms");
125 System.err.println(" Demo Code: "+ (t2-t1) +"ms");
126 System.err.println(" GLInfo: "+ (t3-t2) +"ms");
127 System.err.println(" GLProfile.shutdown(): "+ (t4-t3) +"ms");
128 }
129
130 @Test
131 public void test01OneLife() throws InterruptedException {
132 oneLife(false);
133 }
134
135 @Test
136 public void test02AnotherLifeWithGLInfo() throws InterruptedException {
137 oneLife(true);
138 }
139
140 @Test
141 public void test03AnotherLife() throws InterruptedException {
142 oneLife(true);
143 }
144
145 @Test
146 public void test03TwoLifes() throws InterruptedException {
147 oneLife(false);
148 oneLife(false);
149 }
150
151 static boolean initOnly = false;
152 static boolean waitForEach = false;
153 static boolean waitForKey = false;
154
155 public static void main(final String args[]) throws IOException {
156 for(int i=0; i<args.length; i++) {
157 if(args[i].equals("-wait")) {
158 waitForKey = true;
159 } else if(args[i].equals("-waitForEach")) {
160 waitForEach = true;
161 waitForKey = true;
162 } else if(args[i].equals("-initOnly")) {
163 initOnly = true;
164 }
165 }
166
167 if(waitForKey) {
168 JunitTracer.waitForKey("Start");
169 }
170
171 final String tstname = TestShutdownCompleteNEWT.class.getName();
172 org.junit.runner.JUnitCore.main(tstname);
173 }
174
175}
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setTitle(final String title)
Definition: GLWindow.java:297
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.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static void shutdown()
Manual shutdown method, may be called after your last JOGL use within the running JVM.
Definition: GLProfile.java:277
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
static AbstractGraphicsDevice getDefaultDevice()
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static void initSingleton()
Static initialization of JOGL.
Definition: GLProfile.java:204
static StringBuilder getDefaultOpenGLInfo(AbstractGraphicsDevice device, StringBuilder sb, final boolean withCapabilitiesInfo)
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
A interface describing a graphics device in a toolkit-independent manner.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
boolean isRealized()
Returns true if this drawable is realized, otherwise false.