29package com.jogamp.opengl.test.junit.jogl.demos.es2.newt;
31import java.awt.BorderLayout;
32import java.awt.Button;
33import java.awt.Component;
34import java.awt.Container;
36import java.awt.TextArea;
37import java.awt.event.ComponentEvent;
38import java.awt.event.ComponentListener;
39import java.io.IOException;
40import java.lang.reflect.InvocationTargetException;
42import com.jogamp.common.os.Platform;
43import com.jogamp.newt.Display;
44import com.jogamp.newt.NewtFactory;
45import com.jogamp.newt.Screen;
46import com.jogamp.newt.awt.NewtCanvasAWT;
47import com.jogamp.newt.event.WindowEvent;
48import com.jogamp.newt.event.WindowAdapter;
49import com.jogamp.newt.opengl.GLWindow;
50import com.jogamp.newt.opengl.util.NEWTDemoListener;
51import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
52import com.jogamp.opengl.test.junit.util.MiscUtils;
53import com.jogamp.opengl.test.junit.util.NewtTestUtil;
54import com.jogamp.opengl.test.junit.util.UITestCase;
55import com.jogamp.opengl.util.Animator;
56import com.jogamp.opengl.util.AnimatorBase;
57import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
58import com.jogamp.opengl.test.junit.newt.parenting.NewtAWTReparentingKeyAdapter;
59import com.jogamp.opengl.test.junit.newt.parenting.NewtReparentingKeyAdapter;
61import com.jogamp.nativewindow.ScalableSurface;
62import com.jogamp.nativewindow.util.Dimension;
63import com.jogamp.nativewindow.util.Point;
64import com.jogamp.nativewindow.util.PointImmutable;
65import com.jogamp.nativewindow.util.DimensionImmutable;
66import com.jogamp.opengl.GLCapabilities;
67import com.jogamp.opengl.GLCapabilitiesImmutable;
68import com.jogamp.opengl.GLProfile;
69import javax.swing.SwingUtilities;
71import org.junit.Assert;
72import org.junit.Assume;
73import org.junit.BeforeClass;
74import org.junit.AfterClass;
76import org.junit.FixMethodOrder;
77import org.junit.runners.MethodSorters;
87@FixMethodOrder(MethodSorters.NAME_ASCENDING)
89 public enum FrameLayout { None, TextOnBottom,
BorderBottom, BorderBottom2, BorderCenter, BorderCenterSurrounded, DoubleBorderCenterSurrounded };
92 static int screenIdx = 0;
99 static long duration = 500;
100 static boolean opaque =
true;
101 static int forceAlpha = -1;
102 static boolean fullscreen =
false;
103 static int swapInterval = 1;
104 static boolean showFPS =
false;
105 static int loops = 1;
106 static boolean loop_shutdown =
false;
107 static boolean shallUseOffscreenFBOLayer =
false;
108 static boolean forceES2 =
false;
109 static boolean forceGL3 =
false;
110 static boolean manualTest =
false;
111 static boolean exclusiveContext =
false;
112 static boolean useAnimator =
true;
131 if(
null != frame ) {
132 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
138 }
catch(
final Throwable throwable ) {
139 throwable.printStackTrace();
140 Assume.assumeNoException( throwable );
143 static void setComponentSize(
final Frame frame,
final Component comp,
final DimensionImmutable new_sz) {
145 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
148 final java.awt.Dimension d =
new java.awt.Dimension(new_sz.getWidth(), new_sz.getHeight());
149 comp.setMinimumSize(d);
150 comp.setPreferredSize(d);
152 if(
null != frame ) {
156 }
catch(
final Throwable throwable ) {
157 throwable.printStackTrace();
158 Assume.assumeNoException( throwable );
161 static void setFrameSize(
final Frame frame,
final boolean frameLayout,
final DimensionImmutable new_sz) {
163 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
166 final java.awt.Dimension d =
new java.awt.Dimension(new_sz.getWidth(), new_sz.getHeight());
172 }
catch(
final Throwable throwable ) {
173 throwable.printStackTrace();
174 Assume.assumeNoException( throwable );
178 static void setSize(
final ResizeBy resizeBy,
final Frame frame,
final boolean frameLayout,
final Component comp,
final GLWindow glw,
final DimensionImmutable new_sz) {
181 setGLWindowSize(frameLayout ? frame :
null, glw, new_sz);
184 setComponentSize(frameLayout ? frame :
null, comp, new_sz);
187 setFrameSize(frame, frameLayout, new_sz);
194 System.err.println(
"requested: vsync "+swapInterval+
", "+caps);
198 Assert.assertNotNull(glWindow);
203 if ( shallUseOffscreenFBOLayer ) {
207 final Frame frame =
new Frame(
"AWT Parent Frame");
209 setSize(resizeBy, frame,
false, newtCanvasAWT, glWindow, wsize);
211 switch( frameLayout) {
213 frame.add(newtCanvasAWT);
216 final TextArea ta =
new TextArea(2, 20);
217 ta.append(
"0123456789");
218 ta.append(Platform.getNewline());
219 ta.append(
"Some Text");
220 ta.append(Platform.getNewline());
221 frame.setLayout(
new BorderLayout());
222 frame.add(ta, BorderLayout.SOUTH);
223 frame.add(newtCanvasAWT, BorderLayout.CENTER);
226 frame.setLayout(
new BorderLayout());
227 frame.add(newtCanvasAWT, BorderLayout.SOUTH);
230 frame.setLayout(
new BorderLayout());
231 frame.add(newtCanvasAWT, BorderLayout.SOUTH);
232 frame.add(
new Button(
"North"), BorderLayout.NORTH);
235 frame.setLayout(
new BorderLayout());
236 frame.add(newtCanvasAWT, BorderLayout.CENTER);
238 case BorderCenterSurrounded:
239 frame.setLayout(
new BorderLayout());
240 frame.add(
new Button(
"NORTH"), BorderLayout.NORTH);
241 frame.add(
new Button(
"SOUTH"), BorderLayout.SOUTH);
242 frame.add(
new Button(
"EAST"), BorderLayout.EAST);
243 frame.add(
new Button(
"WEST"), BorderLayout.WEST);
244 frame.add(newtCanvasAWT, BorderLayout.CENTER);
246 case DoubleBorderCenterSurrounded:
247 final Container c =
new Container();
248 c.setLayout(
new BorderLayout());
249 c.add(
new Button(
"north"), BorderLayout.NORTH);
250 c.add(
new Button(
"south"), BorderLayout.SOUTH);
251 c.add(
new Button(
"east"), BorderLayout.EAST);
252 c.add(
new Button(
"west"), BorderLayout.WEST);
253 c.add(newtCanvasAWT, BorderLayout.CENTER);
255 frame.setLayout(
new BorderLayout());
256 frame.add(
new Button(
"NORTH"), BorderLayout.NORTH);
257 frame.add(
new Button(
"SOUTH"), BorderLayout.SOUTH);
258 frame.add(
new Button(
"EAST"), BorderLayout.EAST);
259 frame.add(
new Button(
"WEST"), BorderLayout.WEST);
260 frame.add(c, BorderLayout.CENTER);
273 frame.addComponentListener(
new ComponentListener() {
275 public void componentResized(
final ComponentEvent e) {
279 public void componentMoved(
final ComponentEvent e) {
283 public void componentShown(
final ComponentEvent e) { }
286 public void componentHidden(
final ComponentEvent e) { }
306 animator.
add(glWindow);
309 Assert.assertTrue(animator.isAnimating());
313 SwingUtilities.invokeAndWait(
new Runnable() {
321 frame.setVisible(
true);
336 System.err.println(
"HiDPI PixelScale: "+reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" (req) -> "+
337 valReqSurfacePixelScale[0]+
"x"+valReqSurfacePixelScale[1]+
" (val) -> "+
338 hasSurfacePixelScale1[0]+
"x"+hasSurfacePixelScale1[1]+
" (has)");
341 if(
null != rwsize ) {
343 setSize(resizeBy, frame,
true, newtCanvasAWT, glWindow, rwsize);
347 final long t0 = System.currentTimeMillis();
349 while(!newtDemoListener.
shouldQuit() && t1-t0<duration) {
351 t1 = System.currentTimeMillis();
357 Assert.assertFalse(animator.isAnimating());
358 Assert.assertFalse(animator.
isStarted());
361 SwingUtilities.invokeAndWait(
new Runnable() {
372 public void test01GL2ES2() throws InterruptedException, InvocationTargetException {
373 for(
int i=1; i<=loops; i++) {
374 System.err.println(
"Loop "+i+
"/"+loops);
378 }
else if(forceES2) {
385 if(-1 < forceAlpha) {
388 runTestGL(caps, resizeBy, frameLayout);
396 public void test02GL3() throws InterruptedException, InvocationTargetException {
397 if(manualTest)
return;
400 System.err.println(
"GL3 n/a");
405 runTestGL(caps, resizeBy, frameLayout);
410 if( manualTest )
return;
416 runTestGL(caps, resizeBy, frameLayout);
419 public static void main(
final String args[])
throws IOException {
420 int x=0, y=0, w=640, h=480;
422 boolean usePos =
false;
424 for(
int i=0; i<args.length; i++) {
425 if(args[i].equals(
"-time")) {
428 }
else if(args[i].equals(
"-rwidth")) {
431 }
else if(args[i].equals(
"-rheight")) {
434 }
else if(args[i].equals(
"-layout")) {
437 }
else if(args[i].equals(
"-resizeBy")) {
439 resizeBy =
ResizeBy.valueOf(args[i]);
440 }
else if(args[i].equals(
"-translucent")) {
442 }
else if(args[i].equals(
"-forceAlpha")) {
445 }
else if(args[i].equals(
"-fullscreen")) {
447 }
else if(args[i].equals(
"-vsync")) {
450 }
else if(args[i].equals(
"-layeredFBO")) {
451 shallUseOffscreenFBOLayer =
true;
452 }
else if(args[i].equals(
"-exclctx")) {
453 exclusiveContext =
true;
454 }
else if(args[i].equals(
"-noanim")) {
456 }
else if(args[i].equals(
"-es2")) {
458 }
else if(args[i].equals(
"-gl3")) {
460 }
else if(args[i].equals(
"-showFPS")) {
462 }
else if(args[i].equals(
"-width")) {
465 }
else if(args[i].equals(
"-height")) {
468 }
else if(args[i].equals(
"-x")) {
472 }
else if(args[i].equals(
"-y")) {
476 }
else if(args[i].equals(
"-pixelScale")) {
478 final float pS =
MiscUtils.
atof(args[i], reqSurfacePixelScale[0]);
479 reqSurfacePixelScale[0] = pS;
480 reqSurfacePixelScale[1] = pS;
481 }
else if(args[i].equals(
"-screen")) {
484 }
else if(args[i].equals(
"-loops")) {
487 }
else if(args[i].equals(
"-loop-shutdown")) {
488 loop_shutdown =
true;
489 }
else if(args[i].equals(
"-manual")) {
494 if( 0 < rw && 0 < rh ) {
499 wpos =
new Point(x, y);
502 System.err.println(
"frameLayout "+frameLayout);
503 System.err.println(
"resizeBy "+resizeBy);
504 System.err.println(
"position "+wpos);
505 System.err.println(
"size "+wsize);
506 System.err.println(
"resize "+rwsize);
507 System.err.println(
"screen "+screenIdx);
508 System.err.println(
"translucent "+(!opaque));
509 System.err.println(
"forceAlpha "+forceAlpha);
510 System.err.println(
"fullscreen "+fullscreen);
511 System.err.println(
"loops "+loops);
512 System.err.println(
"loop shutdown "+loop_shutdown);
513 System.err.println(
"shallUseOffscreenFBOLayer "+shallUseOffscreenFBOLayer);
514 System.err.println(
"forceES2 "+forceES2);
515 System.err.println(
"forceGL3 "+forceGL3);
516 System.err.println(
"swapInterval "+swapInterval);
517 System.err.println(
"exclusiveContext "+exclusiveContext);
518 System.err.println(
"useAnimator "+useAnimator);
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.
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.
AWT Canvas containing a NEWT Window using native parenting.
void setShallUseOffscreenLayer(final boolean v)
Request an offscreen layer, if supported.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
final float[] getRequestedSurfaceScale(final float[] result)
Returns the requested pixel scale of the associated NativeSurface.
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 void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
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 Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
void quitAdapterEnable(final boolean v)
Specifies a set of OpenGL capabilities.
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 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 GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
void runTestGL(final GLCapabilitiesImmutable caps, final ResizeBy resizeBy, final FrameLayout frameLayout)
static void releaseClass()
void test99_PixelScale1_DefaultNorm()
static void main(final String args[])
AWT specializing demo functionality of NewtReparentingKeyAdapter, includes NEWTDemoListener.
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
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.
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Thread getExclusiveContextThread()
Specifies an immutable set of OpenGL capabilities.