JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestPerf001GLWindowInit03NEWT.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 */
28package com.jogamp.opengl.test.junit.jogl.perf;
29
30import java.lang.reflect.InvocationTargetException;
31import java.util.concurrent.atomic.AtomicInteger;
32
33import com.jogamp.opengl.GLAutoDrawable;
34import com.jogamp.opengl.GLCapabilities;
35import com.jogamp.opengl.GLCapabilitiesImmutable;
36import com.jogamp.opengl.GLEventListener;
37import com.jogamp.opengl.GLProfile;
38
39import org.junit.BeforeClass;
40import org.junit.FixMethodOrder;
41import org.junit.Test;
42import org.junit.runners.MethodSorters;
43
44import com.jogamp.common.os.Platform;
45import com.jogamp.newt.NewtFactory;
46import com.jogamp.newt.Screen;
47import com.jogamp.newt.opengl.GLWindow;
48import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
49import com.jogamp.opengl.test.junit.util.MiscUtils;
50import com.jogamp.opengl.test.junit.util.UITestCase;
51
52/**
53 * Multiple GLJPanels in a JFrame
54 */
55@FixMethodOrder(MethodSorters.NAME_ASCENDING)
57 final long INIT_TIMEOUT = 10L*1000L; // 10s
58
59 @BeforeClass
60 public static void initClass() {
62 }
63
64 public void test(final GLCapabilitiesImmutable caps, final boolean useGears, final int width, final int height, final int frameCount, final boolean reuseDevice) {
65 final int cols = (int)Math.round(Math.sqrt(frameCount));
66 final int rows = frameCount / cols;
67 final int eWidth = width/cols;
68 final int eHeight = height/rows;
69
70 final GLWindow[] frame = new GLWindow[frameCount];
71 final long[] t = new long[10];
72 if( wait ) {
73 UITestCase.waitForKey("Pre-Init");
74 }
75 System.err.println("INIT START");
76 initCount.set(0);
77
78 t[0] = Platform.currentTimeMillis();
79 int x = 32, y = 32;
80 for(int i=0; i<frameCount; i++) {
81 final Screen screen = NewtFactory.createScreen(NewtFactory.createDisplay(null, reuseDevice), 0);
82 frame[i] = GLWindow.create(screen, caps);
83 frame[i].setTitle("frame_"+i+"/"+frameCount);
84 frame[i].setPosition(x, y);
85 x+=eWidth+32;
86 if(x>=width) {
87 x=32;
88 y+=eHeight+32;
89 }
90 frame[i].setSize(eWidth, eHeight);
91 if( useGears ) {
92 frame[i].addGLEventListener(new GearsES2());
93 }
94 frame[i].addGLEventListener(new GLEventListener() {
95 @Override
96 public void init(final GLAutoDrawable drawable) {
97 initCount.incrementAndGet();
98 }
99 @Override
100 public void dispose(final GLAutoDrawable drawable) {}
101 @Override
102 public void display(final GLAutoDrawable drawable) {}
103 @Override
104 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {}
105 });
106 }
107 t[1] = Platform.currentTimeMillis();
108 for(int i=0; i<frameCount; i++) {
109 frame[i].setVisible(false /*wait*/, true /*visible*/);
110 }
111 t[2] = Platform.currentTimeMillis();
112
113 final long t0 = System.currentTimeMillis();
114 long t1 = t0;
115 while( frameCount > initCount.get() && INIT_TIMEOUT > t1 - t0 ) {
116 try {
117 Thread.sleep(100);
118 System.err.println("Sleep initialized: "+initCount+"/"+frameCount);
119 } catch (final InterruptedException e1) {
120 e1.printStackTrace();
121 }
122 t1 = System.currentTimeMillis();
123 }
124 t[3] = Platform.currentTimeMillis();
125 final double panelCountF = initCount.get();
126 System.err.printf("P: %d GLWindow:%n\tctor\t%6d/t %6.2f/1%n\tvisible\t%6d/t %6.2f/1%n\tsum-i\t%6d/t %6.2f/1%n",
127 initCount.get(),
128 t[1]-t[0], (t[1]-t[0])/panelCountF,
129 t[3]-t[1], (t[3]-t[1])/panelCountF,
130 t[3]-t[0], (t[3]-t[0])/panelCountF);
131
132 System.err.println("INIT END: "+initCount+"/"+frameCount);
133 if( wait ) {
134 UITestCase.waitForKey("Post-Init");
135 }
136 try {
137 Thread.sleep(duration);
138 } catch (final InterruptedException e1) {
139 e1.printStackTrace();
140 }
141 t[4] = Platform.currentTimeMillis();
142 for(int i=0; i<frameCount; i++) {
143 frame[i].destroy();
144 }
145
146 final long ti_net = (t[4]-t[0])-duration;
147 System.err.printf("T: duration %d %d%n\ttotal-d\t%6d/t %6.2f/1%n\ttotal-i\t%6d/t %6.2f/1%n",
148 duration, t[4]-t[3],
149 t[4]-t[0], (t[4]-t[0])/panelCountF,
150 ti_net, ti_net/panelCountF);
151 System.err.println("Total: "+(t[4]-t[0]));
152 }
153
154 static GLCapabilitiesImmutable caps = null;
155
156 @Test
157 public void test01NopGLWindowNoReuse() throws InterruptedException, InvocationTargetException {
158 if(!mainRun) {
159 System.err.println("Disabled for auto unit test until further analysis - Windows/ATI driver crash");
160 return;
161 }
162 test(new GLCapabilities(null), false /*useGears*/, width, height , frameCount, false /* reuseDevice */);
163 }
164 @Test
165 public void test02NopGLWindowReuse() throws InterruptedException, InvocationTargetException {
166 test(new GLCapabilities(null), false /*useGears*/, width, height , frameCount, true /* reuseDevice */);
167 }
168
169 static long duration = 0; // ms
170 static boolean wait = false, mainRun = false;
171 static int width = 800, height = 600, frameCount = 25;
172
173 AtomicInteger initCount = new AtomicInteger(0);
174
175 public static void main(final String[] args) {
176 mainRun = true;
177 boolean useGears = false, manual=false;
178 boolean waitMain = false;
179
180 for(int i=0; i<args.length; i++) {
181 if(args[i].equals("-time")) {
182 i++;
183 duration = MiscUtils.atol(args[i], duration);
184 } else if(args[i].equals("-width")) {
185 width = MiscUtils.atoi(args[++i], width);
186 } else if(args[i].equals("-height")) {
187 height = MiscUtils.atoi(args[++i], height);
188 } else if(args[i].equals("-count")) {
189 frameCount = MiscUtils.atoi(args[++i], frameCount);
190 } else if(args[i].equals("-gears")) {
191 useGears = true;
192 } else if(args[i].equals("-wait")) {
193 wait = true;
194 manual = true;
195 } else if(args[i].equals("-waitMain")) {
196 waitMain = true;
197 manual = true;
198 } else if(args[i].equals("-manual")) {
199 manual = true;
200 }
201 }
202 if( waitMain ) {
203 UITestCase.waitForKey("Main-Start");
204 }
205 if( manual ) {
208 demo.test(null, useGears, width, height, frameCount, false /* reuseDevice */);
209 } else {
210 org.junit.runner.JUnitCore.main(TestPerf001GLWindowInit03NEWT.class.getName());
211 }
212 }
213
214}
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
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 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 void initSingleton()
Static initialization of JOGL.
Definition: GLProfile.java:204
void test(final GLCapabilitiesImmutable caps, final boolean useGears, final int width, final int height, final int frameCount, final boolean reuseDevice)
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.