JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLAutoDrawableFactoryGL2OffscrnCapsNEWT.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.acore;
30
31import java.io.IOException;
32
33import com.jogamp.nativewindow.CapabilitiesImmutable;
34import com.jogamp.opengl.GLCapabilities;
35import com.jogamp.opengl.GLCapabilitiesImmutable;
36import com.jogamp.opengl.GLContext;
37import com.jogamp.opengl.GLDrawableFactory;
38import com.jogamp.opengl.GLEventListener;
39import com.jogamp.opengl.GLOffscreenAutoDrawable;
40import com.jogamp.opengl.GLProfile;
41
42import jogamp.opengl.GLGraphicsConfigurationUtil;
43
44import org.junit.Assert;
45import org.junit.Test;
46import org.junit.FixMethodOrder;
47import org.junit.runners.MethodSorters;
48
49import com.jogamp.opengl.JoglVersion;
50import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
51import com.jogamp.opengl.test.junit.util.GLTestUtil;
52import com.jogamp.opengl.test.junit.util.UITestCase;
53
54/**
55 * Toolkit agnostic {@link GLOffscreenAutoDrawable} tests using the
56 * {@link GLDrawableFactory#createOffscreenAutoDrawable(com.jogamp.nativewindow.AbstractGraphicsDevice, GLCapabilitiesImmutable, com.jogamp.opengl.GLCapabilitiesChooser, int, int, GLContext) factory model}.
57 * <p>
58 * The created {@link GLOffscreenAutoDrawable} is being used to run the {@link GLEventListener}.
59 * </p>
60 */
61@FixMethodOrder(MethodSorters.NAME_ASCENDING)
63 static final int widthStep = 800/4;
64 static final int heightStep = 600/4;
65 volatile int szStep = 2;
66
67 static GLCapabilities getCaps(final String profile) {
68 if( !GLProfile.isAvailable(profile) ) {
69 System.err.println("Profile "+profile+" n/a");
70 return null;
71 }
72 return new GLCapabilities(GLProfile.get(profile));
73 }
74
75 void doTest(final GLCapabilitiesImmutable reqGLCaps, final GLEventListener demo) throws InterruptedException {
76 System.out.println("Requested GL Caps: "+reqGLCaps);
78 final GLCapabilitiesImmutable expGLCaps = GLGraphicsConfigurationUtil.fixGLCapabilities(reqGLCaps, factory, null);
79 System.out.println("Expected GL Caps: "+expGLCaps);
80
81 //
82 // Create native OpenGL resources .. XGL/WGL/CGL ..
83 // equivalent to GLAutoDrawable methods: setVisible(true)
84 //
85 final GLOffscreenAutoDrawable glad = factory.createOffscreenAutoDrawable(null, reqGLCaps, null, widthStep*szStep, heightStep*szStep);
86
87 Assert.assertNotNull(glad);
88 System.out.println("Drawable Pre-GL(0): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName());
89 Assert.assertTrue(glad.isRealized());
90
91 // Check caps of NativeWindow config w/o GL
92 final CapabilitiesImmutable chosenCaps = glad.getChosenGLCapabilities();
93 System.out.println("Drawable Caps Pre_GL : "+chosenCaps);
94 Assert.assertNotNull(chosenCaps);
95 Assert.assertTrue(chosenCaps.getGreenBits()>4);
96 Assert.assertTrue(chosenCaps.getBlueBits()>4);
97 Assert.assertTrue(chosenCaps.getRedBits()>4);
98
99 glad.display(); // force native context creation
100
101 // Check caps of GLDrawable after realization
102 final GLCapabilitiesImmutable chosenGLCaps = glad.getChosenGLCapabilities();
103 System.out.println("Chosen GL CTX (1): "+glad.getContext().getGLVersion());
104 System.out.println("Chosen GL Caps(1): "+chosenGLCaps);
105 System.out.println("Chosen GL Caps(2): "+glad.getNativeSurface().getGraphicsConfiguration().getChosenCapabilities());
106
107 Assert.assertNotNull(chosenGLCaps);
108 Assert.assertTrue(chosenGLCaps.getGreenBits()>4);
109 Assert.assertTrue(chosenGLCaps.getBlueBits()>4);
110 Assert.assertTrue(chosenGLCaps.getRedBits()>4);
111 Assert.assertTrue(chosenGLCaps.getDepthBits()>4);
112 Assert.assertEquals(expGLCaps.isOnscreen(), chosenGLCaps.isOnscreen());
113 Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps.isFBO());
114 Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps.isPBuffer());
115 Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps.isBitmap());
116 /** Single/Double buffer cannot be checked since result may vary ..
117 if(chosenGLCaps.isOnscreen() || chosenGLCaps.isFBO()) {
118 // dbl buffer may be disabled w/ offscreen pbuffer and bitmap
119 Assert.assertEquals(expGLCaps.getDoubleBuffered(), chosenGLCaps.getDoubleBuffered());
120 } */
121
122 glad.addGLEventListener(demo);
123
124 final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener();
125 glad.addGLEventListener(snapshotGLEventListener);
126
127 glad.display(); // initial resize/display
128
129 // 1 - szStep = 2
130 Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(),
131 GLTestUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep, null));
132 snapshotGLEventListener.setMakeSnapshot();
133 glad.display();
134
135 // 2, 3 (resize + display)
136 szStep = 1;
137 glad.setSurfaceSize(widthStep*szStep, heightStep*szStep);
138 Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(),
139 GLTestUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep, null));
140 snapshotGLEventListener.setMakeSnapshot();
141 glad.display();
142
143 // 4, 5 (resize + display)
144 szStep = 4;
145 glad.setSurfaceSize(widthStep*szStep, heightStep*szStep);
146 Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(),
147 GLTestUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep, null));
148 snapshotGLEventListener.setMakeSnapshot();
149 glad.display();
150
151 Thread.sleep(50);
152
153 glad.destroy();
154 System.out.println("Fin Drawable: "+glad);
155 }
156
157 @Test
158 public void testGL2OffScreenAutoDblBuf() throws InterruptedException {
159 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
160 if(null == reqGLCaps) return;
161 reqGLCaps.setOnscreen(false);
162 doTest(reqGLCaps, new Gears(1));
163 }
164
165 @Test
166 public void testGL2OffScreenFBODblBuf() throws InterruptedException {
167 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
168 if(null == reqGLCaps) return;
169 reqGLCaps.setOnscreen(false);
170 reqGLCaps.setFBO(true);
171 doTest(reqGLCaps, new Gears(1));
172 }
173
174 @Test
175 public void testGL2OffScreenFBOSglBuf() throws InterruptedException {
176 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
177 if(null == reqGLCaps) return;
178 reqGLCaps.setOnscreen(false);
179 reqGLCaps.setFBO(true);
180 reqGLCaps.setDoubleBuffered(false);
181 doTest(reqGLCaps, new Gears(1));
182 }
183
184 @Test
185 public void testGL2OffScreenFBODblBufStencil() throws InterruptedException {
186 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
187 if(null == reqGLCaps) return;
188 reqGLCaps.setOnscreen(false);
189 reqGLCaps.setFBO(true);
190 reqGLCaps.setStencilBits(1);
191 doTest(reqGLCaps, new Gears(1));
192 }
193
194 @Test
195 public void testGL2OffScreenFBODblBufMSAA() throws InterruptedException {
196 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
197 if(null == reqGLCaps) return;
198 reqGLCaps.setOnscreen(false);
199 reqGLCaps.setFBO(true);
200 reqGLCaps.setSampleBuffers(true);
201 reqGLCaps.setNumSamples(4);
202 doTest(reqGLCaps, new Gears(1));
203 }
204
205 @Test
206 public void testGL2OffScreenFBODblBufStencilMSAA() throws InterruptedException {
207 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
208 if(null == reqGLCaps) return;
209 reqGLCaps.setOnscreen(false);
210 reqGLCaps.setFBO(true);
211 reqGLCaps.setStencilBits(1);
212 reqGLCaps.setSampleBuffers(true);
213 reqGLCaps.setNumSamples(4);
214 doTest(reqGLCaps, new Gears(1));
215 }
216
217 @Test
218 public void testGL2OffScreenPbufferDblBuf() throws InterruptedException {
219 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
220 if(null == reqGLCaps) return;
221 reqGLCaps.setOnscreen(false);
222 reqGLCaps.setPBuffer(true);
223 doTest(reqGLCaps, new Gears(1));
224 }
225
226 @Test
227 public void testGL2OffScreenPbufferSglBuf() throws InterruptedException {
228 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
229 if(null == reqGLCaps) return;
230 reqGLCaps.setOnscreen(false);
231 reqGLCaps.setPBuffer(true);
232 reqGLCaps.setDoubleBuffered(false);
233 doTest(reqGLCaps, new Gears(1));
234 }
235
236 // Might be reduced to !stencil
237 @Test
238 public void testGL2OffScreenPbufferDblBufStencil() throws InterruptedException {
239 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
240 if(null == reqGLCaps) return;
241 reqGLCaps.setOnscreen(false);
242 reqGLCaps.setPBuffer(true);
243 reqGLCaps.setStencilBits(1);
244 doTest(reqGLCaps, new Gears(1));
245 }
246
247 // Might be reduced to !MSAA
248 @Test
249 public void testGL2OffScreenPbufferDblBufMSAA() throws InterruptedException {
250 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
251 if(null == reqGLCaps) return;
252 reqGLCaps.setOnscreen(false);
253 reqGLCaps.setPBuffer(true);
254 reqGLCaps.setSampleBuffers(true);
255 reqGLCaps.setNumSamples(4);
256 doTest(reqGLCaps, new Gears(1));
257 }
258
259 // Might be reduced to !stencil && !MSAA
260 @Test
261 public void testGL2OffScreenPbufferDblBufStencilMSAA() throws InterruptedException {
262 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
263 if(null == reqGLCaps) return;
264 reqGLCaps.setOnscreen(false);
265 reqGLCaps.setPBuffer(true);
266 reqGLCaps.setStencilBits(1);
267 reqGLCaps.setSampleBuffers(true);
268 reqGLCaps.setNumSamples(4);
269 doTest(reqGLCaps, new Gears(1));
270 }
271
272
273 // Might be reduced to !double-buff
274 @Test
275 public void testGL2OffScreenBitmapDblBuf() throws InterruptedException {
276 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
277 if(null == reqGLCaps) return;
278 reqGLCaps.setOnscreen(false);
279 reqGLCaps.setBitmap(true);
280 doTest(reqGLCaps, new Gears(1));
281 }
282
283 @Test
284 public void testGL2OffScreenBitmapDblBufRGBA8881() throws InterruptedException {
285 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
286 if(null == reqGLCaps) return;
287 reqGLCaps.setRedBits(8);
288 reqGLCaps.setGreenBits(8);
289 reqGLCaps.setBlueBits(8);
290 reqGLCaps.setAlphaBits(1);
291 reqGLCaps.setOnscreen(false);
292 reqGLCaps.setBitmap(true);
293 doTest(reqGLCaps, new Gears(1));
294 }
295
296 @Test
297 public void testGL2OffScreenBitmapDblBufRGB555() throws InterruptedException {
298 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
299 if(null == reqGLCaps) return;
300 reqGLCaps.setRedBits(5);
301 reqGLCaps.setGreenBits(5);
302 reqGLCaps.setBlueBits(5);
303 reqGLCaps.setAlphaBits(0);
304 reqGLCaps.setOnscreen(false);
305 reqGLCaps.setBitmap(true);
306 doTest(reqGLCaps, new Gears(1));
307 }
308
309 @Test
310 public void testGL2OffScreenBitmapDblBufRGBA5551() throws InterruptedException {
311 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
312 if(null == reqGLCaps) return;
313 reqGLCaps.setRedBits(5);
314 reqGLCaps.setGreenBits(5);
315 reqGLCaps.setBlueBits(5);
316 reqGLCaps.setAlphaBits(1);
317 reqGLCaps.setOnscreen(false);
318 reqGLCaps.setBitmap(true);
319 doTest(reqGLCaps, new Gears(1));
320 }
321
322 @Test
323 public void testGL2OffScreenBitmapSglBuf() throws InterruptedException {
324 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
325 if(null == reqGLCaps) return;
326 reqGLCaps.setOnscreen(false);
327 reqGLCaps.setBitmap(true);
328 reqGLCaps.setDoubleBuffered(false);
329 doTest(reqGLCaps, new Gears(1));
330 }
331
332 // Might be reduced to !stencil
333 @Test
334 public void testGL2OffScreenBitmapDblBufStencil() throws InterruptedException {
335 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
336 if(null == reqGLCaps) return;
337 reqGLCaps.setOnscreen(false);
338 reqGLCaps.setBitmap(true);
339 reqGLCaps.setStencilBits(1);
340 doTest(reqGLCaps, new Gears(1));
341 }
342
343 // Might be reduced to !MSAA
344 @Test
345 public void testGL2OffScreenBitmapDblBufMSAA() throws InterruptedException {
346 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
347 if(null == reqGLCaps) return;
348 reqGLCaps.setOnscreen(false);
349 reqGLCaps.setBitmap(true);
350 reqGLCaps.setSampleBuffers(true);
351 reqGLCaps.setNumSamples(4);
352 doTest(reqGLCaps, new Gears(1));
353 }
354
355 // Might be reduced to !stencil && !MSAA
356 @Test
357 public void testGL2OffScreenBitmapDblBufStencilMSAA() throws InterruptedException {
358 final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2);
359 if(null == reqGLCaps) return;
360 reqGLCaps.setOnscreen(false);
361 reqGLCaps.setBitmap(true);
362 reqGLCaps.setStencilBits(1);
363 reqGLCaps.setSampleBuffers(true);
364 reqGLCaps.setNumSamples(4);
365 doTest(reqGLCaps, new Gears(1));
366 }
367
368 public static void main(final String args[]) throws IOException {
369 org.junit.runner.JUnitCore.main(TestGLAutoDrawableFactoryGL2OffscrnCapsNEWT.class.getName());
370 }
371
372}
void setRedBits(final int redBits)
Sets the number of bits requested for the color buffer's red component.
void setBitmap(final boolean enable)
Requesting offscreen bitmap mode.
void setGreenBits(final int greenBits)
Sets the number of bits requested for the color buffer's green component.
void setBlueBits(final int blueBits)
Sets the number of bits requested for the color buffer's blue component.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
Specifies a set of OpenGL capabilities.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
void setStencilBits(final int stencilBits)
Sets the number of bits requested for the stencil buffer.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
void setFBO(final boolean enable)
Requesting offscreen FBO mode.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
final String getGLVersion()
Returns a valid OpenGL version string, ie
Definition: GLContext.java:769
abstract GLOffscreenAutoDrawable createOffscreenAutoDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates a realized GLOffscreenAutoDrawable incl it's offscreen NativeSurface with the given capabilit...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
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 GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
Definition: GLProfile.java:579
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
Definition: Gears.java:34
static boolean waitForSize(final GLDrawable drawable, final int width, final int height, final Runnable waitAction)
Definition: GLTestUtil.java:72
CapabilitiesImmutable getChosenCapabilities()
Return the capabilities reflecting this graphics configuration, which may differ from the capabilitie...
Specifies an immutable set of capabilities that a window's rendering context must support,...
int getBlueBits()
Returns the number of bits for the color buffer's blue component.
boolean isBitmap()
Returns whether bitmap offscreen mode is requested, available or chosen.
int getRedBits()
Returns the number of bits for the color buffer's red component.
int getGreenBits()
Returns the number of bits for the color buffer's green component.
boolean isOnscreen()
Returns whether an on- or offscreen surface is requested, available or chosen.
AbstractGraphicsConfiguration getGraphicsConfiguration()
Returns the graphics configuration corresponding to this window.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
GLContext getContext()
Returns the context associated with this drawable.
Specifies an immutable set of OpenGL capabilities.
int getDepthBits()
Returns the number of depth buffer bits.
boolean isPBuffer()
Returns whether pbuffer offscreen mode is requested, available or chosen.
GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
boolean isFBO()
Returns whether FBO offscreen mode is requested, available or chosen.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
boolean isRealized()
Returns true if this drawable is realized, otherwise false.
NativeSurface getNativeSurface()
Returns the associated NativeSurface of this NativeSurfaceHolder.
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.
Platform-independent GLAutoDrawable specialization, exposing offscreen functionality.
void setSurfaceSize(int newWidth, int newHeight)
Resize this GLAutoDrawable's surface.