JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLAutoDrawableFactoryGLProfileDeviceNEWT.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.AbstractGraphicsDevice;
34import com.jogamp.nativewindow.CapabilitiesImmutable;
35import com.jogamp.nativewindow.egl.EGLGraphicsDevice;
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLCapabilitiesImmutable;
38import com.jogamp.opengl.GLContext;
39import com.jogamp.opengl.GLDrawableFactory;
40import com.jogamp.opengl.GLEventListener;
41import com.jogamp.opengl.GLOffscreenAutoDrawable;
42import com.jogamp.opengl.GLProfile;
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.es2.GearsES2;
51import com.jogamp.opengl.test.junit.util.GLEventListenerCounter;
52import com.jogamp.opengl.test.junit.util.GLTestUtil;
53import com.jogamp.opengl.test.junit.util.UITestCase;
54
55/**
56 * Testing producing {@link GLContext} instances of different {@link GLProfile}s
57 * using different {@link AbstractGraphicsDevice}s.
58 */
59@FixMethodOrder(MethodSorters.NAME_ASCENDING)
61 static final int widthStep = 800/4;
62 static final int heightStep = 600/4;
63 volatile int szStep = 2;
64
65 static GLProfile getProfile(final AbstractGraphicsDevice device, final String profile) {
66 if( !GLProfile.isAvailable(device, profile) ) {
67 System.err.println("Profile "+profile+" n/a");
68 return null;
69 } else {
70 return GLProfile.get(device, profile);
71 }
72 }
73
74 void doTest(final boolean isEGL, final GLDrawableFactory factory, final AbstractGraphicsDevice device,
75 final GLCapabilitiesImmutable reqGLCaps, final GLEventListener demo) throws InterruptedException {
76 System.err.println("Factory: "+factory.getClass().getName());
77 System.err.println("Requested GL Caps: "+reqGLCaps);
78
79 //
80 // Create native OpenGL resources .. XGL/WGL/CGL ..
81 // equivalent to GLAutoDrawable methods: setVisible(true)
82 //
83 final GLOffscreenAutoDrawable glad = factory.createOffscreenAutoDrawable(device, reqGLCaps, null, widthStep*szStep, heightStep*szStep);
84
85 Assert.assertNotNull(glad);
86 Assert.assertTrue(glad.isRealized());
87
88 // Check caps of NativeWindow config w/o GL
89 final CapabilitiesImmutable chosenCaps = glad.getChosenGLCapabilities();
90 Assert.assertNotNull(chosenCaps);
91
92 glad.display(); // force native context creation
93
94 // Check caps of GLDrawable after realization
95 final GLCapabilitiesImmutable chosenGLCaps = glad.getChosenGLCapabilities();
96 Assert.assertNotNull(chosenGLCaps);
97 System.err.println("Choosen GL Caps: "+chosenGLCaps);
98
99 glad.addGLEventListener(demo);
101 glad.addGLEventListener(glelc);
102
103 glad.display(); // initial resize/display
104
105 // 1 - szStep = 2
106 Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(),
107 GLTestUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep, null));
108 glad.display();
109
110 // 2, 3 (resize + display)
111 szStep = 1;
112 glad.setSurfaceSize(widthStep*szStep, heightStep*szStep);
113 Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(),
114 GLTestUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep, null));
115 glad.display();
116
117 Thread.sleep(50);
118
120 glad.destroy();
121 System.err.println("Fin isEGL "+isEGL+", "+adevice);
122 System.err.println("Fin "+glelc);
123 Assert.assertTrue("init count: "+glelc, glelc.initCount > 0);
124 Assert.assertTrue("reshape count: "+glelc, glelc.reshapeCount > 0);
125 Assert.assertTrue("display count: "+glelc, glelc.displayCount > 0);
126 Assert.assertTrue("dispose count: "+glelc, glelc.disposeCount > 0);
127 Assert.assertEquals("EGL/Desktop not matching: isEGL "+isEGL+", "+adevice, isEGL, adevice instanceof EGLGraphicsDevice);
128 }
129
130 @Test
131 public void test00AvailableInfo() {
133 if(null != f) {
134 System.err.println(JoglVersion.getDefaultOpenGLInfo(f.getDefaultDevice(), null, true).toString());
135 }
137 if(null != f) {
138 System.err.println(JoglVersion.getDefaultOpenGLInfo(f.getDefaultDevice(), null, true).toString());
139 }
140 }
141
142 @Test
143 public void test01ES2OnMobile() throws InterruptedException {
144 final GLDrawableFactory factory = GLDrawableFactory.getFactory(true);
145 if( null == factory ) {
146 System.err.println("Mobile Factory n/a");
147 return;
148 }
149 final AbstractGraphicsDevice prodDevice = factory.getDefaultDevice();
150 final GLProfile glp = getProfile(prodDevice, GLProfile.GLES2);
151 if(null != glp) {
152 Assert.assertTrue("Not a GLES2 profile but "+glp, glp.isGLES2());
153 Assert.assertTrue("Not a GL2ES2 profile but "+glp, glp.isGL2ES2());
154 }
155 if(null == glp) {
156 return;
157 }
158 final GLCapabilities reqGLCaps = new GLCapabilities(glp);
159 reqGLCaps.setOnscreen(false);
160 final GearsES2 demo = new GearsES2(1);
161 demo.setVerbose(false);
162 doTest(true /* isEGL */, factory, prodDevice, reqGLCaps, demo);
163 }
164
165 @Test
166 public void test02GLOnMobile() throws InterruptedException {
167 final GLDrawableFactory factory = GLDrawableFactory.getFactory(true);
168 if( null == factory ) {
169 System.err.println("Mobile Factory n/a");
170 return;
171 }
172 final AbstractGraphicsDevice prodDevice = factory.getDefaultDevice();
173 final GLProfile glp = getProfile(prodDevice, GLProfile.GL2GL3);
174 if(null != glp) {
175 Assert.assertTrue("Not a GL2GL3 profile but "+glp, glp.isGL2GL3());
176 }
177 if(null == glp || !glp.isGL2ES2()) {
178 if( null != glp ) {
179 System.err.println("Not a GL2ES2 profile but "+glp);
180 }
181 return;
182 }
183 final GLCapabilities reqGLCaps = new GLCapabilities(glp);
184 reqGLCaps.setOnscreen(false);
185 final GearsES2 demo = new GearsES2(1);
186 demo.setVerbose(false);
187 doTest(true /* isEGL */, factory, prodDevice, reqGLCaps, demo);
188 }
189
190 @Test
191 public void test11ES2OnDesktop() throws InterruptedException {
192 final GLDrawableFactory deskFactory = GLDrawableFactory.getFactory(false);
193 if( null == deskFactory ) {
194 System.err.println("Desktop Factory n/a");
195 return;
196 }
197 final AbstractGraphicsDevice prodDevice = deskFactory.getDefaultDevice();
198 final GLProfile glp = getProfile(prodDevice, GLProfile.GLES2);
199 if(null != glp) {
200 Assert.assertTrue("Not a GLES2 profile but "+glp, glp.isGLES2());
201 Assert.assertTrue("Not a GL2ES2 profile but "+glp, glp.isGL2ES2());
202 }
203 if(null == glp) {
204 return;
205 }
206 final GLDrawableFactory prodFactory = GLDrawableFactory.getFactory(glp);
207 if( null == prodFactory ) {
208 System.err.println("Production Factory n/a");
209 return;
210 }
211 final GLCapabilities reqGLCaps = new GLCapabilities(glp);
212 reqGLCaps.setOnscreen(false);
213 final GearsES2 demo = new GearsES2(1);
214 demo.setVerbose(false);
215 doTest(true /* isEGL */, prodFactory, prodDevice, reqGLCaps, demo);
216 }
217
218 @Test
219 public void test12GLOnDesktop() throws InterruptedException {
220 final GLDrawableFactory factory = GLDrawableFactory.getFactory(false);
221 if( null == factory ) {
222 System.err.println("Desktop Factory n/a");
223 return;
224 }
225 final AbstractGraphicsDevice prodDevice = factory.getDefaultDevice();
226 final GLProfile glp = getProfile(prodDevice, GLProfile.GL2GL3);
227 if(null != glp) {
228 Assert.assertTrue("Not a GL2GL3 profile but "+glp, glp.isGL2GL3());
229 }
230 if(null == glp || !glp.isGL2ES2()) {
231 if( null != glp ) {
232 System.err.println("Not a GL2ES2 profile but "+glp);
233 }
234 return;
235 }
236 final GLCapabilities reqGLCaps = new GLCapabilities(glp);
237 reqGLCaps.setOnscreen(false);
238 final GearsES2 demo = new GearsES2(1);
239 demo.setVerbose(false);
240 doTest(false /* isEGL */, factory, prodDevice, reqGLCaps, demo);
241 }
242
243 public static void main(final String args[]) throws IOException {
244 org.junit.runner.JUnitCore.main(TestGLAutoDrawableFactoryGLProfileDeviceNEWT.class.getName());
245 }
246
247}
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
Encapsulates a graphics device on EGL platforms.
Specifies a set of OpenGL capabilities.
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...
abstract AbstractGraphicsDevice getDefaultDevice()
Retrieve the default device connection, unit ID and unique ID name.
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
final boolean isGLES2()
Indicates whether this profile is capable of GLES2.
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
Definition: GLProfile.java:585
final boolean isGL2ES2()
Indicates whether this profile is capable of GL2ES2.
static final String GL2GL3
The intersection of the desktop GL3 and GL2 profile.
Definition: GLProfile.java:597
final boolean isGL2GL3()
Indicates whether this profile is capable of GL2GL3.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static StringBuilder getDefaultOpenGLInfo(AbstractGraphicsDevice device, StringBuilder sb, final boolean withCapabilitiesInfo)
Testing producing GLContext instances of different GLProfiles using different AbstractGraphicsDevices...
static boolean waitForSize(final GLDrawable drawable, final int width, final int height, final Runnable waitAction)
Definition: GLTestUtil.java:72
AbstractGraphicsScreen getScreen()
Return the screen this graphics configuration is valid for.
A interface describing a graphics device in a toolkit-independent manner.
AbstractGraphicsDevice getDevice()
Return the device this graphics configuration is valid for.
Specifies an immutable set of capabilities that a window's rendering context must support,...
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.
Specifies an immutable set of OpenGL capabilities.
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.