JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGearsES2GLJPanelAWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.demos.es2.awt;
30
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;
37
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;
48
49import javax.swing.JFrame;
50import javax.swing.SwingUtilities;
51
52import jogamp.newt.awt.NewtFactoryAWT;
53
54import org.junit.AfterClass;
55import org.junit.Assert;
56import org.junit.Assume;
57import org.junit.BeforeClass;
58import org.junit.Test;
59import org.junit.FixMethodOrder;
60import org.junit.runners.MethodSorters;
61
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;
77
78@FixMethodOrder(MethodSorters.NAME_ASCENDING)
79public class TestGearsES2GLJPanelAWT extends UITestCase {
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;
95 static float[] reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE };
96
97 @BeforeClass
98 public static void initClass() {
99 if(null == wsize) {
100 wsize = new Dimension(640, 480);
101 }
102 }
103
104 @AfterClass
105 public static void releaseClass() {
106 }
107
108 static void setFrameSize(final JFrame frame, final boolean frameLayout, final java.awt.Dimension new_sz) {
109 try {
110 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
111 @Override
112 public void run() {
113 frame.setSize(new_sz);
114 if( frameLayout ) {
115 frame.validate();
116 }
117 } } );
118 } catch( final Throwable throwable ) {
119 throwable.printStackTrace();
120 Assume.assumeNoException( throwable );
121 }
122 }
123
124 private void setTitle(final JFrame frame, final GLJPanel glc, final GLCapabilitiesImmutable caps) {
125 final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl";
126 final java.awt.Rectangle b = glc.getBounds();
127
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() {
133 @Override
134 public void run() {
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]+"]");
140 } } );
141 }
142
144 final GLEventListener demo;
145 if( 1 == demoType ) {
146 if( caps.isBitmap() || caps.getGLProfile().isGL2() ) {
147 final Gears gears = new Gears(swapInterval);
148 gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
149 demo = gears;
150 } else {
151 final GearsES2 gears = new GearsES2(swapInterval);
152 gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
153 demo = gears;
154 }
155 } else if( 0 == demoType ) {
156 demo = new GLClearOnInitReshape();
157 } else {
158 demo = null;
159 }
160 return demo;
161 }
162
163 protected GLJPanel newGLJPanel(final JFrame frame, final GLCapabilities caps, final FPSAnimator animator, final SnapshotGLEventListener snap)
164 throws AWTException, InterruptedException, InvocationTargetException
165 {
166 final GLJPanel glJPanel = new GLJPanel(caps);
167 Assert.assertNotNull(glJPanel);
168 glJPanel.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip);
169 glJPanel.setMinimumSize(wsize);
170 glJPanel.setPreferredSize(wsize);
171 glJPanel.setSize(wsize);
172 glJPanel.setSurfaceScale(reqSurfacePixelScale);
173 {
174 final GLEventListener demo = createDemo(caps);
175 if( null != demo ) {
176 glJPanel.addGLEventListener(demo);
177 }
178 }
179 if( null != snap ) {
180 glJPanel.addGLEventListener(snap);
181 }
182 glJPanel.addGLEventListener(new GLEventListener() {
183 @Override
184 public void init(final GLAutoDrawable drawable) { }
185 @Override
186 public void dispose(final GLAutoDrawable drawable) { }
187 @Override
188 public void display(final GLAutoDrawable drawable) { }
189 @Override
190 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
191 setTitle(frame, glJPanel, caps);
192 }
193
194 });
195 setTitle(frame, glJPanel, caps);
196
197 frame.addComponentListener(new ComponentListener() {
198 @Override
199 public void componentResized(final ComponentEvent e) {
200 setTitle(frame, glJPanel, caps);
201 }
202
203 @Override
204 public void componentMoved(final ComponentEvent e) {
205 setTitle(frame, glJPanel, caps);
206 }
207
208 @Override
209 public void componentShown(final ComponentEvent e) { }
210
211 @Override
212 public void componentHidden(final ComponentEvent e) { }
213 });
214
215 if( SwingUtilities.isEventDispatchThread() ) {
216 frame.getContentPane().add(glJPanel, BorderLayout.CENTER);
217 frame.getContentPane().validate();
218 frame.pack();
219 frame.setVisible(true);
220 } else {
221 SwingUtilities.invokeAndWait(new Runnable() {
222 @Override
223 public void run() {
224 frame.getContentPane().add(glJPanel, BorderLayout.CENTER);
225 frame.getContentPane().validate();
226 frame.pack();
227 frame.setVisible(true);
228 } } ) ;
229 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true, null));
230 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel, true, null));
231
232 final float[] minSurfacePixelScale = glJPanel.getMinimumSurfaceScale(new float[2]);
233 final float[] maxSurfacePixelScale = glJPanel.getMaximumSurfaceScale(new float[2]);
234 final float[] valReqSurfacePixelScale = glJPanel.getRequestedSurfaceScale(new float[2]);
235 final float[] hasSurfacePixelScale = glJPanel.getCurrentSurfaceScale(new float[2]);
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);
243 }
244
245 if( null != animator ) {
246 animator.add(glJPanel);
247 animator.setUpdateFPSFrames(60, System.err);
248 }
249 return glJPanel;
250 }
251
252 protected void destroy(final JFrame frame, final GLJPanel glJPanel) {
253 try {
254 if( SwingUtilities.isEventDispatchThread() ) {
255 if( null != frame ) {
256 frame.setVisible(false);
257 if( null != glJPanel ) {
258 frame.getContentPane().remove(glJPanel);
259 }
260 frame.remove(glJPanel);
261 }
262 if( null != glJPanel ) {
263 glJPanel.destroy();
264 }
265 if( null != frame ) {
266 frame.dispose();
267 }
268 } else {
269 SwingUtilities.invokeAndWait(new Runnable() {
270 @Override
271 public void run() {
272 if( null != frame ) {
273 frame.setVisible(false);
274 if( null != glJPanel ) {
275 frame.getContentPane().remove(glJPanel);
276 }
277 frame.remove(glJPanel);
278 }
279 if( null != glJPanel ) {
280 glJPanel.destroy();
281 }
282 if( null != frame ) {
283 frame.dispose();
284 }
285 } } );
286 }
287 } catch (final Exception e) {
288 e.printStackTrace();
289 }
290 }
291
292 protected void runTestGL(final GLCapabilities caps)
293 throws AWTException, InterruptedException, InvocationTargetException
294 {
295 final JFrame frame = new JFrame("Swing GLJPanel");
296 frame.setLocation(xpos, ypos);
297 Assert.assertNotNull(frame);
298
299 final FPSAnimator animator = useAnimator ? new FPSAnimator(60) : null;
301 final GLJPanel glJPanel = newGLJPanel(frame, caps, animator, snap);
302 if( null != animator ) {
303 animator.start();
304 Assert.assertEquals(true, animator.isAnimating());
305 }
306 final Screen screen = NewtFactoryAWT.createScreen(glJPanel, true);
307 screen.addReference(); // initial native creation - keep alive!
308 System.err.println("GetPixelScale: AWT -> Screen: "+screen);
309
310 final QuitAdapter quitAdapter = new QuitAdapter();
311 new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glJPanel).addTo(glJPanel);
312 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glJPanel).addTo(frame);
313
314 final JFrame[] frame2 = { null };
315 final GLJPanel[] glJPanel2 = { null };
316
317 final com.jogamp.newt.event.KeyListener kl = new com.jogamp.newt.event.KeyAdapter() {
318 @Override
319 public void keyPressed(final KeyEvent e) {
320 if( e.isAutoRepeat() ) {
321 return;
322 }
323 if( e.getKeySymbol() == KeyEvent.VK_P ) {
324 System.err.println();
325 {
326 // Just for manual validation!
327 final java.awt.Point los = glJPanel.getLocationOnScreen();
328 final RectangleImmutable r = new Rectangle(los.x, los.y, glJPanel.getWidth(), glJPanel.getHeight());
329 System.err.printf("GetPixelScale: Panel Bounds: %s window-units%n", r.toString());
330 System.err.printf("GetPixelScale: Panel Resolution: %d x %d pixel-units%n", glJPanel.getSurfaceWidth(), glJPanel.getSurfaceHeight());
331 }
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;
336 if( e.isShiftDown() ) {
337 // SHIFT: query current mode!
338 pixelPerMM = monitor.getPixelsPerMM(monitor.queryCurrentMode(), new float[2]);
339 cached = false;
340 } else {
341 // Default: Use cached mode!
342 pixelPerMM = monitor.getPixelsPerMM(new float[2]);
343 cached = true;
344 }
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();
348 } else if(e.getKeyChar()=='x') {
349 final float[] hadSurfacePixelScale = glJPanel.getCurrentSurfaceScale(new float[2]);
350 final float[] reqSurfacePixelScale;
351 if( hadSurfacePixelScale[0] == ScalableSurface.IDENTITY_PIXELSCALE ) {
352 reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE };
353 } else {
354 reqSurfacePixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
355 }
356 System.err.println("[set PixelScale pre]: had "+hadSurfacePixelScale[0]+"x"+hadSurfacePixelScale[1]+" -> req "+reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]);
357 glJPanel.setSurfaceScale(reqSurfacePixelScale);
358 final float[] valReqSurfacePixelScale = glJPanel.getRequestedSurfaceScale(new float[2]);
359 final float[] hasSurfacePixelScale1 = glJPanel.getCurrentSurfaceScale(new float[2]);
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);
365 } else if(e.getKeyChar()=='m') {
366 final GLCapabilitiesImmutable capsPre = glJPanel.getChosenGLCapabilities();
367 final GLCapabilities capsNew = new GLCapabilities(capsPre.getGLProfile());
368 capsNew.copyFrom(capsPre);
369 final boolean msaa;
370 if( capsPre.getSampleBuffers() ) {
371 capsNew.setSampleBuffers(false);
372 msaa = false;
373 } else {
374 capsNew.setSampleBuffers(true);
375 capsNew.setNumSamples(4);
376 msaa = true;
377 }
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());
381 glJPanel.setRequestedGLCapabilities(capsNew);
382 System.err.println("XXX-A2: "+animator.toString());
383 System.err.println("XXX: "+glJPanel.toString());
384 } else if(e.getKeyChar()=='n') {
385 System.err.println("XXX: frame2: "+frame2[0]);
386 if( null != frame2[0] ) {
387 System.err.println("XXX: frame2.isShowing: "+frame2[0].isShowing());
388 }
389 System.err.println("XXX: glJPanel2: "+glJPanel2[0]);
390 if( null != frame2[0] && frame2[0].isShowing() ) {
391 destroy(frame2[0], glJPanel2[0]);
392 frame2[0] = null;
393 glJPanel2[0] = null;
394 } else {
395 frame2[0] = new JFrame("GLJPanel2");
396 frame2[0].setLocation(frame.getX()+frame.getWidth()+64, frame.getY());
397 final FPSAnimator animator2 = useAnimator ? new FPSAnimator(60) : null;
398 if( null != animator2 ) {
399 animator2.start();
400 }
402 try {
403 glJPanel2[0] = newGLJPanel(frame2[0], caps, animator2, snap2);
404 } catch (final Exception e2) {
405 e2.printStackTrace();
406 destroy(frame2[0], glJPanel2[0]);
407 frame2[0] = null;
408 glJPanel2[0] = null;
409 }
410 }
411 }
412 } };
413 new AWTKeyAdapter(kl, glJPanel).addTo(glJPanel);
414
415 snap.setMakeSnapshot();
416
417 if( null != rwsize ) {
418 Thread.sleep(500); // 500ms delay
419 setFrameSize(frame, true, rwsize);
420 System.err.println("window resize pos/siz: "+glJPanel.getX()+"/"+glJPanel.getY()+" "+glJPanel.getSurfaceWidth()+"x"+glJPanel.getSurfaceHeight());
421 }
422
423 snap.setMakeSnapshot();
424
425 final long t0 = System.currentTimeMillis();
426 long t1 = t0;
427 boolean triggerSnap = false;
428 while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
429 Thread.sleep(100);
430 t1 = System.currentTimeMillis();
431 snap.getDisplayCount();
432 if( !triggerSnap && snap.getDisplayCount() > 1 ) {
433 // Snapshot only after one frame has been rendered to suite FBO MSAA!
434 snap.setMakeSnapshot();
435 triggerSnap = true;
436 }
437 }
438
439 Assert.assertNotNull(frame);
440 Assert.assertNotNull(glJPanel);
441
442 if( useAnimator ) {
443 Assert.assertNotNull(animator);
444 animator.stop();
445 Assert.assertEquals(false, animator.isAnimating());
446 } else {
447 Assert.assertNull(animator);
448 }
449
450 screen.removeReference(); // final native destroy
451 destroy(frame, glJPanel);
452 if( null != frame2[0] ) {
453 destroy(frame2[0], glJPanel2[0]);
454 }
455 }
456
457 @Test
458 public void test01_DefaultNorm()
459 throws AWTException, InterruptedException, InvocationTargetException
460 {
461 final GLProfile glp;
462 if(forceGL3) {
463 glp = GLProfile.get(GLProfile.GL3);
464 } else if(forceES3) {
466 } else if(forceES2) {
468 } else if(forceGLFFP) {
469 glp = GLProfile.getMaxFixedFunc(true);
470 } else {
471 glp = GLProfile.getDefault();
472 }
473 final GLCapabilities caps = new GLCapabilities( glp );
474 if(useMSAA) {
475 caps.setNumSamples(msaaNumSamples);
476 caps.setSampleBuffers(true);
477 }
478 if(shallUsePBuffer) {
479 caps.setPBuffer(true);
480 }
481 if(shallUseBitmap) {
482 caps.setBitmap(true);
483 }
484 runTestGL(caps);
485 }
486
487 @Test
488 public void test02_DefaultMsaa()
489 throws AWTException, InterruptedException, InvocationTargetException
490 {
491 if( manualTest ) {
492 return;
493 }
495 caps.setNumSamples(4);
496 caps.setSampleBuffers(true);
497 runTestGL(caps);
498 }
499
500 @Test
501 public void test03_PbufferNorm()
502 throws AWTException, InterruptedException, InvocationTargetException
503 {
504 if( manualTest ) {
505 return;
506 }
508 caps.setPBuffer(true);
509 runTestGL(caps);
510 }
511
512 @Test
513 public void test04_PbufferMsaa()
514 throws AWTException, InterruptedException, InvocationTargetException
515 {
516 if( manualTest ) {
517 return;
518 }
520 caps.setNumSamples(4);
521 caps.setSampleBuffers(true);
522 caps.setPBuffer(true);
523 runTestGL(caps);
524 }
525
526 @Test
527 public void test05_BitmapNorm()
528 throws AWTException, InterruptedException, InvocationTargetException
529 {
530 if( manualTest ) {
531 return;
532 }
534 caps.setBitmap(true);
535 runTestGL(caps);
536 }
537
538 @Test
539 public void test06_BitmapMsaa()
540 throws AWTException, InterruptedException, InvocationTargetException
541 {
542 if( manualTest ) {
543 return;
544 }
546 caps.setNumSamples(4);
547 caps.setSampleBuffers(true);
548 caps.setBitmap(true);
549 runTestGL(caps);
550 }
551
552 @Test
553 public void test20_GLES2()
554 throws AWTException, InterruptedException, InvocationTargetException
555 {
556 if( manualTest ) {
557 return;
558 }
559
561 System.err.println("GLES2 n/a");
562 return;
563 }
565 final GLCapabilities caps = new GLCapabilities( glp );
566 runTestGL(caps);
567 }
568
569 @Test
570 public void test30_GLES3()
571 throws AWTException, InterruptedException, InvocationTargetException
572 {
573 if( manualTest ) {
574 return;
575 }
576
578 System.err.println("GLES3 n/a");
579 return;
580 }
582 final GLCapabilities caps = new GLCapabilities( glp );
583 runTestGL(caps);
584 }
585
586 @Test
587 public void test40_GL3()
588 throws AWTException, InterruptedException, InvocationTargetException
589 {
590 if( manualTest ) {
591 return;
592 }
593
595 System.err.println("GL3 n/a");
596 return;
597 }
598 final GLProfile glp = GLProfile.get(GLProfile.GL3);
599 final GLCapabilities caps = new GLCapabilities( glp );
600 runTestGL(caps);
601 }
602
603 @Test
605 throws AWTException, InterruptedException, InvocationTargetException
606 {
607 if( manualTest ) {
608 return;
609 }
610 reqSurfacePixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
611 reqSurfacePixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
612
614 runTestGL(caps);
615 }
616
617 static long duration = 500; // ms
618
619 public static void main(final String args[]) {
620 int w=640, h=480, rw=-1, rh=-1;
621
622 for(int i=0; i<args.length; i++) {
623 if(args[i].equals("-time")) {
624 i++;
625 duration = MiscUtils.atol(args[i], duration);
626 } else if(args[i].equals("-es2")) {
627 forceES2 = true;
628 } else if(args[i].equals("-es3")) {
629 forceES3 = true;
630 } else if(args[i].equals("-gl3")) {
631 forceGL3 = true;
632 } else if(args[i].equals("-glFFP")) {
633 forceGLFFP = true;
634 } else if(args[i].equals("-width")) {
635 i++;
636 w = MiscUtils.atoi(args[i], w);
637 } else if(args[i].equals("-height")) {
638 i++;
639 h = MiscUtils.atoi(args[i], h);
640 } else if(args[i].equals("-x")) {
641 i++;
642 xpos = MiscUtils.atoi(args[i], xpos);
643 } else if(args[i].equals("-y")) {
644 i++;
645 ypos = MiscUtils.atoi(args[i], ypos);
646 } else if(args[i].equals("-rwidth")) {
647 i++;
648 rw = MiscUtils.atoi(args[i], rw);
649 } else if(args[i].equals("-rheight")) {
650 i++;
651 rh = MiscUtils.atoi(args[i], rh);
652 } else if(args[i].equals("-pixelScale")) {
653 i++;
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")) {
660 i++;
661 swapInterval = MiscUtils.atoi(args[i], swapInterval);
662 } else if(args[i].equals("-msaa")) {
663 i++;
664 useMSAA = true;
665 msaaNumSamples = MiscUtils.atoi(args[i], msaaNumSamples);
666 } else if(args[i].equals("-noanim")) {
667 useAnimator = false;
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")) {
673 manualTest = true;
674 } else if(args[i].equals("-demo")) {
675 i++;
676 demoType = MiscUtils.atoi(args[i], 0);
677 }
678 }
679 wsize = new Dimension(w, h);
680 if( 0 < rw && 0 < rh ) {
681 rwsize = new Dimension(rw, rh);
682 }
683
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);
697
698 org.junit.runner.JUnitCore.main(TestGearsES2GLJPanelAWT.class.getName());
699 }
700}
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.
Definition: Screen.java:58
abstract int addReference()
See Display#addReference().
abstract int removeReference()
See Display#removeReference().
final boolean isShiftDown()
getModifiers() contains SHIFT_MASK.
final boolean isAutoRepeat()
getModifiers() contains AUTOREPEAT_MASK.
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
Definition: KeyEvent.java:161
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
Definition: KeyEvent.java:176
static final short VK_P
See VK_A.
Definition: KeyEvent.java:625
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.
Definition: GLProfile.java:77
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
Definition: GLProfile.java:305
static final String GLES3
The embedded OpenGL profile ES 3.x, with x >= 0.
Definition: GLProfile.java:588
static GLProfile getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
Definition: GLProfile.java:808
static final String GL3
The desktop OpenGL core profile 3.x, with x >= 1.
Definition: GLProfile.java:576
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
Definition: GLProfile.java:585
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
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.
Definition: GLJPanel.java:189
final float[] getCurrentSurfaceScale(final float[] result)
Returns the current pixel scale of the associated NativeSurface.
Definition: GLJPanel.java:653
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
Definition: GLJPanel.java:1275
void destroy()
Just an alias for removeNotify.
Definition: GLJPanel.java:531
float[] getMinimumSurfaceScale(final float[] result)
Returns the minimum pixel scale of the associated NativeSurface.the passed storage containing the min...
Definition: GLJPanel.java:665
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
Definition: GLJPanel.java:1217
final void setSkipGLOrientationVerticalFlip(final boolean v)
Skip isGLOriented() based vertical flip, which usually is required by the offscreen backend,...
Definition: GLJPanel.java:1255
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Definition: GLJPanel.java:1222
final void setRequestedGLCapabilities(final GLCapabilitiesImmutable caps)
Set a new requested GLCapabilitiesImmutable for this GLJPanel allowing reconfiguration.
Definition: GLJPanel.java:1300
float[] getMaximumSurfaceScale(final float[] result)
Returns the maximum pixel scale of the associated NativeSurface.The maximum pixel scale maybe used to...
Definition: GLJPanel.java:678
final boolean setSurfaceScale(final float[] pixelScale)
Request a pixel scale in x- and y-direction for the associated NativeSurface, where size_in_pixel_uni...
Definition: GLJPanel.java:619
final float[] getRequestedSurfaceScale(final float[] result)
Returns the requested pixel scale of the associated NativeSurface.If canSetSurfaceScale() returns fal...
Definition: GLJPanel.java:646
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLJPanel.java:989
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)
Definition: Gears.java:34
void setFlipVerticalInGLOrientation(final boolean v)
Definition: Gears.java:84
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)
Definition: MiscUtils.java:75
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
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.
Listener for KeyEvents.
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.