JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestRedSquareES2NEWT.java
Go to the documentation of this file.
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
29package com.jogamp.opengl.test.junit.jogl.demos.es2.newt;
30
31import com.jogamp.newt.event.KeyAdapter;
32import com.jogamp.newt.event.KeyEvent;
33import com.jogamp.newt.opengl.GLWindow;
34import com.jogamp.opengl.test.junit.util.MiscUtils;
35import com.jogamp.opengl.test.junit.util.NewtTestUtil;
36import com.jogamp.opengl.test.junit.util.UITestCase;
37import com.jogamp.opengl.test.junit.util.QuitAdapter;
38import com.jogamp.opengl.util.Animator;
39import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
40import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareMappedES2;
41
42import com.jogamp.nativewindow.NativeWindowFactory;
43import com.jogamp.opengl.GLCapabilities;
44import com.jogamp.opengl.GLEventListener;
45import com.jogamp.opengl.GLProfile;
46
47import org.junit.Assert;
48import org.junit.BeforeClass;
49import org.junit.AfterClass;
50import org.junit.Test;
51import org.junit.FixMethodOrder;
52import org.junit.runners.MethodSorters;
53
54@FixMethodOrder(MethodSorters.NAME_ASCENDING)
55public class TestRedSquareES2NEWT extends UITestCase {
56 static int width, height;
57 static int loops = 1;
58 static boolean loop_shutdown = false;
59 static boolean vsync = false;
60 static boolean forceES2 = false;
61 static boolean forceGL3 = false;
62 static boolean mainRun = false;
63 static boolean doRotate = true;
64 static boolean useMappedBuffers = false;
65
66 @BeforeClass
67 public static void initClass() {
68 width = 512;
69 height = 512;
70 }
71
72 @AfterClass
73 public static void releaseClass() {
74 }
75
76 protected void runTestGL(final GLCapabilities caps) throws InterruptedException {
77 System.err.println("requested: vsync "+vsync+", "+caps);
78 final GLWindow glWindow = GLWindow.create(caps);
79 Assert.assertNotNull(glWindow);
80 glWindow.setTitle(getSimpleTestName("."));
81 glWindow.setSize(width, height);
82
83 final GLEventListener demo;
84 if( useMappedBuffers ) {
85 final RedSquareMappedES2 red = new RedSquareMappedES2(vsync ? 1 : -1);
86 red.setDoRotation(doRotate);
87 demo = red;
88 } else {
89 final RedSquareES2 red = new RedSquareES2(vsync ? 1 : -1);
90 red.setDoRotation(doRotate);
91 demo = red;
92 }
93 glWindow.addGLEventListener(demo);
94
96 snap.setPostSNDetail(demo.getClass().getSimpleName());
97 glWindow.addGLEventListener(snap);
98
99 final Animator animator = new Animator(glWindow);
100 final QuitAdapter quitAdapter = new QuitAdapter();
101
102 //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
103 //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
104 glWindow.addKeyListener(quitAdapter);
105 glWindow.addWindowListener(quitAdapter);
106
107 glWindow.addKeyListener(new KeyAdapter() {
108 public void keyReleased(final KeyEvent e) {
109 if( !e.isPrintableKey() || e.isAutoRepeat() ) {
110 return;
111 }
112 if(e.getKeyChar()=='f') {
113 glWindow.invokeOnNewThread(null, false, new Runnable() {
114 public void run() {
115 glWindow.setFullscreen(!glWindow.isFullscreen());
116 } } );
117 } else if(e.getKeyChar()=='d') {
118 glWindow.invokeOnNewThread(null, false, new Runnable() {
119 public void run() {
120 glWindow.setUndecorated(!glWindow.isUndecorated());
121 } } );
122 }
123 }
124 });
125
126 animator.start();
127
128 glWindow.setVisible(true);
129
130 System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
131 System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
132 System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
133
134 animator.setUpdateFPSFrames(60, System.err);
135 snap.setMakeSnapshot();
136
137 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
138 Thread.sleep(100);
139 }
140
141 animator.stop();
142 Assert.assertFalse(animator.isAnimating());
143 Assert.assertFalse(animator.isStarted());
144 glWindow.destroy();
145 if( NativeWindowFactory.isAWTAvailable() ) {
146 Assert.assertEquals(true, NewtTestUtil.waitForRealized(glWindow, false, null));
147 }
148 }
149
150 @Test
151 public void test01GL2ES2() throws InterruptedException {
152 for(int i=1; i<=loops; i++) {
153 System.err.println("Loop "+i+"/"+loops);
154 final GLProfile glp;
155 if(forceGL3) {
156 glp = GLProfile.get(GLProfile.GL3);
157 } else if(forceES2) {
159 } else {
160 glp = GLProfile.getGL2ES2();
161 }
162 final GLCapabilities caps = new GLCapabilities(glp);
163 runTestGL(caps);
164 if(loop_shutdown) {
166 }
167 }
168 }
169
170 @Test
171 public void test02GL3() throws InterruptedException {
172 if(mainRun) return;
173
175 System.err.println("GL3 n/a");
176 return;
177 }
178 final GLProfile glp = GLProfile.get(GLProfile.GL3);
179 final GLCapabilities caps = new GLCapabilities( glp );
180 runTestGL(caps);
181 }
182
183 static long duration = 500; // ms
184
185 public static void main(final String args[]) {
186 mainRun = true;
187 for(int i=0; i<args.length; i++) {
188 if(args[i].equals("-time")) {
189 i++;
190 duration = MiscUtils.atol(args[i], duration);
191 } else if(args[i].equals("-es2")) {
192 forceES2 = true;
193 } else if(args[i].equals("-gl3")) {
194 forceGL3 = true;
195 } else if(args[i].equals("-norotate")) {
196 doRotate = false;
197 } else if(args[i].equals("-mappedBuffers")) {
198 useMappedBuffers = true;
199 } else if(args[i].equals("-loops")) {
200 i++;
201 loops = MiscUtils.atoi(args[i], 1);
202 } else if(args[i].equals("-loop-shutdown")) {
203 loop_shutdown = true;
204 }
205 }
206 System.err.println("duration "+duration);
207 System.err.println("loops "+loops);
208 System.err.println("loop shutdown "+loop_shutdown);
209 System.err.println("forceES2 "+forceES2);
210 System.err.println("forceGL3 "+forceGL3);
211 System.err.println("mappedBuffers "+useMappedBuffers);
212 org.junit.runner.JUnitCore.main(TestRedSquareES2NEWT.class.getName());
213 }
214}
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
final boolean isAutoRepeat()
getModifiers() contains AUTOREPEAT_MASK.
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
Definition: KeyEvent.java:161
static boolean isPrintableKey(final short uniChar, final boolean isKeyChar)
Returns true if given uniChar represents a printable character, i.e.
Definition: KeyEvent.java:316
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:466
final void setTitle(final String title)
Definition: GLWindow.java:297
final int getX()
Returns the current x position of this window, relative to it's parent.
Definition: GLWindow.java:436
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
Definition: GLWindow.java:902
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
Definition: GLWindow.java:441
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:461
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
Definition: GLWindow.java:534
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
Definition: GLWindow.java:266
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
Definition: GLWindow.java:431
final void setUndecorated(final boolean value)
Definition: GLWindow.java:337
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
Definition: GLWindow.java:277
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
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 GL3
The desktop OpenGL core profile 3.x, with x >= 1.
Definition: GLProfile.java:576
static void shutdown()
Manual shutdown method, may be called after your last JOGL use within the running JVM.
Definition: GLProfile.java:277
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
Definition: GLProfile.java:585
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.
Definition: GLProfile.java:913
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
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
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.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.