28package com.jogamp.opengl.test.junit.jogl.perf;
30import java.awt.BorderLayout;
31import java.awt.Component;
32import java.awt.Dimension;
33import java.awt.Graphics;
34import java.lang.reflect.InvocationTargetException;
35import java.util.ArrayList;
37import java.util.concurrent.atomic.AtomicInteger;
39import com.jogamp.opengl.GLAnimatorControl;
40import com.jogamp.opengl.GLAutoDrawable;
41import com.jogamp.opengl.GLCapabilities;
42import com.jogamp.opengl.GLCapabilitiesImmutable;
43import com.jogamp.opengl.GLEventListener;
44import com.jogamp.opengl.GLProfile;
45import com.jogamp.opengl.awt.GLCanvas;
46import com.jogamp.opengl.awt.GLJPanel;
47import javax.swing.JFrame;
48import javax.swing.JPanel;
49import javax.swing.JTextArea;
50import javax.swing.SwingUtilities;
52import org.junit.Assume;
53import org.junit.BeforeClass;
54import org.junit.FixMethodOrder;
56import org.junit.runners.MethodSorters;
58import com.jogamp.common.os.Platform;
59import com.jogamp.newt.awt.NewtCanvasAWT;
60import com.jogamp.newt.opengl.GLWindow;
61import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
62import com.jogamp.opengl.test.junit.util.MiscUtils;
63import com.jogamp.opengl.test.junit.util.UITestCase;
64import com.jogamp.opengl.util.Animator;
69@FixMethodOrder(MethodSorters.NAME_ASCENDING)
71 final long INIT_TIMEOUT = 10L*1000L;
78 static enum CanvasType { NOP_T, GLCanvas_T, GLJPanel_T, NewtCanvasAWT_T };
80 static class GLADComp {
90 final int height,
final int frameCount,
final boolean initMT,
91 final boolean useSwingDoubleBuffer,
final CanvasType canvasType,
final boolean useAnim,
final boolean overlap) {
98 final int eWidth, eHeight;
100 final int cols = (int)Math.round(Math.sqrt(frameCount));
101 final int rows = frameCount / cols;
102 eWidth = width/cols-32;
103 eHeight = height/rows-32;
105 System.err.println(
"Frame size: "+width+
"x"+height+
" -> "+frameCount+
" x "+eWidth+
"x"+eHeight+
", overlap "+overlap);
106 System.err.println(
"SkipGLOrientationVerticalFlip "+skipGLOrientationVerticalFlip+
", useGears "+useGears+
", initMT "+initMT+
", useAnim "+useAnim);
107 final JFrame[] frame =
new JFrame[frameCount];
108 final List<NewtCanvasAWT> newtCanvasAWTList =
new ArrayList<NewtCanvasAWT>();
110 final long[] t =
new long[10];
114 System.err.println(
"INIT START");
117 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
119 t[0] = Platform.currentTimeMillis();
121 for(
int i=0; i<frameCount; i++) {
122 frame[i] =
new JFrame(i+
"/"+frameCount);
123 frame[i].setLocation(x, y);
131 final JPanel panel =
new JPanel();
132 panel.setLayout(
new BorderLayout());
133 panel.setDoubleBuffered(useSwingDoubleBuffer);
135 final Dimension eSize =
new Dimension(eWidth, eHeight);
136 final GLADComp gladComp;
139 gladComp = createGLCanvas(caps, useGears, animator, eSize);
142 gladComp = createGLJPanel(initMT, useSwingDoubleBuffer, caps, useGears, skipGLOrientationVerticalFlip, animator, eSize);
144 case NewtCanvasAWT_T:
145 gladComp = createNewtCanvasAWT(caps, useGears, animator, eSize);
151 default:
throw new InternalError(
"XXX");
154 if(
null != gladComp ) {
158 initCount.incrementAndGet();
165 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {}
167 panel.add(gladComp.comp);
169 @SuppressWarnings(
"serial")
170 final JTextArea c =
new JTextArea(
"area "+i) {
171 boolean initialized =
false, added =
false;
172 int reshapeWidth=0, reshapeHeight=0;
174 public void addNotify() {
178 @SuppressWarnings(
"deprecation")
180 public void reshape(
final int x,
final int y,
final int width,
final int height) {
181 super.reshape(x, y, width, height);
182 reshapeWidth = width; reshapeHeight = height;
185 protected void paintComponent(
final Graphics g) {
186 super.paintComponent(g);
187 if( !initialized && added && reshapeWidth > 0 && reshapeHeight > 0 && isDisplayable() ) {
189 initCount.incrementAndGet();
193 c.setEditable(
false);
195 c.setPreferredSize(eSize);
198 frame[i].getContentPane().add(panel);
203 t[1] = Platform.currentTimeMillis();
204 for(
int i=0; i<frameCount; i++) {
205 frame[i].setVisible(
true);
207 t[2] = Platform.currentTimeMillis();
209 }
catch(
final Throwable throwable ) {
210 throwable.printStackTrace();
211 Assume.assumeNoException( throwable );
213 final long t0 = System.currentTimeMillis();
215 while( frameCount > initCount.get() && INIT_TIMEOUT > t1 - t0 ) {
218 System.err.println(
"Sleep initialized: "+initCount+
"/"+frameCount);
219 }
catch (
final InterruptedException e1) {
220 e1.printStackTrace();
222 t1 = System.currentTimeMillis();
224 t[3] = Platform.currentTimeMillis();
225 final double panelCountF = initCount.get();
226 System.err.printf(
"P: %d %s%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",
228 canvasType, initMT?
" (mt)":
" (01)",
229 t[1]-t[0], (t[1]-t[0])/panelCountF,
230 t[3]-t[1], (t[3]-t[1])/panelCountF,
231 t[3]-t[0], (t[3]-t[0])/panelCountF);
233 System.err.println(
"INIT END: "+initCount+
"/"+frameCount);
237 if(
null != animator ) {
241 Thread.sleep(duration);
242 }
catch (
final InterruptedException e1) {
243 e1.printStackTrace();
245 if(
null != animator ) {
248 t[4] = Platform.currentTimeMillis();
250 SwingUtilities.invokeAndWait(
new Runnable() {
252 while( !newtCanvasAWTList.isEmpty() ) {
253 newtCanvasAWTList.remove(0).destroy();
255 for(
int i=0; i<frameCount; i++) {
259 }
catch (
final Exception e1) {
260 e1.printStackTrace();
263 final long ti_net = (t[4]-t[0])-duration;
264 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",
266 t[4]-t[0], (t[4]-t[0])/panelCountF,
267 ti_net, ti_net/panelCountF);
268 System.err.println(
"Total: "+(t[4]-t[0]));
274 canvas.setSize(size);
275 canvas.setPreferredSize(size);
284 return new GLADComp(window, canvas);
287 final GLCanvas canvas =
new GLCanvas(caps);
288 canvas.setSize(size);
289 canvas.setPreferredSize(size);
291 final GearsES2 g =
new GearsES2(0);
293 canvas.addGLEventListener(g);
298 return new GLADComp(canvas, canvas);
300 private GLADComp createGLJPanel(
final boolean initMT,
final boolean useSwingDoubleBuffer,
final GLCapabilitiesImmutable caps,
final boolean useGears,
final boolean skipGLOrientationVerticalFlip,
final GLAnimatorControl anim,
final Dimension size) {
301 final GLJPanel canvas =
new GLJPanel(caps);
302 canvas.setSize(size);
303 canvas.setPreferredSize(size);
304 canvas.setDoubleBuffered(useSwingDoubleBuffer);
305 if( skipGLOrientationVerticalFlip ) {
306 canvas.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip);
309 final GearsES2 g =
new GearsES2(0);
311 g.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
312 canvas.addGLEventListener(g);
318 canvas.initializeBackend(
true );
320 return new GLADComp(canvas, canvas);
323 static GLCapabilitiesImmutable caps =
null;
331 test(
new GLCapabilities(
null),
false ,
false , width , height, frameCount,
false ,
332 false , CanvasType.NOP_T,
false ,
false );
337 test(
new GLCapabilities(
null),
false ,
false , width , height, frameCount,
false ,
338 false , CanvasType.GLCanvas_T,
false ,
false );
343 test(
new GLCapabilities(
null),
false ,
false , width , height, frameCount,
false ,
344 false , CanvasType.GLJPanel_T,
false ,
false );
349 test(
new GLCapabilities(
null),
false ,
true , width , height, frameCount,
false ,
350 false , CanvasType.GLJPanel_T,
false ,
false );
355 test(
new GLCapabilities(
null),
false ,
true , width , height, frameCount,
true ,
356 false , CanvasType.GLJPanel_T,
false ,
false );
361 test(
new GLCapabilities(
null),
false ,
false , width , height, frameCount,
false ,
362 false , CanvasType.NewtCanvasAWT_T,
false ,
false );
371 test(
new GLCapabilities(
null),
true ,
false , width , height, frameCount,
false ,
372 false , CanvasType.GLCanvas_T,
true ,
false );
377 test(
new GLCapabilities(
null),
true ,
false , width , height, frameCount,
false ,
378 false , CanvasType.GLJPanel_T,
true ,
false );
383 test(
new GLCapabilities(
null),
true ,
true , width , height, frameCount,
false ,
384 false , CanvasType.GLJPanel_T,
true ,
false );
389 test(
new GLCapabilities(
null),
true ,
true , width , height, frameCount,
true ,
390 false , CanvasType.GLJPanel_T,
true ,
false );
395 test(
new GLCapabilities(
null),
true ,
false , width , height, frameCount,
false ,
396 false , CanvasType.NewtCanvasAWT_T,
true ,
false );
406 test(
null,
false ,
false , width , height, frameCount,
false ,
407 false , CanvasType.NOP_T,
false ,
true );
412 test(
new GLCapabilities(
null),
false ,
false , width , height, frameCount,
false ,
413 false , CanvasType.GLCanvas_T,
false ,
true );
418 test(
new GLCapabilities(
null),
false ,
false , width , height, frameCount,
false ,
419 false , CanvasType.GLJPanel_T,
false ,
true );
424 test(
new GLCapabilities(
null),
false ,
false , width , height, frameCount,
true ,
425 false , CanvasType.GLJPanel_T,
false ,
true );
430 test(
new GLCapabilities(
null),
false ,
false , width , height, frameCount,
false ,
431 false , CanvasType.NewtCanvasAWT_T,
false ,
true );
436 test(
new GLCapabilities(
null),
false ,
false , width , height, frameCount,
false ,
437 false , CanvasType.GLJPanel_T,
false ,
true );
444 test(caps,
false ,
false , width , height, frameCount,
false ,
445 false , CanvasType.GLJPanel_T,
false ,
false);
448 static long duration = 0;
449 static boolean wait =
false;
450 static int width = 800, height = 600, frameCount = 25;
452 AtomicInteger initCount =
new AtomicInteger(0);
454 public static void main(
final String[] args) {
455 boolean manual=
false;
456 boolean waitMain =
false;
457 CanvasType canvasType = CanvasType.GLJPanel_T;
458 boolean initMT =
false, useSwingDoubleBuffer=
false;
459 boolean useGears =
false, skipGLOrientationVerticalFlip=
false, useAnim =
false;
460 boolean overlap =
false;
462 for(
int i=0; i<args.length; i++) {
463 if(args[i].equals(
"-time")) {
466 }
else if(args[i].equals(
"-width")) {
468 }
else if(args[i].equals(
"-height")) {
470 }
else if(args[i].equals(
"-count")) {
472 }
else if(args[i].equals(
"-initMT")) {
475 }
else if(args[i].equals(
"-type")) {
477 canvasType = CanvasType.valueOf(args[i]);
479 }
else if(args[i].equals(
"-swingDoubleBuffer")) {
480 useSwingDoubleBuffer =
true;
481 }
else if(args[i].equals(
"-gears")) {
483 }
else if(args[i].equals(
"-anim")) {
485 }
else if(args[i].equals(
"-userVertFlip")) {
486 skipGLOrientationVerticalFlip =
true;
487 }
else if(args[i].equals(
"-overlap")) {
489 }
else if(args[i].equals(
"-wait")) {
492 }
else if(args[i].equals(
"-waitMain")) {
495 }
else if(args[i].equals(
"-manual")) {
505 demo.
test(
null, useGears, skipGLOrientationVerticalFlip, width, height, frameCount,
506 initMT, useSwingDoubleBuffer, canvasType, useAnim, overlap);
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 JFrames each with a [GLJPanels, GLCanvas or NewtCanvasAWT].
void test13GearsGLJPanelDefGridSingleManualFlip()
void testXXNopGLJPanelBitmapGridSingle()
void testXXNopGLJPanelDefOverlapSingle()
void test04NopGLJPanelDefGridMTManualFlip()
void test25NopNewtCanvasAWTDefOverlap()
void test05NopNewtCanvasAWTDefGrid()
void test22NopGLJPanelDefOverlapSingle()
void test12GearsGLJPanelDefGridSingleAutoFlip()
static void main(final String[] args)
void test(final GLCapabilitiesImmutable caps, final boolean useGears, final boolean skipGLOrientationVerticalFlip, final int width, final int height, final int frameCount, final boolean initMT, final boolean useSwingDoubleBuffer, final CanvasType canvasType, final boolean useAnim, final boolean overlap)
void test21NopGLCanvasDefOverlap()
void test11GearsGLCanvasDefGrid()
void test00NopNoGLDefGrid()
void test20NopNoGLDefOverlap()
void test15GearsNewtCanvasAWTDefGrid()
void test14GearsGLJPanelDefGridMTManualFlip()
void test03NopGLJPanelDefGridSingleManualFlip()
void test01NopGLCanvasDefGrid()
void test02NopGLJPanelDefGridSingleAutoFlip()
void test23NopGLJPanelDefOverlapMT()
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.