29package com.jogamp.opengl.test.junit.jogl.demos.es2.awt;
31import com.jogamp.nativewindow.ScalableSurface;
32import com.jogamp.opengl.*;
34import com.jogamp.opengl.util.Animator;
36import com.jogamp.opengl.awt.GLCanvas;
38import com.jogamp.common.os.Platform;
39import com.jogamp.common.util.awt.AWTEDTExecutor;
40import com.jogamp.newt.event.awt.AWTKeyAdapter;
41import com.jogamp.newt.event.awt.AWTWindowAdapter;
42import com.jogamp.newt.event.KeyEvent;
43import com.jogamp.newt.event.TraceKeyAdapter;
44import com.jogamp.newt.event.TraceWindowAdapter;
45import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
46import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
47import com.jogamp.opengl.test.junit.util.MiscUtils;
48import com.jogamp.opengl.test.junit.util.UITestCase;
49import com.jogamp.opengl.test.junit.util.QuitAdapter;
51import java.awt.BorderLayout;
52import java.awt.Button;
53import java.awt.Component;
54import java.awt.Container;
55import java.awt.Dimension;
56import java.awt.EventQueue;
58import java.awt.TextArea;
59import java.io.BufferedReader;
60import java.io.IOException;
61import java.io.InputStreamReader;
62import java.lang.reflect.InvocationTargetException;
64import org.junit.Assert;
65import org.junit.Assume;
66import org.junit.BeforeClass;
67import org.junit.AfterClass;
69import org.junit.FixMethodOrder;
70import org.junit.runners.MethodSorters;
72@FixMethodOrder(MethodSorters.NAME_ASCENDING)
77 static long duration = 500;
78 static int width = 640, height = 480;
79 static int xpos = 10, ypos = 10;
84 static boolean forceES2 =
false;
85 static boolean forceGL3 =
false;
86 static boolean manualTest =
false;
87 static boolean shallUseOffscreenFBOLayer =
false;
88 static boolean shallUseOffscreenPBufferLayer =
false;
89 static boolean useMSAA =
false;
90 static boolean useStencil =
false;
91 static boolean shutdownRemoveGLCanvas =
true;
92 static boolean shutdownDisposeFrame =
true;
93 static boolean shutdownSystemExit =
false;
94 static int swapInterval = 1;
95 static boolean exclusiveContext =
false;
96 static boolean useAnimator =
true;
98 static java.awt.Dimension rwsize =
null;
103 EventQueue.invokeAndWait(
new Runnable() {
106 awtEDT = Thread.currentThread();
108 }
catch (
final Exception e) {
110 Assert.assertNull(e);
118 static void setComponentSize(
final Frame frame,
final Component comp,
final java.awt.Dimension new_sz) {
120 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
123 comp.setMinimumSize(new_sz);
124 comp.setPreferredSize(new_sz);
125 comp.setSize(new_sz);
126 if(
null != frame ) {
130 }
catch(
final Throwable throwable ) {
131 throwable.printStackTrace();
132 Assume.assumeNoException( throwable );
135 static void setFrameSize(
final Frame frame,
final boolean frameLayout,
final java.awt.Dimension new_sz) {
137 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
140 frame.setSize(new_sz);
145 }
catch(
final Throwable throwable ) {
146 throwable.printStackTrace();
147 Assume.assumeNoException( throwable );
151 static void setSize(
final ResizeBy resizeBy,
final Frame frame,
final boolean frameLayout,
final Component comp,
final java.awt.Dimension new_sz) {
154 setComponentSize(frameLayout ? frame :
null, comp, new_sz);
157 setFrameSize(frame, frameLayout, new_sz);
164 final java.awt.Rectangle b = glc.getBounds();
165 final float[] minSurfacePixelScale = glc.getMinimumSurfaceScale(
new float[2]);
166 final float[] maxSurfacePixelScale = glc.getMaximumSurfaceScale(
new float[2]);
167 final float[] reqSurfacePixelScale = glc.getRequestedSurfaceScale(
new float[2]);
168 final float[] hasSurfacePixelScale = glc.getCurrentSurfaceScale(
new float[2]);
169 AWTEDTExecutor.singleton.invoke(
false,
new Runnable() {
172 frame.setTitle(
"GLCanvas["+capsA+
"], swapI "+swapInterval+
", win: ["+b.x+
"/"+b.y+
" "+b.width+
"x"+b.height+
"], pix: "+glc.getSurfaceWidth()+
"x"+glc.getSurfaceHeight()+
173 ", scale[min "+minSurfacePixelScale[0]+
"x"+minSurfacePixelScale[1]+
", max "+
174 maxSurfacePixelScale[0]+
"x"+maxSurfacePixelScale[1]+
", req "+
175 reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" -> has "+
176 hasSurfacePixelScale[0]+
"x"+hasSurfacePixelScale[1]+
"]");
181 final Frame frame =
new Frame(
"GearsES2 AWT Test");
182 Assert.assertNotNull(frame);
185 Assert.assertNotNull(glCanvas);
186 setSize(resizeBy, frame,
false, glCanvas,
new Dimension(width, height));
189 frame.setLocation(xpos, ypos);
191 switch( frameLayout) {
196 final TextArea ta =
new TextArea(2, 20);
197 ta.append(
"0123456789");
198 ta.append(Platform.getNewline());
199 ta.append(
"Some Text");
200 ta.append(Platform.getNewline());
201 frame.setLayout(
new BorderLayout());
202 frame.add(ta, BorderLayout.SOUTH);
203 frame.add(glCanvas, BorderLayout.CENTER);
205 case BorderCenterSurrounded:
206 frame.setLayout(
new BorderLayout());
207 frame.add(
new Button(
"NORTH"), BorderLayout.NORTH);
208 frame.add(
new Button(
"SOUTH"), BorderLayout.SOUTH);
209 frame.add(
new Button(
"EAST"), BorderLayout.EAST);
210 frame.add(
new Button(
"WEST"), BorderLayout.WEST);
211 frame.add(glCanvas, BorderLayout.CENTER);
213 case DoubleBorderCenterSurrounded:
214 final Container c =
new Container();
215 c.setLayout(
new BorderLayout());
216 c.add(
new Button(
"north"), BorderLayout.NORTH);
217 c.add(
new Button(
"south"), BorderLayout.SOUTH);
218 c.add(
new Button(
"east"), BorderLayout.EAST);
219 c.add(
new Button(
"west"), BorderLayout.WEST);
220 c.add(glCanvas, BorderLayout.CENTER);
222 frame.setLayout(
new BorderLayout());
223 frame.add(
new Button(
"NORTH"), BorderLayout.NORTH);
224 frame.add(
new Button(
"SOUTH"), BorderLayout.SOUTH);
225 frame.add(
new Button(
"EAST"), BorderLayout.EAST);
226 frame.add(
new Button(
"WEST"), BorderLayout.WEST);
227 frame.add(c, BorderLayout.CENTER);
230 setTitle(frame, glCanvas, caps);
245 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {
246 setTitle(frame, glCanvas, caps);
251 if( useAnimator && exclusiveContext ) {
260 public void keyPressed(
final KeyEvent e) {
266 final float[] reqSurfacePixelScale;
272 System.err.println(
"[set PixelScale pre]: had "+hadSurfacePixelScale[0]+
"x"+hadSurfacePixelScale[1]+
" -> req "+reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]);
276 System.err.println(
"[set PixelScale post]: "+hadSurfacePixelScale[0]+
"x"+hadSurfacePixelScale[1]+
" (had) -> "+
277 reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" (req) -> "+
278 valReqSurfacePixelScale[0]+
"x"+valReqSurfacePixelScale[1]+
" (val) -> "+
279 hasSurfacePixelScale1[0]+
"x"+hasSurfacePixelScale1[1]+
" (has)");
280 setTitle(frame, glCanvas, caps);
285 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
293 frame.setVisible(
true);
299 System.err.println(
"HiDPI PixelScale: "+reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" (req) -> "+
300 valReqSurfacePixelScale[0]+
"x"+valReqSurfacePixelScale[1]+
" (val) -> "+
301 hasSurfacePixelScale1[0]+
"x"+hasSurfacePixelScale1[1]+
" (has)");
302 setTitle(frame, glCanvas, caps);
307 Assert.assertTrue(animator.isAnimating());
316 if(
null != rwsize ) {
318 setSize(resizeBy, frame,
true, glCanvas, rwsize);
324 final long t0 = System.currentTimeMillis();
326 while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
328 t1 = System.currentTimeMillis();
331 Assert.assertNotNull(frame);
332 Assert.assertNotNull(glCanvas);
335 Assert.assertNotNull(animator);
338 Assert.assertFalse(animator.isAnimating());
339 Assert.assertFalse(animator.
isStarted());
343 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
346 frame.setVisible(
false);
348 Assert.assertEquals(
false, frame.isVisible());
349 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
352 if(shutdownRemoveGLCanvas) {
353 frame.remove(glCanvas);
355 if(shutdownDisposeFrame) {
358 if(shutdownSystemExit) {
365 public void test01() throws InterruptedException, InvocationTargetException {
369 }
else if(forceES2) {
382 if(shallUseOffscreenFBOLayer) {
385 if(shallUseOffscreenPBufferLayer) {
388 runTestGL(caps, resizeBy, frameLayout);
392 public void test02_GLES2() throws InterruptedException, InvocationTargetException {
393 if(manualTest)
return;
396 System.err.println(
"GLES2 n/a");
401 runTestGL(caps, resizeBy, frameLayout);
405 public void test03_GL3() throws InterruptedException, InvocationTargetException {
406 if(manualTest)
return;
409 System.err.println(
"GL3 n/a");
414 runTestGL(caps, resizeBy, frameLayout);
419 if( manualTest )
return;
425 runTestGL(caps, resizeBy, frameLayout);
428 public static void main(
final String args[]) {
429 boolean waitForKey =
false;
432 for(
int i=0; i<args.length; i++) {
433 if(args[i].equals(
"-time")) {
436 }
else if(args[i].equals(
"-width")) {
439 }
else if(args[i].equals(
"-height")) {
442 }
else if(args[i].equals(
"-x")) {
445 }
else if(args[i].equals(
"-y")) {
448 }
else if(args[i].equals(
"-rwidth")) {
451 }
else if(args[i].equals(
"-rheight")) {
454 }
else if(args[i].equals(
"-pixelScale")) {
456 final float pS =
MiscUtils.
atof(args[i], reqSurfacePixelScale[0]);
457 reqSurfacePixelScale[0] = pS;
458 reqSurfacePixelScale[1] = pS;
459 }
else if(args[i].equals(
"-layout")) {
462 }
else if(args[i].equals(
"-resizeBy")) {
464 resizeBy =
ResizeBy.valueOf(args[i]);
465 }
else if(args[i].equals(
"-es2")) {
467 }
else if(args[i].equals(
"-gl3")) {
469 }
else if(args[i].equals(
"-vsync")) {
472 }
else if(args[i].equals(
"-exclctx")) {
473 exclusiveContext =
true;
474 }
else if(args[i].equals(
"-noanim")) {
476 }
else if(args[i].equals(
"-layeredFBO")) {
477 shallUseOffscreenFBOLayer =
true;
478 }
else if(args[i].equals(
"-layeredPBuffer")) {
479 shallUseOffscreenPBufferLayer =
true;
480 }
else if(args[i].equals(
"-msaa")) {
482 }
else if(args[i].equals(
"-stencil")) {
484 }
else if(args[i].equals(
"-wait")) {
486 }
else if(args[i].equals(
"-shutdownKeepGLCanvas")) {
487 shutdownRemoveGLCanvas =
false;
488 }
else if(args[i].equals(
"-shutdownKeepFrame")) {
489 shutdownDisposeFrame =
false;
490 }
else if(args[i].equals(
"-shutdownKeepAll")) {
491 shutdownRemoveGLCanvas =
false;
492 shutdownDisposeFrame =
false;
493 }
else if(args[i].equals(
"-shutdownSystemExit")) {
494 shutdownSystemExit =
true;
495 }
else if(args[i].equals(
"-manual")) {
499 if( 0 < rw && 0 < rh ) {
500 rwsize =
new Dimension(rw, rh);
503 System.err.println(
"resize "+rwsize);
504 System.err.println(
"frameLayout "+frameLayout);
505 System.err.println(
"resizeBy "+resizeBy);
506 System.err.println(
"forceES2 "+forceES2);
507 System.err.println(
"forceGL3 "+forceGL3);
508 System.err.println(
"swapInterval "+swapInterval);
509 System.err.println(
"exclusiveContext "+exclusiveContext);
510 System.err.println(
"useMSAA "+useMSAA);
511 System.err.println(
"useAnimator "+useAnimator);
513 System.err.println(
"shallUseOffscreenFBOLayer "+shallUseOffscreenFBOLayer);
514 System.err.println(
"shallUseOffscreenPBufferLayer "+shallUseOffscreenPBufferLayer);
517 final BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
518 System.err.println(
"Press enter to continue");
520 System.err.println(stdin.readLine());
521 }
catch (
final IOException e) { }
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
AWT: printable: PRESSED (t0), TYPED (t0), RELEASED (t1) non-printable: PRESSED (t0),...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
Specifies a set of OpenGL capabilities.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
void setStencilBits(final int stencilBits)
Sets the number of bits requested for the stencil buffer.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
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 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.
A heavyweight AWT component which provides OpenGL rendering support.
final float[] getRequestedSurfaceScale(final float[] result)
Returns the requested pixel scale of the associated NativeSurface.If canSetSurfaceScale() returns fal...
final Thread getExclusiveContextThread()
final boolean setSurfaceScale(final float[] pixelScale)
Request a pixel scale in x- and y-direction for the associated NativeSurface, where size_in_pixel_uni...
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
final float[] getCurrentSurfaceScale(final float[] result)
Returns the current pixel scale of the associated NativeSurface.
static void releaseClass()
static void main(final String args[])
void test99_PixelScale1_DefaultNorm()
void runTestGL(final GLCapabilities caps, final ResizeBy resizeBy, final FrameLayout frameLayout)
static boolean waitForRealized(final java.awt.Component comp, final boolean realized, final Runnable waitAction)
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)
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.
boolean isBackgroundOpaque()
Returns whether an opaque or translucent surface is requested, supported or chosen.
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,...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
Specifies an immutable set of OpenGL capabilities.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.