29package com.jogamp.opengl.test.junit.jogl.demos.es2.newt;
31import java.io.IOException;
32import java.lang.reflect.InvocationTargetException;
34import com.jogamp.junit.util.JunitTracer;
35import com.jogamp.newt.Display;
36import com.jogamp.newt.MonitorDevice;
37import com.jogamp.newt.NewtFactory;
38import com.jogamp.newt.Screen;
39import com.jogamp.newt.Window;
40import com.jogamp.newt.event.WindowEvent;
41import com.jogamp.newt.event.KeyAdapter;
42import com.jogamp.newt.event.KeyEvent;
43import com.jogamp.newt.event.TraceMouseAdapter;
44import com.jogamp.newt.event.WindowAdapter;
45import com.jogamp.newt.opengl.GLWindow;
46import com.jogamp.newt.opengl.util.NEWTDemoListener;
47import com.jogamp.newt.util.EDTUtil;
48import com.jogamp.opengl.test.junit.util.MiscUtils;
49import com.jogamp.opengl.test.junit.util.NewtTestUtil;
50import com.jogamp.opengl.test.junit.util.UITestCase;
51import com.jogamp.opengl.util.Animator;
52import com.jogamp.opengl.util.AnimatorBase;
53import com.jogamp.opengl.test.junit.jogl.demos.GLClearOnInitReshape;
54import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
55import com.jogamp.opengl.test.junit.jogl.demos.es2.LineSquareXDemoES2;
56import com.jogamp.nativewindow.NativeWindowFactory;
57import com.jogamp.nativewindow.ScalableSurface;
58import com.jogamp.nativewindow.util.Dimension;
59import com.jogamp.nativewindow.util.Point;
60import com.jogamp.nativewindow.util.PointImmutable;
61import com.jogamp.nativewindow.util.DimensionImmutable;
62import com.jogamp.opengl.GL;
63import com.jogamp.opengl.GLAnimatorControl;
64import com.jogamp.opengl.GLAutoDrawable;
65import com.jogamp.opengl.GLCapabilities;
66import com.jogamp.opengl.GLCapabilitiesImmutable;
67import com.jogamp.opengl.GLEventListener;
68import com.jogamp.opengl.GLPipelineFactory;
69import com.jogamp.opengl.GLProfile;
71import jogamp.newt.DefaultEDTUtil;
73import org.junit.Assert;
74import org.junit.BeforeClass;
75import org.junit.AfterClass;
77import org.junit.FixMethodOrder;
78import org.junit.runners.MethodSorters;
88@FixMethodOrder(MethodSorters.NAME_ASCENDING)
90 static int screenIdx = 0;
95 static long duration = 500;
96 static boolean opaque =
true;
97 static int forceAlpha = -1;
98 static boolean undecorated =
false;
99 static boolean alwaysOnTop =
false;
100 static boolean alwaysOnBottom =
false;
101 static boolean resizable =
true;
102 static boolean sticky =
false;
103 static boolean max_vert=
false;
104 static boolean max_horz=
false;
105 static boolean fullscreen =
false;
106 static int swapInterval = 1;
107 static boolean waitForKey =
false;
108 static boolean mouseVisible =
true;
109 static boolean mouseConfined =
false;
110 static boolean setPointerIcon =
false;
111 static boolean showFPS =
false;
112 static int loops = 1;
113 static boolean loop_shutdown =
false;
114 static boolean forceES2 =
false;
115 static boolean forceES3 =
false;
116 static boolean forceGL3 =
false;
117 static boolean forceGL2 =
false;
118 static boolean forceDebug =
false;
119 static boolean forceTrace =
false;
120 static int demoType = 1;
121 static boolean traceMouse =
false;
122 static boolean manualTest =
false;
123 static boolean exclusiveContext =
false;
124 static boolean useAnimator =
true;
125 static boolean useMappedBuffers =
false;
126 static enum SysExit { none, testExit, testError, testEDTError, displayExit, displayError, displayEDTError };
127 static SysExit sysExit = SysExit.none;
141 System.err.println(
"requested: vsync "+swapInterval+
", "+caps);
145 Assert.assertNotNull(glWindow);
164 if( 2 == demoType ) {
167 }
else if( 1 == demoType ) {
172 }
else if( 0 == demoType ) {
177 if( forceDebug || forceTrace ) {
185 }
catch (
final Exception e) {e.printStackTrace();}
192 }
catch (
final Exception e) {e.printStackTrace();}
200 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {}
220 JunitTracer.waitForKey(
"3s mark");
226 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
227 final int width,
final int height) { }
249 final GLWindow[] glWindow2 = {
null };
261 public void keyPressed(
final KeyEvent e) {
266 if(
null != glWindow2[0] && glWindow2[0].isNativeValid() ) {
276 if(
null != animator2 ) {
285 animator.
add(glWindow);
288 Assert.assertTrue(animator.isAnimating());
292 if( SysExit.displayError == sysExit || SysExit.displayExit == sysExit || SysExit.displayEDTError == sysExit ) {
303 if( ms >= duration/2 || ms >= 3000 ) {
304 if( SysExit.displayError == sysExit ) {
305 throw new Error(
"test error send from GLEventListener.display - "+Thread.currentThread());
306 }
else if ( SysExit.displayExit == sysExit ) {
307 System.err.println(
"exit(0) send from GLEventListener");
309 }
else if ( SysExit.displayEDTError == sysExit ) {
311 System.err.println(
"EDT invokeAndWaitError: upstream type "+upstream.getClass().getName());
312 if( upstream instanceof
Window ) {
313 final EDTUtil edt = ((
Window)upstream).getScreen().getDisplay().getEDTUtil();
314 System.err.println(
"EDT invokeAndWaitError: edt type "+edt.getClass().getName());
315 if( edt instanceof DefaultEDTUtil ) {
316 newtDemoListener.
doQuit();
317 ((DefaultEDTUtil)edt).invokeAndWaitError(
new Runnable() {
320 throw new RuntimeException(
"XXX Should never ever be seen! - "+Thread.currentThread());
332 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) { }
345 System.err.println(
"window insets: "+glWindow.
getInsets());
346 System.err.println(
"window bounds (window): "+glWindow.
getBounds());
350 System.err.println(
"HiDPI PixelScale: "+reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" (req) -> "+
351 valReqSurfacePixelScale[0]+
"x"+valReqSurfacePixelScale[1]+
" (val) -> "+
352 hasSurfacePixelScale1[0]+
"x"+hasSurfacePixelScale1[1]+
" (has)");
356 System.err.println(
"Monitor: "+mm);
361 if(
null != rwsize ) {
369 final long t0 = System.currentTimeMillis();
371 while(!newtDemoListener.
shouldQuit() && t1-t0<duration) {
373 t1 = System.currentTimeMillis();
374 if( SysExit.testError == sysExit || SysExit.testExit == sysExit || SysExit.testEDTError == sysExit) {
375 final long ms = t1-t0;
376 if( ms >= duration/2 || ms >= 3000 ) {
377 if( SysExit.testError == sysExit ) {
378 throw new Error(
"test error send from test thread");
379 }
else if ( SysExit.testExit == sysExit ) {
380 System.err.println(
"exit(0) send from test thread");
382 }
else if ( SysExit.testEDTError == sysExit ) {
384 System.err.println(
"EDT invokeAndWaitError: edt type "+edt.getClass().getName());
385 if( edt instanceof DefaultEDTUtil ) {
386 newtDemoListener.
doQuit();
387 ((DefaultEDTUtil)edt).invokeAndWaitError(
new Runnable() {
390 throw new RuntimeException(
"XXX Should never ever be seen!");
402 Assert.assertFalse(animator.isAnimating());
403 Assert.assertFalse(animator.
isStarted());
407 if(
null != glWindow2[0] && glWindow2[0].isNativeValid() ) {
418 for(
int i=1; i<=loops; i++) {
419 System.err.println(
"Loop "+i+
"/"+loops);
423 }
else if(forceES3) {
425 }
else if(forceES2) {
427 }
else if(forceGL2) {
434 if(-1 < forceAlpha) {
437 runTestGL(caps, undecorated);
446 if(manualTest)
return;
449 System.err.println(
"GLES2 n/a");
454 runTestGL(caps, undecorated);
459 if(manualTest)
return;
462 System.err.println(
"GL3 n/a");
467 runTestGL(caps, undecorated);
472 if( manualTest )
return;
478 runTestGL(caps, undecorated);
481 public static void main(
final String args[])
throws IOException {
482 int x=0, y=0, w=640, h=480, rw=-1, rh=-1;
483 boolean usePos =
false;
485 for(
int i=0; i<args.length; i++) {
486 if(args[i].equals(
"-time")) {
489 }
else if(args[i].equals(
"-translucent")) {
491 }
else if(args[i].equals(
"-forceAlpha")) {
494 }
else if(args[i].equals(
"-undecorated")) {
496 }
else if(args[i].equals(
"-atop")) {
498 }
else if(args[i].equals(
"-abottom")) {
499 alwaysOnBottom =
true;
500 }
else if(args[i].equals(
"-noresize")) {
502 }
else if(args[i].equals(
"-sticky")) {
504 }
else if(args[i].equals(
"-maxv")) {
506 }
else if(args[i].equals(
"-maxh")) {
508 }
else if(args[i].equals(
"-fullscreen")) {
510 }
else if(args[i].equals(
"-vsync")) {
513 }
else if(args[i].equals(
"-exclctx")) {
514 exclusiveContext =
true;
515 }
else if(args[i].equals(
"-noanim")) {
517 }
else if(args[i].equals(
"-es2")) {
519 }
else if(args[i].equals(
"-es3")) {
521 }
else if(args[i].equals(
"-gl3")) {
523 }
else if(args[i].equals(
"-gl2")) {
525 }
else if(args[i].equals(
"-debug")) {
527 }
else if(args[i].equals(
"-trace")) {
529 }
else if(args[i].equals(
"-mappedBuffers")) {
530 useMappedBuffers =
true;
531 }
else if(args[i].equals(
"-wait")) {
533 }
else if(args[i].equals(
"-mouseInvisible")) {
534 mouseVisible =
false;
535 }
else if(args[i].equals(
"-mouseConfine")) {
536 mouseConfined =
true;
537 }
else if(args[i].equals(
"-pointerIcon")) {
538 setPointerIcon =
true;
539 }
else if(args[i].equals(
"-showFPS")) {
541 }
else if(args[i].equals(
"-width")) {
544 }
else if(args[i].equals(
"-height")) {
547 }
else if(args[i].equals(
"-x")) {
551 }
else if(args[i].equals(
"-y")) {
555 }
else if(args[i].equals(
"-pixelScale")) {
557 final float pS =
MiscUtils.
atof(args[i], reqSurfacePixelScale[0]);
558 reqSurfacePixelScale[0] = pS;
559 reqSurfacePixelScale[1] = pS;
560 }
else if(args[i].equals(
"-rwidth")) {
563 }
else if(args[i].equals(
"-rheight")) {
566 }
else if(args[i].equals(
"-screen")) {
569 }
else if(args[i].equals(
"-loops")) {
572 }
else if(args[i].equals(
"-loop-shutdown")) {
573 loop_shutdown =
true;
574 }
else if(args[i].equals(
"-sysExit")) {
576 sysExit = SysExit.valueOf(args[i]);
577 }
else if(args[i].equals(
"-manual")) {
579 }
else if(args[i].equals(
"-demo")) {
582 }
else if(args[i].equals(
"-traceMouse")) {
587 if( 0 < rw && 0 < rh ) {
592 wpos =
new Point(x, y);
594 System.err.println(
"position "+wpos);
595 System.err.println(
"size "+wsize);
596 System.err.println(
"resize "+rwsize);
597 System.err.println(
"screen "+screenIdx);
598 System.err.println(
"translucent "+(!opaque));
599 System.err.println(
"forceAlpha "+forceAlpha);
600 System.err.println(
"undecorated "+undecorated);
601 System.err.println(
"atop "+alwaysOnTop);
602 System.err.println(
"abottom "+alwaysOnBottom);
603 System.err.println(
"resizable "+resizable);
604 System.err.println(
"sticky "+sticky);
605 System.err.println(
"max_vert "+max_vert);
606 System.err.println(
"max_horz "+max_horz);
607 System.err.println(
"fullscreen "+fullscreen);
608 System.err.println(
"mouseVisible "+mouseVisible);
609 System.err.println(
"mouseConfined "+mouseConfined);
610 System.err.println(
"pointerIcon "+setPointerIcon);
611 System.err.println(
"loops "+loops);
612 System.err.println(
"loop shutdown "+loop_shutdown);
613 System.err.println(
"forceES2 "+forceES2);
614 System.err.println(
"forceES3 "+forceES3);
615 System.err.println(
"forceGL3 "+forceGL3);
616 System.err.println(
"forceGL2 "+forceGL2);
617 System.err.println(
"forceDebug "+forceDebug);
618 System.err.println(
"forceTrace "+forceTrace);
619 System.err.println(
"swapInterval "+swapInterval);
620 System.err.println(
"exclusiveContext "+exclusiveContext);
621 System.err.println(
"useAnimator "+useAnimator);
622 System.err.println(
"sysExitWithin "+sysExit);
623 System.err.println(
"mappedBuffers "+useMappedBuffers);
624 System.err.println(
"demoType "+demoType);
625 System.err.println(
"traceMouse "+traceMouse);
628 JunitTracer.waitForKey(
"Start");
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
abstract EDTUtil getEDTUtil()
Visual output device, i.e.
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.
abstract Display getDisplay()
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final String getStateMaskString()
Returns a string representation of the current state mask.
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void setPointerVisible(final boolean mouseVisible)
Makes the pointer visible or invisible.
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
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.
final void setTitle(final String title)
final void setAlwaysOnTop(final boolean value)
final float[] getRequestedSurfaceScale(final float[] result)
Returns the requested pixel scale of the associated NativeSurface.
final void setMaximized(final boolean horz, final boolean vert)
final int getX()
Returns the current x position of this window, relative to it's parent.
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
final float[] getCurrentSurfaceScale(final float[] result)
Returns the current pixel scale of the associated NativeSurface.
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final String getSupportedStateMaskString()
Returns a string representation of the supported state mask.
final Rectangle getSurfaceBounds()
Returns a newly created Rectangle containing window's surface origin and size in pixel units.
final MonitorDevice getMainMonitor()
Returns the MonitorDevice with the highest viewport coverage of this window.
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
final void setAlwaysOnBottom(final boolean value)
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final Rectangle getBounds()
Returns a newly created Rectangle containing window origin, getX() & getY(), and size,...
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final int getHeight()
Returns the height of the client area excluding insets (window decorations) in window units.
final void setSticky(final boolean value)
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
final void setResizable(final boolean value)
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
final void setUndecorated(final boolean value)
final boolean setSurfaceScale(final float[] pixelScale)
Request a pixel scale in x- and y-direction for the associated NativeSurface, where size_in_pixel_uni...
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
final int getWidth()
Returns the width of the client area excluding insets (window decorations) in window units.
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
final void confinePointer(final boolean grab)
Confine the pointer to this window, ie.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
NEWT GLWindow Demo functionality.
void quitAdapterEnable(final boolean v)
Specifies a set of OpenGL capabilities.
abstract GL setGL(GL gl)
Sets the GL pipeline object for this GLContext.
Factory for pipelining GL instances.
static final GL create(final String pipelineClazzBaseName, final Class<?> reqInterface, final GL downstream, final Object[] additionalArgs)
Creates a pipelined GL instance using the given downstream downstream and optional arguments addition...
Specifies the the OpenGL profile.
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
static final String GLES3
The embedded OpenGL profile ES 3.x, with x >= 0.
static final String GL3
The desktop OpenGL core profile 3.x, with x >= 1.
static void shutdown()
Manual shutdown method, may be called after your last JOGL use within the running JVM.
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
void setValidateBuffers(final boolean v)
void setUseMappedBuffers(final boolean v)
static void releaseClass()
static void main(final String args[])
void test99_PixelScale1_DefaultNorm()
void runTestGL(final GLCapabilitiesImmutable caps, final boolean undecorated)
static float atof(final String str, final float def)
static int atoi(final String str, final int def)
static long atol(final String str, final long def)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
final synchronized Thread getThread()
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized Thread setExclusiveContext(final Thread t)
Dedicate all GLAutoDrawable's context to the given exclusive context thread.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Adding mutable surface pixel scale property to implementing class, usually to a NativeSurface impleme...
static final float IDENTITY_PIXELSCALE
Setting surface-pixel-scale of {@value}, results in same pixel- and window-units.
static final float AUTOMAX_PIXELSCALE
Setting surface-pixel-scale of {@value}, results in maximum platform dependent pixel-scale,...
Immutable Dimension Interface, consisting of it's read only components:
Immutable Point interface.
Specifying NEWT's Window functionality:
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
EDT stands for Event Dispatch Thread.
void resetFPSCounter()
Reset all performance counter (startTime, currentTime, frame number)
long getTotalFPSDuration()
An animator control interface, which implementation may drive a com.jogamp.opengl....
boolean isAnimating()
Indicates whether this animator is started and is not paused.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GLAnimatorControl getAnimator()
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
Object getUpstreamWidget()
Method may return the upstream UI toolkit object holding this GLAutoDrawable instance,...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Thread getExclusiveContextThread()
GLContext getContext()
Returns the GLContext associated which this GL object.
Specifies an immutable set of OpenGL capabilities.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.