29package com.jogamp.opengl.test.junit.jogl.demos.es2.awt;
31import java.awt.AWTException;
32import java.awt.BorderLayout;
33import java.awt.Dimension;
34import java.awt.event.ComponentEvent;
35import java.awt.event.ComponentListener;
36import java.lang.reflect.InvocationTargetException;
38import com.jogamp.common.util.awt.AWTEDTExecutor;
39import com.jogamp.nativewindow.ScalableSurface;
40import com.jogamp.nativewindow.util.Rectangle;
41import com.jogamp.nativewindow.util.RectangleImmutable;
42import com.jogamp.opengl.GLAutoDrawable;
43import com.jogamp.opengl.GLCapabilities;
44import com.jogamp.opengl.GLCapabilitiesImmutable;
45import com.jogamp.opengl.GLEventListener;
46import com.jogamp.opengl.GLProfile;
47import com.jogamp.opengl.awt.GLJPanel;
49import javax.swing.JFrame;
50import javax.swing.SwingUtilities;
52import jogamp.newt.awt.NewtFactoryAWT;
54import org.junit.AfterClass;
55import org.junit.Assert;
56import org.junit.Assume;
57import org.junit.BeforeClass;
59import org.junit.FixMethodOrder;
60import org.junit.runners.MethodSorters;
62import com.jogamp.newt.MonitorDevice;
63import com.jogamp.newt.Screen;
64import com.jogamp.newt.event.KeyEvent;
65import com.jogamp.newt.event.TraceKeyAdapter;
66import com.jogamp.newt.event.TraceWindowAdapter;
67import com.jogamp.newt.event.awt.AWTKeyAdapter;
68import com.jogamp.newt.event.awt.AWTWindowAdapter;
69import com.jogamp.opengl.test.junit.jogl.demos.GLClearOnInitReshape;
70import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
71import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
72import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
73import com.jogamp.opengl.test.junit.util.MiscUtils;
74import com.jogamp.opengl.test.junit.util.QuitAdapter;
75import com.jogamp.opengl.test.junit.util.UITestCase;
76import com.jogamp.opengl.util.FPSAnimator;
78@FixMethodOrder(MethodSorters.NAME_ASCENDING)
80 static Dimension wsize, rwsize=
null;
81 static boolean forceES2 =
false;
82 static boolean forceES3 =
false;
83 static boolean forceGL3 =
false;
84 static boolean forceGLFFP =
false;
85 static int demoType = 1;
86 static boolean shallUsePBuffer =
false;
87 static boolean shallUseBitmap =
false;
88 static boolean useMSAA =
false;
89 static int msaaNumSamples = 4;
90 static int swapInterval = 0;
91 static boolean useAnimator =
true;
92 static boolean manualTest =
false;
93 static boolean skipGLOrientationVerticalFlip =
false;
94 static int xpos = 10, ypos = 10;
100 wsize =
new Dimension(640, 480);
108 static void setFrameSize(
final JFrame frame,
final boolean frameLayout,
final java.awt.Dimension new_sz) {
110 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
113 frame.setSize(new_sz);
118 }
catch(
final Throwable throwable ) {
119 throwable.printStackTrace();
120 Assume.assumeNoException( throwable );
126 final java.awt.Rectangle b = glc.getBounds();
128 final float[] minSurfacePixelScale = glc.getMinimumSurfaceScale(
new float[2]);
129 final float[] maxSurfacePixelScale = glc.getMaximumSurfaceScale(
new float[2]);
130 final float[] reqSurfacePixelScale = glc.getRequestedSurfaceScale(
new float[2]);
131 final float[] hasSurfacePixelScale = glc.getCurrentSurfaceScale(
new float[2]);
132 AWTEDTExecutor.singleton.invoke(
false,
new Runnable() {
135 frame.setTitle(
"GLJPanel["+capsA+
"], swapI "+swapInterval+
", win: ["+b.x+
"/"+b.y+
" "+b.width+
"x"+b.height+
"], pix: "+glc.getSurfaceWidth()+
"x"+glc.getSurfaceHeight()+
136 ", scale[min "+minSurfacePixelScale[0]+
"x"+minSurfacePixelScale[1]+
", max "+
137 maxSurfacePixelScale[0]+
"x"+maxSurfacePixelScale[1]+
", req "+
138 reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" -> has "+
139 hasSurfacePixelScale[0]+
"x"+hasSurfacePixelScale[1]+
"]");
145 if( 1 == demoType ) {
155 }
else if( 0 == demoType ) {
164 throws AWTException, InterruptedException, InvocationTargetException
167 Assert.assertNotNull(glJPanel);
169 glJPanel.setMinimumSize(wsize);
170 glJPanel.setPreferredSize(wsize);
190 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {
191 setTitle(frame, glJPanel, caps);
195 setTitle(frame, glJPanel, caps);
197 frame.addComponentListener(
new ComponentListener() {
199 public void componentResized(
final ComponentEvent e) {
200 setTitle(frame, glJPanel, caps);
204 public void componentMoved(
final ComponentEvent e) {
205 setTitle(frame, glJPanel, caps);
209 public void componentShown(
final ComponentEvent e) { }
212 public void componentHidden(
final ComponentEvent e) { }
215 if( SwingUtilities.isEventDispatchThread() ) {
216 frame.getContentPane().add(glJPanel, BorderLayout.CENTER);
217 frame.getContentPane().validate();
219 frame.setVisible(
true);
221 SwingUtilities.invokeAndWait(
new Runnable() {
224 frame.getContentPane().add(glJPanel, BorderLayout.CENTER);
225 frame.getContentPane().validate();
227 frame.setVisible(
true);
236 System.err.println(
"HiDPI PixelScale: min "+
237 minSurfacePixelScale[0]+
"x"+minSurfacePixelScale[1]+
", max "+
238 maxSurfacePixelScale[0]+
"x"+maxSurfacePixelScale[1]+
", req "+
239 reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" -> val "+
240 valReqSurfacePixelScale[0]+
"x"+valReqSurfacePixelScale[1]+
" -> has "+
241 hasSurfacePixelScale[0]+
"x"+hasSurfacePixelScale[1]);
242 setTitle(frame, glJPanel, caps);
245 if(
null != animator ) {
246 animator.add(glJPanel);
247 animator.setUpdateFPSFrames(60, System.err);
254 if( SwingUtilities.isEventDispatchThread() ) {
255 if(
null != frame ) {
256 frame.setVisible(
false);
257 if(
null != glJPanel ) {
258 frame.getContentPane().remove(glJPanel);
260 frame.remove(glJPanel);
262 if(
null != glJPanel ) {
265 if(
null != frame ) {
269 SwingUtilities.invokeAndWait(
new Runnable() {
272 if(
null != frame ) {
273 frame.setVisible(
false);
274 if(
null != glJPanel ) {
275 frame.getContentPane().remove(glJPanel);
277 frame.remove(glJPanel);
279 if(
null != glJPanel ) {
282 if(
null != frame ) {
287 }
catch (
final Exception e) {
293 throws AWTException, InterruptedException, InvocationTargetException
295 final JFrame frame =
new JFrame(
"Swing GLJPanel");
296 frame.setLocation(xpos, ypos);
297 Assert.assertNotNull(frame);
301 final GLJPanel glJPanel = newGLJPanel(frame, caps, animator, snap);
302 if(
null != animator ) {
304 Assert.assertEquals(
true, animator.isAnimating());
306 final Screen screen = NewtFactoryAWT.createScreen(glJPanel,
true);
308 System.err.println(
"GetPixelScale: AWT -> Screen: "+screen);
314 final JFrame[] frame2 = {
null };
315 final GLJPanel[] glJPanel2 = {
null };
319 public void keyPressed(
final KeyEvent e) {
324 System.err.println();
327 final java.awt.Point los = glJPanel.getLocationOnScreen();
329 System.err.printf(
"GetPixelScale: Panel Bounds: %s window-units%n", r.toString());
332 final MonitorDevice monitor = NewtFactoryAWT.getMonitorDevice(screen, glJPanel);
333 System.err.printf(
"GetPixelScale: %s%n", monitor.
toString());
334 final float[] pixelPerMM;
335 final boolean cached;
345 System.err.println(
" pixel/mm ["+pixelPerMM[0]+
", "+pixelPerMM[1]+
"], cached-mode "+cached);
346 System.err.println(
" pixel/in ["+pixelPerMM[0]*25.4f+
", "+pixelPerMM[1]*25.4f+
"], cached-mode "+cached);
347 System.err.println();
350 final float[] reqSurfacePixelScale;
356 System.err.println(
"[set PixelScale pre]: had "+hadSurfacePixelScale[0]+
"x"+hadSurfacePixelScale[1]+
" -> req "+reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]);
360 System.err.println(
"[set PixelScale post]: "+hadSurfacePixelScale[0]+
"x"+hadSurfacePixelScale[1]+
" (had) -> "+
361 reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" (req) -> "+
362 valReqSurfacePixelScale[0]+
"x"+valReqSurfacePixelScale[1]+
" (val) -> "+
363 hasSurfacePixelScale1[0]+
"x"+hasSurfacePixelScale1[1]+
" (has)");
364 setTitle(frame, glJPanel, caps);
378 System.err.println(
"[set MSAA "+msaa+
" Caps had]: "+capsPre);
379 System.err.println(
"[set MSAA "+msaa+
" Caps new]: "+capsNew);
380 System.err.println(
"XXX-A1: "+animator.
toString());
382 System.err.println(
"XXX-A2: "+animator.
toString());
383 System.err.println(
"XXX: "+glJPanel.
toString());
385 System.err.println(
"XXX: frame2: "+frame2[0]);
386 if(
null != frame2[0] ) {
387 System.err.println(
"XXX: frame2.isShowing: "+frame2[0].isShowing());
389 System.err.println(
"XXX: glJPanel2: "+glJPanel2[0]);
390 if(
null != frame2[0] && frame2[0].isShowing() ) {
391 destroy(frame2[0], glJPanel2[0]);
395 frame2[0] =
new JFrame(
"GLJPanel2");
396 frame2[0].setLocation(frame.getX()+frame.getWidth()+64, frame.getY());
398 if(
null != animator2 ) {
403 glJPanel2[0] = newGLJPanel(frame2[0], caps, animator2, snap2);
404 }
catch (
final Exception e2) {
405 e2.printStackTrace();
406 destroy(frame2[0], glJPanel2[0]);
417 if(
null != rwsize ) {
419 setFrameSize(frame,
true, rwsize);
425 final long t0 = System.currentTimeMillis();
427 boolean triggerSnap =
false;
428 while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
430 t1 = System.currentTimeMillis();
439 Assert.assertNotNull(frame);
440 Assert.assertNotNull(glJPanel);
443 Assert.assertNotNull(animator);
445 Assert.assertEquals(
false, animator.isAnimating());
447 Assert.assertNull(animator);
451 destroy(frame, glJPanel);
452 if(
null != frame2[0] ) {
453 destroy(frame2[0], glJPanel2[0]);
459 throws AWTException, InterruptedException, InvocationTargetException
464 }
else if(forceES3) {
466 }
else if(forceES2) {
468 }
else if(forceGLFFP) {
478 if(shallUsePBuffer) {
489 throws AWTException, InterruptedException, InvocationTargetException
502 throws AWTException, InterruptedException, InvocationTargetException
514 throws AWTException, InterruptedException, InvocationTargetException
528 throws AWTException, InterruptedException, InvocationTargetException
540 throws AWTException, InterruptedException, InvocationTargetException
554 throws AWTException, InterruptedException, InvocationTargetException
561 System.err.println(
"GLES2 n/a");
571 throws AWTException, InterruptedException, InvocationTargetException
578 System.err.println(
"GLES3 n/a");
588 throws AWTException, InterruptedException, InvocationTargetException
595 System.err.println(
"GL3 n/a");
605 throws AWTException, InterruptedException, InvocationTargetException
617 static long duration = 500;
619 public static void main(
final String args[]) {
620 int w=640, h=480, rw=-1, rh=-1;
622 for(
int i=0; i<args.length; i++) {
623 if(args[i].equals(
"-time")) {
626 }
else if(args[i].equals(
"-es2")) {
628 }
else if(args[i].equals(
"-es3")) {
630 }
else if(args[i].equals(
"-gl3")) {
632 }
else if(args[i].equals(
"-glFFP")) {
634 }
else if(args[i].equals(
"-width")) {
637 }
else if(args[i].equals(
"-height")) {
640 }
else if(args[i].equals(
"-x")) {
643 }
else if(args[i].equals(
"-y")) {
646 }
else if(args[i].equals(
"-rwidth")) {
649 }
else if(args[i].equals(
"-rheight")) {
652 }
else if(args[i].equals(
"-pixelScale")) {
654 final float pS =
MiscUtils.
atof(args[i], reqSurfacePixelScale[0]);
655 reqSurfacePixelScale[0] = pS;
656 reqSurfacePixelScale[1] = pS;
657 }
else if(args[i].equals(
"-userVFlip")) {
658 skipGLOrientationVerticalFlip =
true;
659 }
else if(args[i].equals(
"-vsync")) {
662 }
else if(args[i].equals(
"-msaa")) {
666 }
else if(args[i].equals(
"-noanim")) {
668 }
else if(args[i].equals(
"-pbuffer")) {
669 shallUsePBuffer =
true;
670 }
else if(args[i].equals(
"-bitmap")) {
671 shallUseBitmap =
true;
672 }
else if(args[i].equals(
"-manual")) {
674 }
else if(args[i].equals(
"-demo")) {
679 wsize =
new Dimension(w, h);
680 if( 0 < rw && 0 < rh ) {
681 rwsize =
new Dimension(rw, rh);
684 System.err.println(
"size "+wsize);
685 System.err.println(
"resize "+rwsize);
686 System.err.println(
"userVFlip "+skipGLOrientationVerticalFlip);
687 System.err.println(
"swapInterval "+swapInterval);
688 System.err.println(
"forceES2 "+forceES2);
689 System.err.println(
"forceGL3 "+forceGL3);
690 System.err.println(
"forceGLFFP "+forceGLFFP);
691 System.err.println(
"useMSAA "+useMSAA+
", msaaNumSamples "+msaaNumSamples);
692 System.err.println(
"useAnimator "+useAnimator);
693 System.err.println(
"shallUsePBuffer "+shallUsePBuffer);
694 System.err.println(
"shallUseBitmap "+shallUseBitmap);
695 System.err.println(
"manualTest "+manualTest);
696 System.err.println(
"demoType "+demoType);
void setBitmap(final boolean enable)
Requesting offscreen bitmap mode.
boolean isBitmap()
Returns whether bitmap offscreen mode is requested, available or chosen.
Visual output device, i.e.
abstract MonitorMode queryCurrentMode()
Returns the current MonitorMode resulting from a native query.
final float[] getPixelsPerMM(final float[] ppmmStore)
Returns the pixels per millimeter value according to the current mode's surface resolution.
A screen may span multiple MonitorDevices representing their combined virtual size.
abstract int addReference()
See Display#addReference().
abstract int removeReference()
See Display#removeReference().
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
static final short VK_P
See VK_A.
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 setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
GLCapabilities copyFrom(final CapabilitiesImmutable source)
Copies all CapabilitiesImmutable values from source into this instance.
final GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
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 GLES3
The embedded OpenGL profile ES 3.x, with x >= 0.
static GLProfile getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
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 getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
final boolean isGL2()
Indicates whether this profile is capable of GL2 .
A lightweight Swing component which provides OpenGL rendering support.
final float[] getCurrentSurfaceScale(final float[] result)
Returns the current pixel scale of the associated NativeSurface.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
void destroy()
Just an alias for removeNotify.
float[] getMinimumSurfaceScale(final float[] result)
Returns the minimum pixel scale of the associated NativeSurface.the passed storage containing the min...
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
final void setSkipGLOrientationVerticalFlip(final boolean v)
Skip isGLOriented() based vertical flip, which usually is required by the offscreen backend,...
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void setRequestedGLCapabilities(final GLCapabilitiesImmutable caps)
Set a new requested GLCapabilitiesImmutable for this GLJPanel allowing reconfiguration.
float[] getMaximumSurfaceScale(final float[] result)
Returns the maximum pixel scale of the associated NativeSurface.The maximum pixel scale maybe used to...
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 float[] getRequestedSurfaceScale(final float[] result)
Returns the requested pixel scale of the associated NativeSurface.If canSetSurfaceScale() returns fal...
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void setFlipVerticalInGLOrientation(final boolean v)
void runTestGL(final GLCapabilities caps)
void test04_PbufferMsaa()
void test01_DefaultNorm()
static void releaseClass()
GLEventListener createDemo(final GLCapabilities caps)
void test02_DefaultMsaa()
void test99_PixelScale1_DefaultNorm()
void test03_PbufferNorm()
static void main(final String args[])
void destroy(final JFrame frame, final GLJPanel glJPanel)
GLJPanel newGLJPanel(final JFrame frame, final GLCapabilities caps, final FPSAnimator animator, final SnapshotGLEventListener snap)
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
void setFlipVerticalInGLOrientation(final boolean v)
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)
An Animator subclass which attempts to achieve a target frames-per-second rate to avoid using all CPU...
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this FPSAnimator.
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,...
Immutable Rectangle interface, with its position on the top-left.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
Specifies an immutable set of OpenGL capabilities.
boolean getSampleBuffers()
Returns whether sample buffers for full-scene antialiasing (FSAA) should be allocated for this drawab...
GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.