JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestPerf001RawInit00NEWT.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;
31
32import com.jogamp.nativewindow.AbstractGraphicsConfiguration;
33import com.jogamp.nativewindow.GraphicsConfigurationFactory;
34import com.jogamp.nativewindow.VisualIDHolder;
35import com.jogamp.opengl.GLCapabilities;
36import com.jogamp.opengl.GLCapabilitiesImmutable;
37import com.jogamp.opengl.GLContext;
38import com.jogamp.opengl.GLDrawable;
39import com.jogamp.opengl.GLDrawableFactory;
40import com.jogamp.opengl.GLProfile;
41
42import org.junit.BeforeClass;
43import org.junit.FixMethodOrder;
44import org.junit.Test;
45import org.junit.runners.MethodSorters;
46
47import com.jogamp.common.os.Platform;
48import com.jogamp.newt.Display;
49import com.jogamp.newt.NewtFactory;
50import com.jogamp.newt.Screen;
51import com.jogamp.opengl.test.junit.util.MiscUtils;
52import com.jogamp.opengl.test.junit.util.UITestCase;
53
54/**
55 * Raw initialization of multiple offscreen GLAutoDrawables
56 */
57@FixMethodOrder(MethodSorters.NAME_ASCENDING)
59
60 @BeforeClass
61 public static void initClass() {
63 }
64
65 public void testChooseOnly(final int runNum, final Screen screen, final int count) throws InterruptedException {
66 final long[] t = new long[10];
67 final GLProfile glp = GLProfile.getGL2ES2();
68 final int[] chosenCfgs = { 0 };
69
70 final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
71 final GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(screen.getDisplay().getGraphicsDevice(), caps);
72
73 if( wait && 0 == runNum ) {
74 UITestCase.waitForKey("Pre-Init");
75 }
76 System.err.println("INIT START #"+runNum);
77 screen.getDisplay().getEDTUtil().invoke(true, new Runnable() {
78 public void run() {
79 t[0] = Platform.currentTimeMillis();
80 for(int i=0; i<count; i++) {
81 final AbstractGraphicsConfiguration cfg = factory.chooseGraphicsConfiguration(caps, caps, null, screen.getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
82 if( null != cfg ) {
83 chosenCfgs[0]++;
84 }
85 }
86 t[1] = Platform.currentTimeMillis();
87 } } );
88
89 final double countF = count;
90 System.err.printf("Run: %d, count %d/%d raw:%n\tchoose\t%6d/t %6.2f/1%n",
91 runNum, chosenCfgs[0], count, t[1]-t[0], (t[1]-t[0])/countF);
92 System.err.println("INIT END #"+runNum);
93 if( wait && 2 == runNum ) {
94 UITestCase.waitForKey("Post-Init");
95 }
96 }
97
98 public void testFull(final int runNum, final int width, final int height, final int count) {
99 // panel.setBounds(0, 0, width, height);
100 final long[] t = new long[10];
101 final GLDrawable[] glDrawables = new GLDrawable[count];
102 final GLContext[] glConti = new GLContext[count];
103 final GLProfile glp = GLProfile.getGL2ES2();
104 final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
106 if( wait && 0 == runNum ) {
107 UITestCase.waitForKey("Pre-Init");
108 }
109 System.err.println("INIT START #"+runNum);
110 t[0] = Platform.currentTimeMillis();
111 for(int i=0; i<count; i++) {
112 glDrawables[i] = factory.createOffscreenDrawable(null, caps, null, width, height);
113 }
114 t[1] = Platform.currentTimeMillis();
115 for(int i=0; i<count; i++) {
116 glDrawables[i].setRealized(true);
117 }
118 t[2] = Platform.currentTimeMillis();
119 // 1st makeCurrent - context creation incl. release
120 for(int i=0; i<count; i++) {
121 final GLContext context = glDrawables[i].createContext(null);
122 if( GLContext.CONTEXT_NOT_CURRENT >= context.makeCurrent() ) {
123 // oops
124 glDrawables[i].setRealized(false);
125 glDrawables[i] = null;
126 glConti[i] = null;
127 continue;
128 }
129 glConti[i] = context;
130 context.release();
131 }
132 t[3] = Platform.currentTimeMillis();
133 // 2nd makeCurrent and release
134 for(int i=0; i<count; i++) {
135 final GLContext context = glConti[i];
136 if( GLContext.CONTEXT_NOT_CURRENT >= context.makeCurrent() ) {
137 // oops
138 glDrawables[i].setRealized(false);
139 glDrawables[i] = null;
140 glConti[i] = null;
141 continue;
142 }
143 context.release();
144 }
145 t[4] = Platform.currentTimeMillis();
146
147 final double countF = count;
148 System.err.printf("Run: %d, count %d raw:%n\tglad-create\t%6d/t %6.2f/1%n"+
149 "\tglad-realize\t%6d/t %6.2f/1%n"+
150 "\tctx-create1\t%6d/t %6.2f/1%n"+
151 "\tctx-curren2\t%6d/t %6.2f/1%n"+
152 "\tglad-ctx-init\t%6d/t %6.2f/1%n",
153 runNum, count,
154 t[1]-t[0], (t[1]-t[0])/countF, // create
155 t[2]-t[1], (t[2]-t[1])/countF, // realize
156 t[3]-t[2], (t[3]-t[2])/countF, // context-create1
157 t[4]-t[3], (t[4]-t[3])/countF, // context-curren2
158 t[3]-t[0], (t[3]-t[0])/countF);// init total
159 System.err.println("INIT END #"+runNum);
160 if( wait && 2 == runNum ) {
161 UITestCase.waitForKey("Post-Init");
162 }
163
164 // destroy
165 for(int i=0; i<count; i++) {
166 final GLContext context = glConti[i];
167 if( null != context ) {
168 context.destroy();
169 }
170 final GLDrawable glDrawable = glDrawables[i];
171 if( null != glDrawable ) {
172 glDrawable.setRealized(false);
173 }
174 glConti[i] = null;
175 glDrawables[i] = null;
176 }
177 }
178
179 @Test
180 public void test01ChooseOnly() throws InterruptedException, InvocationTargetException {
181 if( 0 != manualTest && 1 != manualTest ) {
182 return;
183 }
184 final Display display = NewtFactory.createDisplay(null, false);
185 final Screen screen = NewtFactory.createScreen(display, 0);
186 screen.addReference();
187 try {
188 testChooseOnly(0, screen, count); // warm-up
189 testChooseOnly(1, screen, count);
190 testChooseOnly(2, screen, count);
191 } finally {
192 screen.removeReference();
193 }
194 }
195
196 @Test
197 public void test02Full() throws InterruptedException, InvocationTargetException {
198 if( 0 != manualTest && 2 != manualTest ) {
199 return;
200 }
201 testFull(0, width, height, count); // warm-up
202 testFull(1, width, height, count);
203 testFull(2, width, height, count);
204 }
205
206 static boolean wait = false;
207 static int manualTest = 0;
208 static int width = 800, height = 600, count = 50;
209
210 public static void main(final String[] args) {
211 boolean waitMain = false;
212
213 for(int i=0; i<args.length; i++) {
214 if(args[i].equals("-width")) {
215 width = MiscUtils.atoi(args[++i], width);
216 } else if(args[i].equals("-height")) {
217 height = MiscUtils.atoi(args[++i], height);
218 } else if(args[i].equals("-count")) {
219 count = MiscUtils.atoi(args[++i], count);
220 } else if(args[i].equals("-wait")) {
221 wait = true;
222 } else if(args[i].equals("-waitMain")) {
223 waitMain = true;
224 } else if(args[i].equals("-test")) {
225 manualTest = MiscUtils.atoi(args[++i], manualTest);
226 }
227 }
228 if( waitMain ) {
229 UITestCase.waitForKey("Main-Start");
230 }
231 org.junit.runner.JUnitCore.main(TestPerf001RawInit00NEWT.class.getName());
232 }
233
234}
Provides the mechanism by which the graphics configuration for a window can be chosen before the wind...
final AbstractGraphicsConfiguration chooseGraphicsConfiguration(final CapabilitiesImmutable capsChosen, final CapabilitiesImmutable capsRequested, final CapabilitiesChooser chooser, final AbstractGraphicsScreen screen, final int nativeVisualID)
static GraphicsConfigurationFactory getFactory(final AbstractGraphicsDevice device, final CapabilitiesImmutable caps)
Returns the graphics configuration factory for use with the given device and capability.
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
abstract int addReference()
See Display#addReference().
abstract int removeReference()
See Display#removeReference().
Specifies a set of OpenGL capabilities.
Abstraction for an OpenGL rendering context.
Definition: GLContext.java:74
static final int CONTEXT_NOT_CURRENT
Indicates that the context was not made current during the last call to makeCurrent,...
Definition: GLContext.java:112
abstract int makeCurrent()
Makes this GLContext current on the calling thread.
abstract void release()
Releases control of this GLContext from the current thread.
abstract void destroy()
Destroys this OpenGL context and frees its associated resources.
abstract GLDrawable createOffscreenDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates an unrealized offscreen GLDrawable incl it's offscreen NativeSurface with the given capabilit...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
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
Raw initialization of multiple offscreen GLAutoDrawables.
void testChooseOnly(final int runNum, final Screen screen, final int count)
void testFull(final int runNum, final int width, final int height, final int count)
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
A marker interface describing a graphics configuration, visual, or pixel format in a toolkit-independ...
static final int VID_UNDEFINED
getVisualID(VIDType) result indicating an undefined value, which could be cause by an unsupported que...
Specifies an immutable set of OpenGL capabilities.
An abstraction for an OpenGL rendering target.
Definition: GLDrawable.java:51
void setRealized(boolean realized)
Indicates to GLDrawable implementations whether the underlying surface has been created and can be dr...
GLContext createContext(GLContext shareWith)
Creates a new context for drawing to this drawable that will optionally share buffer objects,...