JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestAddRemove03GLWindowNEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 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;
32import java.lang.reflect.InvocationTargetException;
33
34import com.jogamp.opengl.GLCapabilities;
35import com.jogamp.opengl.GLProfile;
36
37import org.junit.AfterClass;
38import org.junit.Assert;
39import org.junit.BeforeClass;
40import org.junit.Test;
41import org.junit.FixMethodOrder;
42import org.junit.runners.MethodSorters;
43
44import com.jogamp.newt.opengl.GLWindow;
45import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
46import com.jogamp.opengl.test.junit.util.MiscUtils;
47import com.jogamp.opengl.test.junit.util.UITestCase;
48
49@FixMethodOrder(MethodSorters.NAME_ASCENDING)
51 static long durationPerTest = 50;
52 static int addRemoveCount = 15;
53 static int pauseEach = 0;
54 static int pauseDuration = 500;
55 static GLProfile glp;
56 static int width, height;
57 static boolean waitForKey = false;
58
59 @BeforeClass
60 public static void initClass() {
63 Assert.assertNotNull(glp);
64 width = 640;
65 height = 480;
66 } else {
67 setTestSupported(false);
68 }
69 }
70
71 @AfterClass
72 public static void releaseClass() {
73 }
74
75 protected void runTestGL(final GLCapabilities caps, final int addRemoveOpCount)
76 throws InterruptedException, InvocationTargetException
77 {
78
79 for(int i=0; i<addRemoveOpCount; i++) {
80 System.err.println("Loop # "+i+" / "+addRemoveCount);
81 final GLWindow glw = GLWindow.create(caps);
82 Assert.assertNotNull(glw);
83 glw.setTitle("GLWindow #"+i);
84 glw.setSize(width, height);
85 final GearsES2 gears = new GearsES2(1);
86 gears.setVerbose(false);
87 glw.addGLEventListener(gears);
88
89 glw.setVisible(true);
90
91 final long t0 = System.currentTimeMillis();
92 do {
93 glw.display();
94 Thread.sleep(10);
95 } while ( ( System.currentTimeMillis() - t0 ) < durationPerTest ) ;
96
97 System.err.println("GLWindow: "+glw.getChosenGLCapabilities());
98
99 glw.destroy();
100
101 if( 0 < pauseEach && 0 == i % pauseEach ) {
102 System.err.println("******* P A U S E ********");
103 Thread.sleep(pauseDuration);
104 }
105 }
106 }
107
108 @Test
109 public void test01Onscreen()
110 throws InterruptedException, InvocationTargetException
111 {
112 final GLCapabilities caps = new GLCapabilities(glp);
113 runTestGL(caps, addRemoveCount);
114 }
115
116 public static void main(final String args[]) throws IOException {
117 for(int i=0; i<args.length; i++) {
118 if(args[i].equals("-time")) {
119 i++;
120 try {
121 durationPerTest = Long.parseLong(args[i]);
122 } catch (final Exception ex) { ex.printStackTrace(); }
123 } else if(args[i].equals("-loops")) {
124 i++;
125 addRemoveCount = MiscUtils.atoi(args[i], addRemoveCount);
126 } else if(args[i].equals("-pauseEach")) {
127 i++;
128 pauseEach = MiscUtils.atoi(args[i], pauseEach);
129 } else if(args[i].equals("-pauseDuration")) {
130 i++;
131 pauseDuration = MiscUtils.atoi(args[i], pauseDuration);
132 } else if(args[i].equals("-wait")) {
133 waitForKey = true;
134 }
135 }
136 System.err.println("waitForKey "+waitForKey);
137
138 System.err.println("addRemoveCount "+addRemoveCount);
139 System.err.println("pauseEach "+pauseEach);
140 System.err.println("pauseDuration "+pauseDuration);
141
142 if(waitForKey) {
143 UITestCase.waitForKey("Start");
144 }
145 org.junit.runner.JUnitCore.main(TestAddRemove03GLWindowNEWT.class.getName());
146 }
147}
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.
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 final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
void runTestGL(final GLCapabilities caps, final int addRemoveOpCount)
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...