Jogamp
bc6b5e26fc1a41fb0651218f58ce22ce3180a40a
[jogl.git] / src / test / com / jogamp / opengl / test / junit / jogl / demos / es2 / newt / TestGearsES2NEWT.java
1 /**
2  * Copyright 2011 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
29 package com.jogamp.opengl.test.junit.jogl.demos.es2.newt;
30
31 import java.io.IOException;
32 import java.net.URLConnection;
33
34 import com.jogamp.common.util.IOUtil;
35 import com.jogamp.newt.Display;
36 import com.jogamp.newt.Display.PointerIcon;
37 import com.jogamp.newt.NewtFactory;
38 import com.jogamp.newt.Screen;
39 import com.jogamp.newt.Window;
40 import com.jogamp.newt.event.KeyAdapter;
41 import com.jogamp.newt.event.KeyEvent;
42 import com.jogamp.newt.event.MouseAdapter;
43 import com.jogamp.newt.event.MouseEvent;
44 import com.jogamp.newt.event.WindowEvent;
45 import com.jogamp.newt.event.WindowAdapter;
46 import com.jogamp.newt.opengl.GLWindow;
47 import com.jogamp.newt.util.EDTUtil;
48 import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
49 import com.jogamp.opengl.test.junit.util.MiscUtils;
50 import com.jogamp.opengl.test.junit.util.UITestCase;
51 import com.jogamp.opengl.test.junit.util.QuitAdapter;
52 import com.jogamp.opengl.util.Animator;
53 import com.jogamp.opengl.util.PNGPixelRect;
54 import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
55
56 import javax.media.nativewindow.NativeWindowFactory;
57 import javax.media.nativewindow.util.Dimension;
58 import javax.media.nativewindow.util.Point;
59 import javax.media.nativewindow.util.PointImmutable;
60 import javax.media.nativewindow.util.DimensionImmutable;
61 import javax.media.opengl.GLAnimatorControl;
62 import javax.media.opengl.GLAutoDrawable;
63 import javax.media.opengl.GLCapabilities;
64 import javax.media.opengl.GLCapabilitiesImmutable;
65 import javax.media.opengl.GLEventListener;
66 import javax.media.opengl.GLProfile;
67
68 import jogamp.newt.DefaultEDTUtil;
69
70 import org.junit.Assert;
71 import org.junit.BeforeClass;
72 import org.junit.AfterClass;
73 import org.junit.Test;
74 import org.junit.FixMethodOrder;
75 import org.junit.runners.MethodSorters;
76
77 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
78 public class TestGearsES2NEWT extends UITestCase {
79     static int screenIdx = 0;
80     static PointImmutable wpos;
81     static DimensionImmutable wsize, rwsize=null;
82
83     static long duration = 500; // ms
84     static boolean opaque = true;
85     static int forceAlpha = -1;
86     static boolean undecorated = false;
87     static boolean alwaysOnTop = false;
88     static boolean fullscreen = false;
89     static boolean pmvUseBackingArray = true;
90     static int swapInterval = 1;
91     static boolean waitForKey = false;
92     static boolean mouseVisible = true;
93     static boolean mouseConfined = false;
94     static boolean setPointerIcon = false;
95     static boolean showFPS = false;
96     static int loops = 1;
97     static boolean loop_shutdown = false;
98     static boolean forceES2 = false;
99     static boolean forceES3 = false;
100     static boolean forceGL3 = false;
101     static boolean forceGL2 = false;
102     static boolean mainRun = false;
103     static boolean exclusiveContext = false;
104     static boolean useAnimator = true;
105     static boolean useMappedBuffers = false;
106     static enum SysExit { none, testExit, testError, testEDTError, displayExit, displayError, displayEDTError };
107     static SysExit sysExit = SysExit.none;
108
109     @BeforeClass
110     public static void initClass() {
111         if(null == wsize) {
112             wsize = new Dimension(640, 480);
113         }
114     }
115
116     @AfterClass
117     public static void releaseClass() {
118     }
119
120     private void setTitle(final Window win, final GLCapabilitiesImmutable caps) {
121         final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl";
122         win.setTitle("GLWindow["+capsA+"], swapI "+swapInterval+", win: "+win.getBounds()+", pix: "+win.getSurfaceBounds());
123     }
124     protected void runTestGL(final GLCapabilitiesImmutable caps, boolean undecorated) throws InterruptedException {
125         System.err.println("requested: vsync "+swapInterval+", "+caps);
126         Display dpy = NewtFactory.createDisplay(null);
127         Screen screen = NewtFactory.createScreen(dpy, screenIdx);
128         final GLWindow glWindow = GLWindow.create(screen, caps);
129         Assert.assertNotNull(glWindow);
130         glWindow.setSize(wsize.getWidth(), wsize.getHeight());
131         if(null != wpos) {
132             glWindow.setPosition(wpos.getX(), wpos.getY());
133         }
134         glWindow.setUndecorated(undecorated);
135         glWindow.setAlwaysOnTop(alwaysOnTop);
136         glWindow.setFullscreen(fullscreen);
137         glWindow.setPointerVisible(mouseVisible);
138         glWindow.confinePointer(mouseConfined);
139         setTitle(glWindow, caps);
140
141         final GearsES2 demo = new GearsES2(swapInterval);
142         demo.setPMVUseBackingArray(pmvUseBackingArray);
143         demo.setUseMappedBuffers(useMappedBuffers);
144         demo.setValidateBuffers(true);
145         glWindow.addGLEventListener(demo);
146
147         final SnapshotGLEventListener snap = new SnapshotGLEventListener();
148         glWindow.addGLEventListener(snap);
149         if(waitForKey) {
150             glWindow.addGLEventListener(new GLEventListener() {
151                 public void init(GLAutoDrawable drawable) { }
152                 public void dispose(GLAutoDrawable drawable) { }
153                 public void display(GLAutoDrawable drawable) {
154                     GLAnimatorControl  actrl = drawable.getAnimator();
155                     if(waitForKey && actrl.getTotalFPSFrames() == 60*3) {
156                         UITestCase.waitForKey("3s mark");
157                         actrl.resetFPSCounter();
158                         waitForKey = false;
159                     }
160                 }
161                 public void reshape(GLAutoDrawable drawable, int x, int y,
162                         int width, int height) { }
163             });
164         }
165
166         final Animator animator = useAnimator ? new Animator() : null;
167         if( useAnimator ) {
168             animator.setModeBits(false, Animator.MODE_EXPECT_AWT_RENDERING_THREAD);
169             animator.setExclusiveContext(exclusiveContext);
170         }
171
172         final QuitAdapter quitAdapter = new QuitAdapter();
173         //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
174         //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
175         glWindow.addKeyListener(quitAdapter);
176         glWindow.addWindowListener(quitAdapter);
177
178         glWindow.addWindowListener(new WindowAdapter() {
179             public void windowResized(WindowEvent e) {
180                 System.err.println("window resized: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight());
181                 setTitle(glWindow, caps);
182             }
183             public void windowMoved(WindowEvent e) {
184                 System.err.println("window moved:   "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight());
185                 setTitle(glWindow, caps);
186             }
187         });
188
189         final PointerIcon[] pointerIcons = { null, null, null };
190         {
191             final Display disp = glWindow.getScreen().getDisplay();
192             disp.createNative();
193             {
194                 PointerIcon _pointerIcon = null;
195                 final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/cross-grey-alpha-16x16.png" } );
196                 try {
197                     _pointerIcon = disp.createPointerIcon(res, 8, 8);
198                     System.err.println("Create PointerIcon #01: "+_pointerIcon);
199                 } catch (Exception e) {
200                     e.printStackTrace();
201                 }
202                 pointerIcons[0] = _pointerIcon;
203             }
204             {
205                 PointerIcon _pointerIcon = null;
206                 final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/pointer-grey-alpha-16x24.png" } );
207                 try {
208                     _pointerIcon = disp.createPointerIcon(res, 0, 0);
209                     System.err.println("Create PointerIcon #02: "+_pointerIcon);
210                 } catch (Exception e) {
211                     e.printStackTrace();
212                 }
213                 pointerIcons[1] = _pointerIcon;
214             }
215             {
216                 PointerIcon _pointerIcon = null;
217                 final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "jogamp-pointer-64x64.png" } );
218                 try {
219                     final URLConnection urlConn = res.resolve(0);
220                     final PNGPixelRect image = PNGPixelRect.read(urlConn.getInputStream(), null, false /* directBuffer */, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */);
221                     System.err.println("Create PointerIcon #03: "+image);
222                     _pointerIcon = disp.createPointerIcon(image, 32, 0);
223                     System.err.println("Create PointerIcon #03: "+_pointerIcon);
224                 } catch (Exception e) {
225                     e.printStackTrace();
226                 }
227                 pointerIcons[2] = _pointerIcon;
228             }
229         }
230         if( setPointerIcon ) {
231             glWindow.setPointerIcon(pointerIcons[0]);
232             System.err.println("Set PointerIcon: "+glWindow.getPointerIcon());
233         }
234
235         glWindow.addKeyListener(new KeyAdapter() {
236             int pointerIconIdx = 0;
237
238             @Override
239             public void keyPressed(final KeyEvent e) {
240                 if( e.isAutoRepeat() ) {
241                     return;
242                 }
243                 if(e.getKeyChar()=='f') {
244                     new Thread() {
245                         public void run() {
246                             final Thread t = glWindow.setExclusiveContextThread(null);
247                             System.err.println("[set fullscreen  pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
248                             if( glWindow.isFullscreen() ) {
249                                 glWindow.setFullscreen( false );
250                             } else {
251                                 if( e.isAltDown() ) {
252                                     glWindow.setFullscreen( null );
253                                 } else {
254                                     glWindow.setFullscreen( true );
255                                 }
256                             }
257                             System.err.println("[set fullscreen post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
258                             glWindow.setExclusiveContextThread(t);
259                     } }.start();
260                 } else if(e.getKeyChar()=='a') {
261                     new Thread() {
262                         public void run() {
263                             final Thread t = glWindow.setExclusiveContextThread(null);
264                             System.err.println("[set alwaysontop pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
265                             glWindow.setAlwaysOnTop(!glWindow.isAlwaysOnTop());
266                             System.err.println("[set alwaysontop post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
267                             glWindow.setExclusiveContextThread(t);
268                     } }.start();
269                 } else if(e.getKeyChar()=='d') {
270                     new Thread() {
271                         public void run() {
272                             final Thread t = glWindow.setExclusiveContextThread(null);
273                             // while( null != glWindow.getExclusiveContextThread() ) ;
274                             System.err.println("[set undecorated  pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", d "+glWindow.isUndecorated()+", "+glWindow.getInsets());
275                             glWindow.setUndecorated(!glWindow.isUndecorated());
276                             System.err.println("[set undecorated post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", d "+glWindow.isUndecorated()+", "+glWindow.getInsets());
277                             glWindow.setExclusiveContextThread(t);
278                     } }.start();
279                 } else if(e.getKeyChar()=='s') {
280                     new Thread() {
281                         public void run() {
282                             final Thread t = glWindow.setExclusiveContextThread(null);
283                             System.err.println("[set position  pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
284                             glWindow.setPosition(100, 100);
285                             System.err.println("[set position post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
286                             glWindow.setExclusiveContextThread(t);
287                     } }.start();
288                 } else if(e.getKeyChar()=='c') {
289                     new Thread() {
290                         public void run() {
291                             final Thread t = glWindow.setExclusiveContextThread(null);
292                             System.err.println("[set pointer-icon pre]");
293                             final PointerIcon currentPI = glWindow.getPointerIcon();
294                             final PointerIcon newPI;
295                             if( pointerIconIdx >= pointerIcons.length ) {
296                                 newPI=null;
297                                 pointerIconIdx=0;
298                             } else {
299                                 newPI=pointerIcons[pointerIconIdx++];
300                             }
301                             glWindow.setPointerIcon( newPI );
302                             System.err.println("[set pointer-icon post] "+currentPI+" -> "+glWindow.getPointerIcon());
303                             glWindow.setExclusiveContextThread(t);
304                     } }.start();
305                 } else if(e.getKeyChar()=='i') {
306                     new Thread() {
307                         public void run() {
308                             final Thread t = glWindow.setExclusiveContextThread(null);
309                             System.err.println("[set mouse visible pre]: "+glWindow.isPointerVisible());
310                             glWindow.setPointerVisible(!glWindow.isPointerVisible());
311                             System.err.println("[set mouse visible post]: "+glWindow.isPointerVisible());
312                             glWindow.setExclusiveContextThread(t);
313                     } }.start();
314                 } else if(e.getKeyChar()=='j') {
315                     new Thread() {
316                         public void run() {
317                             final Thread t = glWindow.setExclusiveContextThread(null);
318                             System.err.println("[set mouse confined pre]: "+glWindow.isPointerConfined());
319                             glWindow.confinePointer(!glWindow.isPointerConfined());
320                             System.err.println("[set mouse confined post]: "+glWindow.isPointerConfined());
321                             if(!glWindow.isPointerConfined()) {
322                                 demo.setConfinedFixedCenter(false);
323                             }
324                             glWindow.setExclusiveContextThread(t);
325                     } }.start();
326                 } else if(e.getKeyChar()=='J') {
327                     new Thread() {
328                         public void run() {
329                             final Thread t = glWindow.setExclusiveContextThread(null);
330                             System.err.println("[set mouse confined pre]: "+glWindow.isPointerConfined());
331                             glWindow.confinePointer(!glWindow.isPointerConfined());
332                             System.err.println("[set mouse confined post]: "+glWindow.isPointerConfined());
333                             demo.setConfinedFixedCenter(glWindow.isPointerConfined());
334                             glWindow.setExclusiveContextThread(t);
335                     } }.start();
336                 } else if(e.getKeyChar()=='w') {
337                     new Thread() {
338                         public void run() {
339                             final Thread t = glWindow.setExclusiveContextThread(null);
340                             System.err.println("[set mouse pos pre]");
341                             glWindow.warpPointer(glWindow.getSurfaceWidth()/2, glWindow.getSurfaceHeight()/2);
342                             System.err.println("[set mouse pos post]");
343                             glWindow.setExclusiveContextThread(t);
344                     } }.start();
345                 }
346             }
347         });
348         glWindow.addMouseListener(new MouseAdapter() {
349             public void mouseClicked(MouseEvent e) {
350                 if(e.getClickCount() == 2 && e.getPointerCount() == 1) {
351                     glWindow.setFullscreen(!glWindow.isFullscreen());
352                     System.err.println("setFullscreen: "+glWindow.isFullscreen());
353                 }
354             }
355          });
356
357         if( useAnimator ) {
358             animator.add(glWindow);
359             animator.start();
360             Assert.assertTrue(animator.isStarted());
361             Assert.assertTrue(animator.isAnimating());
362             Assert.assertEquals(exclusiveContext ? animator.getThread() : null, glWindow.getExclusiveContextThread());
363         }
364
365         if( SysExit.displayError == sysExit || SysExit.displayExit == sysExit || SysExit.displayEDTError == sysExit ) {
366             glWindow.addGLEventListener(new GLEventListener() {
367                 @Override
368                 public void init(GLAutoDrawable drawable) {}
369                 @Override
370                 public void dispose(GLAutoDrawable drawable) { }
371                 @Override
372                 public void display(GLAutoDrawable drawable) {
373                     final GLAnimatorControl anim = drawable.getAnimator();
374                     if( null != anim && anim.isAnimating() ) {
375                         final long ms = anim.getTotalFPSDuration();
376                         if( ms >= duration/2 || ms >= 3000 ) { // max 3s wait until provoking error
377                             if( SysExit.displayError == sysExit ) {
378                                 throw new Error("test error send from GLEventListener.display - "+Thread.currentThread());
379                             } else if ( SysExit.displayExit == sysExit ) {
380                                 System.err.println("exit(0) send from GLEventListener");
381                                 System.exit(0);
382                             } else if ( SysExit.displayEDTError == sysExit ) {
383                                 final Object upstream = drawable.getUpstreamWidget();
384                                 System.err.println("EDT invokeAndWaitError: upstream type "+upstream.getClass().getName());
385                                 if( upstream instanceof Window ) {
386                                     final EDTUtil edt = ((Window)upstream).getScreen().getDisplay().getEDTUtil();
387                                     System.err.println("EDT invokeAndWaitError: edt type "+edt.getClass().getName());
388                                     if( edt instanceof DefaultEDTUtil ) {
389                                         quitAdapter.doQuit();
390                                         ((DefaultEDTUtil)edt).invokeAndWaitError(new Runnable() {
391                                             public void run() {
392                                                 throw new RuntimeException("XXX Should never ever be seen! - "+Thread.currentThread());
393                                             }
394                                         });
395                                     }
396                                 }
397                             }
398                         }
399                     } else {
400                         System.exit(0);
401                     }
402                 }
403                 @Override
404                 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
405             });
406         }
407
408         glWindow.setVisible(true);
409         if( useAnimator ) {
410             animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
411         }
412
413         System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
414         System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
415         System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
416
417         snap.setMakeSnapshot();
418
419         if( null != rwsize ) {
420             Thread.sleep(500); // 500ms delay
421             glWindow.setSize(rwsize.getWidth(), rwsize.getHeight());
422             System.err.println("window resize pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
423         }
424
425         snap.setMakeSnapshot();
426
427         final long t0 = System.currentTimeMillis();
428         long t1 = t0;
429         while(!quitAdapter.shouldQuit() && t1-t0<duration) {
430             Thread.sleep(100);
431             t1 = System.currentTimeMillis();
432             if( SysExit.testError == sysExit || SysExit.testExit == sysExit || SysExit.testEDTError == sysExit) {
433                 final long ms = t1-t0;
434                 if( ms >= duration/2 || ms >= 3000 ) { // max 3s wait until provoking error
435                     if( SysExit.testError == sysExit ) {
436                         throw new Error("test error send from test thread");
437                     } else if ( SysExit.testExit == sysExit ) {
438                         System.err.println("exit(0) send from test thread");
439                         System.exit(0);
440                     } else if ( SysExit.testEDTError == sysExit ) {
441                         final EDTUtil edt = glWindow.getScreen().getDisplay().getEDTUtil();
442                         System.err.println("EDT invokeAndWaitError: edt type "+edt.getClass().getName());
443                         if( edt instanceof DefaultEDTUtil ) {
444                             quitAdapter.doQuit();
445                             ((DefaultEDTUtil)edt).invokeAndWaitError(new Runnable() {
446                                 public void run() {
447                                     throw new RuntimeException("XXX Should never ever be seen!");
448                                 }
449                             });
450                         }
451                     }
452                 }
453             }
454         }
455
456         if( useAnimator ) {
457             Assert.assertEquals(exclusiveContext ? animator.getThread() : null, glWindow.getExclusiveContextThread());
458             animator.stop();
459             Assert.assertFalse(animator.isAnimating());
460             Assert.assertFalse(animator.isStarted());
461         }
462         Assert.assertEquals(null, glWindow.getExclusiveContextThread());
463         glWindow.destroy();
464         if( NativeWindowFactory.isAWTAvailable() ) {
465             Assert.assertEquals(true,  AWTRobotUtil.waitForRealized(glWindow, false));
466         }
467     }
468
469     @Test
470     public void test01_GL2ES2() throws InterruptedException {
471         for(int i=1; i<=loops; i++) {
472             System.err.println("Loop "+i+"/"+loops);
473             final GLProfile glp;
474             if(forceGL3) {
475                 glp = GLProfile.get(GLProfile.GL3);
476             } else if(forceES3) {
477                 glp = GLProfile.get(GLProfile.GLES3);
478             } else if(forceES2) {
479                 glp = GLProfile.get(GLProfile.GLES2);
480             } else if(forceGL2) {
481                 glp = GLProfile.get(GLProfile.GL2);
482             } else {
483                 glp = GLProfile.getGL2ES2();
484             }
485             final GLCapabilities caps = new GLCapabilities( glp );
486             caps.setBackgroundOpaque(opaque);
487             if(-1 < forceAlpha) {
488                 caps.setAlphaBits(forceAlpha);
489             }
490             runTestGL(caps, undecorated);
491             if(loop_shutdown) {
492                 GLProfile.shutdown();
493             }
494         }
495     }
496
497     @Test
498     public void test02_GLES2() throws InterruptedException {
499         if(mainRun) return;
500
501         if( !GLProfile.isAvailable(GLProfile.GLES2) ) {
502             System.err.println("GLES2 n/a");
503             return;
504         }
505         final GLProfile glp = GLProfile.get(GLProfile.GLES2);
506         final GLCapabilities caps = new GLCapabilities( glp );
507         runTestGL(caps, undecorated);
508     }
509
510     @Test
511     public void test03_GL3() throws InterruptedException {
512         if(mainRun) return;
513
514         if( !GLProfile.isAvailable(GLProfile.GL3) ) {
515             System.err.println("GL3 n/a");
516             return;
517         }
518         final GLProfile glp = GLProfile.get(GLProfile.GL3);
519         final GLCapabilities caps = new GLCapabilities( glp );
520         runTestGL(caps, undecorated);
521     }
522
523     public static void main(String args[]) throws IOException {
524         mainRun = true;
525
526         int x=0, y=0, w=640, h=480, rw=-1, rh=-1;
527         boolean usePos = false;
528
529         for(int i=0; i<args.length; i++) {
530             if(args[i].equals("-time")) {
531                 i++;
532                 duration = MiscUtils.atol(args[i], duration);
533             } else if(args[i].equals("-translucent")) {
534                 opaque = false;
535             } else if(args[i].equals("-forceAlpha")) {
536                 i++;
537                 forceAlpha = MiscUtils.atoi(args[i], 0);
538             } else if(args[i].equals("-undecorated")) {
539                 undecorated = true;
540             } else if(args[i].equals("-atop")) {
541                 alwaysOnTop = true;
542             } else if(args[i].equals("-fullscreen")) {
543                 fullscreen = true;
544             } else if(args[i].equals("-pmvDirect")) {
545                 pmvUseBackingArray = false;
546             } else if(args[i].equals("-vsync")) {
547                 i++;
548                 swapInterval = MiscUtils.atoi(args[i], swapInterval);
549             } else if(args[i].equals("-exclctx")) {
550                 exclusiveContext = true;
551             } else if(args[i].equals("-noanim")) {
552                 useAnimator  = false;
553             } else if(args[i].equals("-es2")) {
554                 forceES2 = true;
555             } else if(args[i].equals("-es3")) {
556                 forceES3 = true;
557             } else if(args[i].equals("-gl3")) {
558                 forceGL3 = true;
559             } else if(args[i].equals("-gl2")) {
560                 forceGL2 = true;
561             } else if(args[i].equals("-mappedBuffers")) {
562                 useMappedBuffers = true;
563             } else if(args[i].equals("-wait")) {
564                 waitForKey = true;
565             } else if(args[i].equals("-mouseInvisible")) {
566                 mouseVisible = false;
567             } else if(args[i].equals("-mouseConfine")) {
568                 mouseConfined = true;
569             } else if(args[i].equals("-pointerIcon")) {
570                 setPointerIcon = true;
571             } else if(args[i].equals("-showFPS")) {
572                 showFPS = true;
573             } else if(args[i].equals("-width")) {
574                 i++;
575                 w = MiscUtils.atoi(args[i], w);
576             } else if(args[i].equals("-height")) {
577                 i++;
578                 h = MiscUtils.atoi(args[i], h);
579             } else if(args[i].equals("-x")) {
580                 i++;
581                 x = MiscUtils.atoi(args[i], x);
582                 usePos = true;
583             } else if(args[i].equals("-y")) {
584                 i++;
585                 y = MiscUtils.atoi(args[i], y);
586                 usePos = true;
587             } else if(args[i].equals("-rwidth")) {
588                 i++;
589                 rw = MiscUtils.atoi(args[i], rw);
590             } else if(args[i].equals("-rheight")) {
591                 i++;
592                 rh = MiscUtils.atoi(args[i], rh);
593             } else if(args[i].equals("-screen")) {
594                 i++;
595                 screenIdx = MiscUtils.atoi(args[i], 0);
596             } else if(args[i].equals("-loops")) {
597                 i++;
598                 loops = MiscUtils.atoi(args[i], 1);
599             } else if(args[i].equals("-loop-shutdown")) {
600                 loop_shutdown = true;
601             } else if(args[i].equals("-sysExit")) {
602                 i++;
603                 sysExit = SysExit.valueOf(args[i]);
604             }
605         }
606         wsize = new Dimension(w, h);
607         if( 0 < rw && 0 < rh ) {
608             rwsize = new Dimension(rw, rh);
609         }
610
611         if(usePos) {
612             wpos = new Point(x, y);
613         }
614         System.err.println("position "+wpos);
615         System.err.println("size "+wsize);
616         System.err.println("resize "+rwsize);
617         System.err.println("screen "+screenIdx);
618         System.err.println("translucent "+(!opaque));
619         System.err.println("forceAlpha "+forceAlpha);
620         System.err.println("undecorated "+undecorated);
621         System.err.println("atop "+alwaysOnTop);
622         System.err.println("fullscreen "+fullscreen);
623         System.err.println("pmvDirect "+(!pmvUseBackingArray));
624         System.err.println("mouseVisible "+mouseVisible);
625         System.err.println("mouseConfined "+mouseConfined);
626         System.err.println("pointerIcon "+setPointerIcon);
627         System.err.println("loops "+loops);
628         System.err.println("loop shutdown "+loop_shutdown);
629         System.err.println("forceES2 "+forceES2);
630         System.err.println("forceES3 "+forceES3);
631         System.err.println("forceGL3 "+forceGL3);
632         System.err.println("forceGL2 "+forceGL2);
633         System.err.println("swapInterval "+swapInterval);
634         System.err.println("exclusiveContext "+exclusiveContext);
635         System.err.println("useAnimator "+useAnimator);
636         System.err.println("sysExitWithin "+sysExit);
637         System.err.println("mappedBuffers "+useMappedBuffers);
638
639         if(waitForKey) {
640             UITestCase.waitForKey("Start");
641         }
642         org.junit.runner.JUnitCore.main(TestGearsES2NEWT.class.getName());
643     }
644 }
http://JogAmp.org git info: FAQ, tutorial and man pages.