JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLAutoDrawableFactoryGLnBitmapCapsNEWT.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 void doTest(final GLCapabilitiesImmutable reqGLCaps, final GLEventListener demo) throws InterruptedException {
68 System.out.println("Requested GL Caps: "+reqGLCaps);
70 final GLCapabilitiesImmutable expGLCaps = GLGraphicsConfigurationUtil.fixGLCapabilities(reqGLCaps, factory, null);
71 System.out.println("Expected GL Caps: "+expGLCaps);
72
73 //
74 // Create native OpenGL resources .. XGL/WGL/CGL ..
75 // equivalent to GLAutoDrawable methods: setVisible(true)
76 //
77 final GLOffscreenAutoDrawable glad = factory.createOffscreenAutoDrawable(null, reqGLCaps, null, widthStep*szStep, heightStep*szStep);
78
79 Assert.assertNotNull(glad);
80 System.out.println("Drawable Pre-GL(0): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName());
81 Assert.assertTrue(glad.isRealized());
82
83 // Check caps of NativeWindow config w/o GL
84 final CapabilitiesImmutable chosenCaps = glad.getChosenGLCapabilities();
85 System.out.println("Drawable Caps Pre_GL : "+chosenCaps);
86 Assert.assertNotNull(chosenCaps);
87 Assert.assertTrue(chosenCaps.getGreenBits()>4);
88 Assert.assertTrue(chosenCaps.getBlueBits()>4);
89 Assert.assertTrue(chosenCaps.getRedBits()>4);
90
91 glad.display(); // force native context creation
92
93 // Check caps of GLDrawable after realization
94 final GLCapabilitiesImmutable chosenGLCaps = glad.getChosenGLCapabilities();
95 System.out.println("Chosen GL CTX (1): "+glad.getContext().getGLVersion());
96 System.out.println("Chosen GL Caps(1): "+chosenGLCaps);
97 System.out.println("Chosen GL Caps(2): "+glad.getNativeSurface().getGraphicsConfiguration().getChosenCapabilities());
98
99 Assert.assertNotNull(chosenGLCaps);
100 Assert.assertTrue(chosenGLCaps.getGreenBits()>4);
101 Assert.assertTrue(chosenGLCaps.getBlueBits()>4);
102 Assert.assertTrue(chosenGLCaps.getRedBits()>4);
103 Assert.assertTrue(chosenGLCaps.getDepthBits()>4);
104 Assert.assertEquals(expGLCaps.isOnscreen(), chosenGLCaps.isOnscreen());
105 Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps.isFBO());
106 Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps.isPBuffer());
107 Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps.isBitmap());
108 /** Single/Double buffer cannot be checked since result may vary ..
109 if(chosenGLCaps.isOnscreen() || chosenGLCaps.isFBO()) {
110 // dbl buffer may be disabled w/ offscreen pbuffer and bitmap
111 Assert.assertEquals(expGLCaps.getDoubleBuffered(), chosenGLCaps.getDoubleBuffered());
112 } */
113
114 glad.addGLEventListener(demo);
115
116 final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener();
117 glad.addGLEventListener(snapshotGLEventListener);
118
119 glad.display(); // initial resize/display
120
121 // 1 - szStep = 2
122 Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(),
123 GLTestUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep, null));
124 snapshotGLEventListener.setMakeSnapshot();
125 glad.display();
126
127 // 2, 3 (resize + display)
128 szStep = 1;
129 glad.setSurfaceSize(widthStep*szStep, heightStep*szStep);
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 // 4, 5 (resize + display)
136 szStep = 4;
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 Thread.sleep(50);
144
145 glad.destroy();
146 System.out.println("Fin Drawable: "+glad);
147 }
148
149 // Might be reduced to !double-buff
150 @Test
151 public void testGL2OffScreenBitmapDblBuf() throws InterruptedException {
152 final GLCapabilities reqGLCaps = new GLCapabilities(GLProfile.getDefault());
153 reqGLCaps.setOnscreen(false);
154 reqGLCaps.setBitmap(true);
155 doTest(reqGLCaps, new Gears(1));
156 }
157
158 // Might be reduced to !MSAA
159 @Test
160 public void testGL2OffScreenBitmapDblBufMSAA() throws InterruptedException {
161 final GLCapabilities reqGLCaps = new GLCapabilities(GLProfile.getDefault());
162 reqGLCaps.setOnscreen(false);
163 reqGLCaps.setBitmap(true);
164 reqGLCaps.setSampleBuffers(true);
165 reqGLCaps.setNumSamples(4);
166 doTest(reqGLCaps, new Gears(1));
167 }
168
169 public static void main(final String args[]) throws IOException {
170 org.junit.runner.JUnitCore.main(TestGLAutoDrawableFactoryGLnBitmapCapsNEWT.class.getName());
171 }
172
173}
void setBitmap(final boolean enable)
Requesting offscreen bitmap mode.
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
Specifies a set of OpenGL capabilities.
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 GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
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.