JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestFBOMix2DemosES2NEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2012 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.acore;
30
31import java.io.BufferedReader;
32import java.io.IOException;
33import java.io.InputStreamReader;
34
35import com.jogamp.common.util.InterruptSource;
36import com.jogamp.newt.event.KeyAdapter;
37import com.jogamp.newt.event.KeyEvent;
38import com.jogamp.newt.event.WindowEvent;
39import com.jogamp.newt.event.WindowAdapter;
40import com.jogamp.newt.opengl.GLWindow;
41import com.jogamp.opengl.test.junit.util.MiscUtils;
42import com.jogamp.opengl.test.junit.util.NewtTestUtil;
43import com.jogamp.opengl.test.junit.util.UITestCase;
44import com.jogamp.opengl.test.junit.util.QuitAdapter;
45
46import com.jogamp.opengl.util.Animator;
47import com.jogamp.opengl.util.GLReadBufferUtil;
48import com.jogamp.opengl.util.texture.TextureIO;
49
50import com.jogamp.opengl.test.junit.jogl.demos.es2.FBOMix2DemosES2;
51
52import com.jogamp.opengl.GLAutoDrawable;
53import com.jogamp.opengl.GLCapabilities;
54import com.jogamp.opengl.GLCapabilitiesImmutable;
55import com.jogamp.opengl.GLEventListener;
56import com.jogamp.opengl.GLProfile;
57
58import org.junit.Assert;
59import org.junit.AfterClass;
60import org.junit.Test;
61import org.junit.FixMethodOrder;
62import org.junit.runners.MethodSorters;
63
64@FixMethodOrder(MethodSorters.NAME_ASCENDING)
65public class TestFBOMix2DemosES2NEWT extends UITestCase {
66 static long duration = 1000; // ms
67 static int swapInterval = 1;
68 static boolean showFPS = false;
69 static boolean forceES2 = false;
70 static boolean doRotate = true;
71 static boolean demo0Only = false;
72 static int globalNumSamples = 0;
73 static boolean manual = false;
74
75 @AfterClass
76 public static void releaseClass() {
77 }
78
79 protected void runTestGL(final GLCapabilitiesImmutable caps, final int numSamples) throws InterruptedException {
80 final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
81 System.err.println("requested: vsync "+swapInterval+", "+caps);
82 final GLWindow glWindow = GLWindow.create(caps);
83 Assert.assertNotNull(glWindow);
84 glWindow.setTitle("Gears NEWT Test (translucent "+!caps.isBackgroundOpaque()+"), swapInterval "+swapInterval);
85 if(manual) {
86 glWindow.setSize(512, 512);
87 } else {
88 glWindow.setSize(128, 128);
89 }
90
91 final FBOMix2DemosES2 demo = new FBOMix2DemosES2(swapInterval);
92 demo.setMSAA(numSamples);
93 demo.setDoRotation(doRotate);
94 demo.setDemo0Only(demo0Only);
95 glWindow.addGLEventListener(demo);
96 glWindow.addGLEventListener(new GLEventListener() {
97 int i=0, c=0;
98 int origS;
99 public void init(final GLAutoDrawable drawable) {
100 origS = demo.getMSAA();
101 }
102 public void dispose(final GLAutoDrawable drawable) {}
103 public void display(final GLAutoDrawable drawable) {
104 if(manual) return;
105
106 final int dw = drawable.getSurfaceWidth();
107 final int dh = drawable.getSurfaceHeight();
108 c++;
109
110 if(dw<800) {
111 System.err.println("XXX: "+dw+"x"+dh+", c "+c);
112 if(0 == c%3) {
113 snapshot(i++, "msaa"+demo.getMSAA(), drawable.getGL(), screenshot, TextureIO.PNG, null);
114 }
115 if( 3 == c ) {
116 demo.setMSAA(4);
117 } else if( 6 == c ) {
118 new InterruptSource.Thread() {
119 @Override
120 public void run() {
121 glWindow.setSize(dw+64, dh+64);
122 } }.start();
123 } else if( 9 == c ) {
124 demo.setMSAA(8);
125 } else if( 12 == c ) {
126 demo.setMSAA(0);
127 } else if( 15 == c ) {
128 new InterruptSource.Thread() {
129 @Override
130 public void run() {
131 glWindow.setSize(dw+128, dh+128);
132 } }.start();
133 } else if( 18 == c ) {
134 c=0;
135 new InterruptSource.Thread() {
136 @Override
137 public void run() {
138 glWindow.setSize(dw+256, dh+256);
139 demo.setMSAA(origS);
140 } }.start();
141 }
142 }
143 }
144 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
145 });
146
147 final Animator animator = new Animator(glWindow);
148 final QuitAdapter quitAdapter = new QuitAdapter();
149
150 //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
151 //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
152 glWindow.addKeyListener(quitAdapter);
153 glWindow.addWindowListener(quitAdapter);
154
155 glWindow.addWindowListener(new WindowAdapter() {
156 public void windowResized(final WindowEvent e) {
157 System.err.println("window resized: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight());
158 }
159 public void windowMoved(final WindowEvent e) {
160 System.err.println("window moved: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight());
161 }
162 });
163
164 glWindow.addKeyListener(new KeyAdapter() {
165 public void keyReleased(final KeyEvent e) {
166 if( !e.isPrintableKey() || e.isAutoRepeat() ) {
167 return;
168 }
169 System.err.println("*** "+e);
170 if(e.getKeyChar()=='f') {
171 new InterruptSource.Thread() {
172 public void run() {
173 System.err.println("[set fullscreen pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
174 glWindow.setFullscreen(!glWindow.isFullscreen());
175 System.err.println("[set fullscreen post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
176 } }.start();
177 } else if(e.getKeyChar()=='d') {
178 demo.setDemo0Only(!demo.getDemo0Only());
179 } else {
180 final int num = e.getKeyChar() - '0';
181 System.err.println("*** "+num);
182 if(0 <= num && num <= 8) {
183 System.err.println("MSAA: "+demo.getMSAA()+" -> "+num);
184 demo.setMSAA(num);
185 }
186 }
187 }
188 });
189
190 animator.start();
191 // glWindow.setSkipContextReleaseThread(animator.getThread());
192
193 glWindow.setVisible(true);
194
195 System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
196 System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
197 System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
198
199 animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
200
201 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
202 Thread.sleep(100);
203 }
204
205 animator.stop();
206 Assert.assertFalse(animator.isAnimating());
207 Assert.assertFalse(animator.isStarted());
208 glWindow.destroy();
209 Assert.assertEquals(true, NewtTestUtil.waitForRealized(glWindow, false, null));
210 }
211
212 @Test
213 public void test00_Manual() throws InterruptedException {
214 if( manual ) {
216 caps.setAlphaBits(1);
217 runTestGL(caps, globalNumSamples);
218 }
219 }
220
221 @Test
222 public void test01_startMSAA0() throws InterruptedException {
223 if( manual ) return ;
225 caps.setAlphaBits(1);
226 runTestGL(caps, 0);
227 }
228
229 @Test
230 public void test02_startMSAA4() throws InterruptedException {
231 if( manual ) return ;
233 caps.setAlphaBits(1);
234 runTestGL(caps, 4);
235 }
236
237 public static void main(final String args[]) throws IOException {
238 boolean waitForKey = false;
239
240 manual = false;
241
242 for(int i=0; i<args.length; i++) {
243 if(args[i].equals("-time")) {
244 i++;
245 duration = MiscUtils.atol(args[i], duration);
246 } else if(args[i].equals("-vsync")) {
247 i++;
248 swapInterval = MiscUtils.atoi(args[i], swapInterval);
249 } else if(args[i].equals("-es2")) {
250 forceES2 = true;
251 } else if(args[i].equals("-showFPS")) {
252 showFPS = true;
253 } else if(args[i].equals("-samples")) {
254 i++;
255 globalNumSamples = MiscUtils.atoi(args[i], globalNumSamples);
256 } else if(args[i].equals("-norotate")) {
257 doRotate = false;
258 } else if(args[i].equals("-demo0Only")) {
259 demo0Only = true;
260 } else if(args[i].equals("-wait")) {
261 waitForKey = true;
262 } else if(args[i].equals("-manual")) {
263 manual = true;
264 }
265 }
266
267 System.err.println("swapInterval "+swapInterval);
268 System.err.println("forceES2 "+forceES2);
269 System.err.println("manual "+manual);
270
271 if(waitForKey) {
272 final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
273 System.err.println("Press enter to continue");
274 try {
275 System.err.println(stdin.readLine());
276 } catch (final IOException e) { }
277 }
278 org.junit.runner.JUnitCore.main(TestFBOMix2DemosES2NEWT.class.getName());
279 }
280}
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
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
NEWT Window events are provided for notification purposes ONLY.
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 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 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
void runTestGL(final GLCapabilitiesImmutable caps, final int numSamples)
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
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
static final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
Definition: TextureIO.java:171
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.