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 
29 package com.jogamp.opengl.test.junit.jogl.offscreen;
30 
31 import com.jogamp.newt.Display;
32 import com.jogamp.newt.NewtFactory;
33 import com.jogamp.newt.Screen;
34 import com.jogamp.newt.Window;
35 import com.jogamp.newt.opengl.GLWindow;
36 import org.junit.AfterClass;
37 import org.junit.Assert;
38 import org.junit.Before;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41 import org.junit.FixMethodOrder;
42 import org.junit.runners.MethodSorters;
43 
44 import com.jogamp.opengl.*;
45 
46 import com.jogamp.opengl.test.junit.util.UITestCase;
47 import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
48 import java.io.IOException;
49 
50 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
51 public class TestOffscreen01GLPBufferNEWT extends UITestCase {
52     static GLProfile glpDefault;
53     static GLDrawableFactory glDrawableFactory;
54     static int width, height;
55     GLCapabilities capsDefault;
56 
57     @BeforeClass
initClass()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
releaseClass()68     public static void releaseClass() {
69     }
70 
71     @Before
init()72     public void init() {
73         capsDefault = new GLCapabilities(glpDefault);
74         Assert.assertNotNull(capsDefault);
75         capsDefault.setAlphaBits(1); // req. alpha channel
76     }
77 
do01OffscreenWindowPBuffer(final GLCapabilities caps)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
test01aOffscreenWindowPBuffer()113     public void test01aOffscreenWindowPBuffer() {
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
test01bOffscreenWindowPBufferStencil()123     public void test01bOffscreenWindowPBufferStencil() {
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
test01cOffscreenWindowPBufferStencilAlpha()134     public void test01cOffscreenWindowPBufferStencilAlpha() {
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
test01cOffscreenWindowPBuffer555()146     public void test01cOffscreenWindowPBuffer555() {
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
test02Offscreen3Windows1DisplayPBuffer()159     public void test02Offscreen3Windows1DisplayPBuffer() {
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
test03Offscreen3Windows3DisplaysPBuffer()213     public void test03Offscreen3Windows3DisplaysPBuffer() {
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
test04OffscreenSnapshotWithDemoPBuffer()267     public void test04OffscreenSnapshotWithDemoPBuffer() {
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 
main(final String args[])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 }
319