JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestOffscreen01GLPBufferNEWT.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.offscreen;
30
31import com.jogamp.newt.Display;
32import com.jogamp.newt.NewtFactory;
33import com.jogamp.newt.Screen;
34import com.jogamp.newt.Window;
35import com.jogamp.newt.opengl.GLWindow;
36import org.junit.AfterClass;
37import org.junit.Assert;
38import org.junit.Before;
39import org.junit.BeforeClass;
40import org.junit.Test;
41import org.junit.FixMethodOrder;
42import org.junit.runners.MethodSorters;
43
44import com.jogamp.opengl.*;
45
46import com.jogamp.opengl.test.junit.util.UITestCase;
47import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
48import java.io.IOException;
49
50@FixMethodOrder(MethodSorters.NAME_ASCENDING)
52 static GLProfile glpDefault;
53 static GLDrawableFactory glDrawableFactory;
54 static int width, height;
55 GLCapabilities capsDefault;
56
57 @BeforeClass
58 public static void initClass() {
59 glpDefault = GLProfile.getDefault();
60 Assert.assertNotNull(glpDefault);
61 glDrawableFactory = GLDrawableFactory.getFactory(glpDefault);
62 System.out.println("INFO: PBuffer supported: "+ glDrawableFactory.canCreateGLPbuffer(null, glpDefault));
63 width = 640;
64 height = 480;
65 }
66
67 @AfterClass
68 public static void releaseClass() {
69 }
70
71 @Before
72 public void init() {
73 capsDefault = new GLCapabilities(glpDefault);
74 Assert.assertNotNull(capsDefault);
75 capsDefault.setAlphaBits(1); // req. alpha channel
76 }
77
78 private void do01OffscreenWindowPBuffer(final GLCapabilities caps) {
79 final Display display = NewtFactory.createDisplay(null); // local display
80 Assert.assertNotNull(display);
81 final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
82 Assert.assertNotNull(screen);
83 final Window window = NewtFactory.createWindow(screen, caps);
84 Assert.assertNotNull(window);
85 window.setSize(width, height);
86 final GLWindow glWindow = GLWindow.create(window);
87 Assert.assertNotNull(glWindow);
88 glWindow.setVisible(true);
89
90 final GLEventListener demo = new RedSquareES2();
91 WindowUtilNEWT.setDemoFields(demo, window, glWindow, false);
92 glWindow.addGLEventListener(demo);
93
94 while ( glWindow.getTotalFPSFrames() < 2) {
95 glWindow.display();
96 }
97
98 if(null!=glWindow) {
99 glWindow.destroy();
100 }
101 if(null!=window) {
102 window.destroy();
103 }
104 if(null!=screen) {
105 screen.destroy();
106 }
107 if(null!=display) {
108 display.destroy();
109 }
110 }
111
112 @Test
114 if(!glDrawableFactory.canCreateGLPbuffer(null, capsDefault.getGLProfile())) {
115 System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
116 return;
117 }
118 final GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
119 do01OffscreenWindowPBuffer(caps2);
120 }
121
122 @Test
124 if(!glDrawableFactory.canCreateGLPbuffer(null, capsDefault.getGLProfile())) {
125 System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
126 return;
127 }
128 final GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
129 caps2.setStencilBits(8);
130 do01OffscreenWindowPBuffer(caps2);
131 }
132
133 @Test
135 if(!glDrawableFactory.canCreateGLPbuffer(null, capsDefault.getGLProfile())) {
136 System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
137 return;
138 }
139 final GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
140 caps2.setStencilBits(8);
141 caps2.setAlphaBits(8);
142 do01OffscreenWindowPBuffer(caps2);
143 }
144
145 @Test
147 if(!glDrawableFactory.canCreateGLPbuffer(null, capsDefault.getGLProfile())) {
148 System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
149 return;
150 }
151 final GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
152 caps2.setRedBits(5);
153 caps2.setGreenBits(5);
154 caps2.setBlueBits(5);
155 do01OffscreenWindowPBuffer(caps2);
156 }
157
158 @Test
160 if(!glDrawableFactory.canCreateGLPbuffer(null, capsDefault.getGLProfile())) {
161 System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
162 return;
163 }
164 final GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
165 final int winnum = 3;
166 int i;
167 final Window windows[] = new Window[winnum];
168 final GLWindow glWindows[] = new GLWindow[winnum];
169 final GLEventListener demos[] = new GLEventListener[winnum];
170
171 final Display display = NewtFactory.createDisplay(null); // local display
172 Assert.assertNotNull(display);
173 final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
174 Assert.assertNotNull(screen);
175
176 for(i=0; i<winnum; i++) {
177 System.out.println("Create Window "+i);
178 windows[i] = NewtFactory.createWindow(screen, caps2);
179 Assert.assertNotNull(windows[i]);
180 windows[i].setSize(width, height);
181 glWindows[i] = GLWindow.create(windows[i]);
182 Assert.assertNotNull(glWindows[i]);
183 glWindows[i].setVisible(true);
184
185 demos[i] = new RedSquareES2();
186 WindowUtilNEWT.setDemoFields(demos[i], windows[i], glWindows[i], false);
187 glWindows[i].addGLEventListener(demos[i]);
188 }
189
190 while ( glWindows[0].getTotalFPSFrames() < 2) {
191 for(i=0; i<winnum; i++) {
192 glWindows[i].display();
193 }
194 }
195
196 for(i=0; i<winnum; i++) {
197 if(null!=glWindows[i]) {
198 glWindows[i].destroy();
199 }
200 if(null!=windows[i]) {
201 windows[i].destroy();
202 }
203 }
204 if(null!=screen) {
205 screen.destroy();
206 }
207 if(null!=display) {
208 display.destroy();
209 }
210 }
211
212 @Test
214 if(!glDrawableFactory.canCreateGLPbuffer(null, capsDefault.getGLProfile())) {
215 System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
216 return;
217 }
218 final GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
219 final int winnum = 3;
220 int i;
221 final Display displays[] = new Display[winnum];
222 final Screen screens[] = new Screen[winnum];
223 final Window windows[] = new Window[winnum];
224 final GLWindow glWindows[] = new GLWindow[winnum];
225 final GLEventListener demos[] = new GLEventListener[winnum];
226
227 for(i=0; i<winnum; i++) {
228 System.out.println("Create Window "+i);
229 displays[i] = NewtFactory.createDisplay(null, false); // local display
230 Assert.assertNotNull(displays[i]);
231 screens[i] = NewtFactory.createScreen(displays[i], 0); // screen 0
232 Assert.assertNotNull(screens[i]);
233 windows[i] = NewtFactory.createWindow(screens[i], caps2);
234 Assert.assertNotNull(windows[i]);
235 windows[i].setSize(width, height);
236 glWindows[i] = GLWindow.create(windows[i]);
237 Assert.assertNotNull(glWindows[i]);
238 glWindows[i].setVisible(true);
239 demos[i] = new RedSquareES2();
240 WindowUtilNEWT.setDemoFields(demos[i], windows[i], glWindows[i], false);
241 glWindows[i].addGLEventListener(demos[i]);
242 }
243
244 while ( glWindows[0].getTotalFPSFrames() < 2) {
245 for(i=0; i<winnum; i++) {
246 glWindows[i].display();
247 }
248 }
249
250 for(i=0; i<winnum; i++) {
251 if(null!=glWindows[i]) {
252 glWindows[i].destroy();
253 }
254 if(null!=windows[i]) {
255 windows[i].destroy();
256 }
257 if(null!=screens[i]) {
258 screens[i].destroy();
259 }
260 if(null!=displays[i]) {
261 displays[i].destroy();
262 }
263 }
264 }
265
266 @Test
268 if(!glDrawableFactory.canCreateGLPbuffer(null, capsDefault.getGLProfile())) {
269 System.out.println("WARNING: PBuffer not supported on this platform - cannot test");
270 return;
271 }
272 final GLCapabilities caps2 = WindowUtilNEWT.fixCaps(capsDefault, false, true, false);
273
274 System.out.println("Create Window 1");
275 final Display display = NewtFactory.createDisplay(null); // local display
276 Assert.assertNotNull(display);
277 final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
278 Assert.assertNotNull(screen);
279 final Window window = NewtFactory.createWindow(screen, caps2);
280 Assert.assertNotNull(window);
281 window.setSize(width, height);
282 final GLWindow glWindow = GLWindow.create(window);
283 Assert.assertNotNull(glWindow);
284 glWindow.setVisible(true);
285
286 WindowUtilNEWT.run(getSimpleTestName("."), glWindow, new RedSquareES2(), null, null, null, null,
287 2 /* frames */, true /*snapshot*/, false /*debug*/);
288
289 if(null!=glWindow) {
290 glWindow.destroy();
291 }
292 if(null!=window) {
293 window.destroy();
294 }
295 if(null!=screen) {
296 screen.destroy();
297 }
298 if(null!=display) {
299 display.destroy();
300 }
301 }
302
303 public static void main(final String args[]) throws IOException {
304 final String tstname = TestOffscreen01GLPBufferNEWT.class.getName();
305 org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
306 tstname,
307 "filtertrace=true",
308 "haltOnError=false",
309 "haltOnFailure=false",
310 "showoutput=true",
311 "outputtoformatters=true",
312 "logfailedtests=true",
313 "logtestlistenerevents=true",
314 "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
315 "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
316 }
317
318}
void setRedBits(final int redBits)
Sets the number of bits requested for the color buffer's red component.
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.
abstract void destroy()
Manually trigger the destruction, incl.
static Display createDisplay(final String name)
Create a Display entity.
static Window createWindow(final CapabilitiesImmutable caps)
Create a top level Window entity on the default Display and default Screen.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
Definition: Screen.java:58
abstract void destroy()
Manually trigger the destruction, incl.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
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.
void setStencilBits(final int stencilBits)
Sets the number of bits requested for the stencil buffer.
final GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
abstract boolean canCreateGLPbuffer(AbstractGraphicsDevice device, GLProfile glp)
Returns true if it is possible to create an pbuffer surface.
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
static void setDemoFields(final GLEventListener demo, final Window window, final GLWindow glWindow, final boolean debug)
static void run(final String testName, final GLWindow windowOffScreen, final GLEventListener demo, final GLWindow windowOnScreenBlit, final WindowListener wl, final MouseListener ml, final SurfaceUpdatedListener ul, final int frames, final boolean snapshot, final boolean debug)
static GLCapabilities fixCaps(final GLCapabilities caps, final boolean onscreen, final boolean pbuffer, final boolean undecorated)
Specifying NEWT's Window functionality:
Definition: Window.java:115
void setSize(int width, int height)
Sets the size of the window's client area in window units, excluding decorations.
void destroy()
Destroys this window incl.releasing all related resources.
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.