28package com.jogamp.opengl.test.junit.jogl.perf;
30import java.awt.Component;
31import java.awt.Dimension;
32import java.awt.GridLayout;
33import java.lang.reflect.InvocationTargetException;
34import java.util.ArrayList;
36import java.util.concurrent.atomic.AtomicInteger;
38import com.jogamp.opengl.GLAnimatorControl;
39import com.jogamp.opengl.GLAutoDrawable;
40import com.jogamp.opengl.GLCapabilities;
41import com.jogamp.opengl.GLCapabilitiesImmutable;
42import com.jogamp.opengl.GLEventListener;
43import com.jogamp.opengl.GLProfile;
44import com.jogamp.opengl.awt.GLCanvas;
45import com.jogamp.opengl.awt.GLJPanel;
46import javax.swing.JFrame;
47import javax.swing.JPanel;
48import javax.swing.SwingUtilities;
50import org.junit.Assume;
51import org.junit.BeforeClass;
52import org.junit.FixMethodOrder;
54import org.junit.runners.MethodSorters;
56import com.jogamp.common.os.Platform;
57import com.jogamp.newt.awt.NewtCanvasAWT;
58import com.jogamp.newt.opengl.GLWindow;
59import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
60import com.jogamp.opengl.test.junit.util.MiscUtils;
61import com.jogamp.opengl.test.junit.util.UITestCase;
62import com.jogamp.opengl.util.Animator;
67@FixMethodOrder(MethodSorters.NAME_ASCENDING)
69 final long INIT_TIMEOUT = 10L*1000L;
76 static enum CanvasType { GLCanvas_T, GLJPanel_T, NewtCanvasAWT_T };
78 static class GLADComp {
87 final int columns,
final CanvasType canvasType,
final boolean useAnim) {
92 final List<NewtCanvasAWT> newtCanvasAWTList =
new ArrayList<NewtCanvasAWT>();
95 frame =
new JFrame(getSimpleTestName(
"."));
97 panel.setLayout(
new GridLayout(rows, columns));
99 final int panelCount = rows*columns;
100 final Dimension eSize =
new Dimension(width/columns, height/rows);
101 final long[] t =
new long[10];
105 System.err.println(
"INIT START");
108 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
110 t[0] = Platform.currentTimeMillis();
111 for(
int i=0; i<panelCount; i++) {
112 final GLADComp gladComp;
115 gladComp = createGLCanvas(caps, useGears, animator, eSize);
118 gladComp = createGLJPanel(caps, useGears, animator, eSize);
120 case NewtCanvasAWT_T:
121 gladComp = createNewtCanvasAWT(caps, useGears, animator, eSize);
124 default:
throw new InternalError(
"XXX");
129 initCount.getAndIncrement();
136 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {}
138 panel.add(gladComp.comp);
140 t[1] = Platform.currentTimeMillis();
141 frame.getContentPane().add(panel);
145 frame.setVisible(
true);
146 t[2] = Platform.currentTimeMillis();
148 }
catch(
final Throwable throwable ) {
149 throwable.printStackTrace();
150 Assume.assumeNoException( throwable );
152 final long t0 = System.currentTimeMillis();
154 while( panelCount > initCount.get() && INIT_TIMEOUT > t1 - t0 ) {
157 System.err.println(
"Sleep initialized: "+initCount.get()+
"/"+panelCount);
158 }
catch (
final InterruptedException e1) {
159 e1.printStackTrace();
161 t1 = System.currentTimeMillis();
163 t[3] = Platform.currentTimeMillis();
164 final double panelCountF = initCount.get();
165 System.err.printf(
"P: %d %s:%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",
168 t[1]-t[0], (t[1]-t[0])/panelCountF,
169 t[3]-t[1], (t[3]-t[1])/panelCountF,
170 t[3]-t[0], (t[3]-t[0])/panelCountF);
171 System.err.println(
"INIT END: "+initCount.get()+
"/"+panelCount);
175 if(
null != animator ) {
179 Thread.sleep(duration);
180 }
catch (
final InterruptedException e1) {
181 e1.printStackTrace();
183 if(
null != animator ) {
186 t[4] = Platform.currentTimeMillis();
188 SwingUtilities.invokeAndWait(
new Runnable() {
190 while( !newtCanvasAWTList.isEmpty() ) {
191 newtCanvasAWTList.remove(0).destroy();
195 }
catch (
final Exception e1) {
196 e1.printStackTrace();
198 final long ti_net = (t[4]-t[0])-duration;
199 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",
201 t[4]-t[0], (t[4]-t[0])/panelCountF,
202 ti_net, ti_net/panelCountF);
203 System.err.println(
"Total: "+(t[4]-t[0]));
209 canvas.setSize(size);
210 canvas.setPreferredSize(size);
219 return new GLADComp(window, canvas);
222 final GLCanvas canvas =
new GLCanvas(caps);
223 canvas.setSize(size);
224 canvas.setPreferredSize(size);
226 canvas.addGLEventListener(
new GearsES2(0));
231 return new GLADComp(canvas, canvas);
233 private GLADComp createGLJPanel(
final GLCapabilitiesImmutable caps,
final boolean useGears,
final GLAnimatorControl anim,
final Dimension size) {
234 final GLJPanel canvas =
new GLJPanel(caps);
235 canvas.setSize(size);
236 canvas.setPreferredSize(size);
238 canvas.addGLEventListener(
new GearsES2(0));
243 return new GLADComp(canvas, canvas);
248 test(
new GLCapabilities(
null),
false , width, height, rows, cols, CanvasType.GLJPanel_T,
false );
255 test(caps,
false , width, height, rows, cols, CanvasType.GLJPanel_T,
false );
260 test(
new GLCapabilities(
null),
false , width, height, rows, cols, CanvasType.GLCanvas_T,
false );
265 test(
new GLCapabilities(
null),
true , width, height, rows, cols, CanvasType.GLJPanel_T,
true );
270 test(
new GLCapabilities(
null),
true , width, height, rows, cols, CanvasType.GLCanvas_T,
true );
275 test(
new GLCapabilities(
null),
true , width, height, rows, cols, CanvasType.NewtCanvasAWT_T,
true );
278 static long duration = 0;
279 static boolean wait =
false;
280 static int width = 800, height = 600, rows = 5, cols = 5;
282 AtomicInteger initCount =
new AtomicInteger(0);
284 public static void main(
final String[] args) {
285 CanvasType canvasType = CanvasType.GLJPanel_T;
286 boolean useGears =
false, manual=
false;
287 boolean waitMain =
false;
289 for(
int i=0; i<args.length; i++) {
290 if(args[i].equals(
"-time")) {
293 }
else if(args[i].equals(
"-width")) {
295 }
else if(args[i].equals(
"-height")) {
297 }
else if(args[i].equals(
"-rows")) {
299 }
else if(args[i].equals(
"-cols")) {
301 }
else if(args[i].equals(
"-type")) {
303 canvasType = CanvasType.valueOf(args[i]);
305 }
else if(args[i].equals(
"-gears")) {
307 }
else if(args[i].equals(
"-wait")) {
310 }
else if(args[i].equals(
"-waitMain")) {
313 }
else if(args[i].equals(
"-manual")) {
323 demo.
test(
null, useGears, width, height, rows, cols, canvasType, useGears );
void setBitmap(final boolean enable)
Requesting offscreen bitmap mode.
AWT Canvas containing a NEWT Window using native parenting.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static void initSingleton()
Static initialization of JOGL.
GearsES2 setVerbose(final boolean v)
Tests multiple [GLJPanels, GLCanvas or NewtCanvasAWT] in a JFrame's Grid.
void test11GearsGLJPanel()
void test02NopGLJPanelBMP()
void test(final GLCapabilitiesImmutable caps, final boolean useGears, final int width, final int height, final int rows, final int columns, final CanvasType canvasType, final boolean useAnim)
void test13GearsGLCanvas()
void test14GearsNewtCanvasAWT()
static void main(final String[] args)
static int atoi(final String str, final int def)
static long atol(final String str, final long def)
An animator control interface, which implementation may drive a com.jogamp.opengl....
boolean start()
Starts this animator, if not running.
boolean stop()
Stops this animator.
void add(GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
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.