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 package com.jogamp.opengl.test.junit.graph;
29 
30 import java.io.IOException;
31 
32 import com.jogamp.opengl.GLAutoDrawable;
33 import com.jogamp.opengl.GLCapabilities;
34 import com.jogamp.opengl.GLCapabilitiesImmutable;
35 import com.jogamp.opengl.GLEventListener;
36 import com.jogamp.opengl.GLException;
37 import com.jogamp.opengl.GLProfile;
38 
39 import jogamp.common.os.PlatformPropsImpl;
40 
41 import org.junit.Assert;
42 import org.junit.Test;
43 import org.junit.FixMethodOrder;
44 import org.junit.runners.MethodSorters;
45 
46 import com.jogamp.common.os.Platform;
47 import com.jogamp.graph.curve.Region;
48 import com.jogamp.graph.curve.opengl.RenderState;
49 import com.jogamp.graph.geom.SVertex;
50 import com.jogamp.newt.opengl.GLWindow;
51 import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener01;
52 import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener02;
53 import com.jogamp.opengl.test.junit.graph.demos.GPURendererListenerBase01;
54 import com.jogamp.opengl.test.junit.util.UITestCase;
55 
56 
57 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
58 public class TestRegionRendererNEWT01 extends UITestCase {
59 
main(final String args[])60     public static void main(final String args[]) throws IOException {
61         final String tstname = TestRegionRendererNEWT01.class.getName();
62         org.junit.runner.JUnitCore.main(tstname);
63     }
64 
destroyWindow(final GLWindow window)65     static void destroyWindow(final GLWindow window) {
66         if(null!=window) {
67             window.destroy();
68         }
69     }
70 
createWindow(final String title, final GLCapabilitiesImmutable caps, final int width, final int height)71     static GLWindow createWindow(final String title, final GLCapabilitiesImmutable caps, final int width, final int height) {
72         Assert.assertNotNull(caps);
73 
74         final GLWindow window = GLWindow.create(caps);
75         window.setSize(width, height);
76         window.setPosition(10, 10);
77         window.setTitle(title);
78         Assert.assertNotNull(window);
79         window.setVisible(true);
80 
81         return window;
82     }
83 
84     // @Test
test00RegionRendererNONE01()85     public void test00RegionRendererNONE01() throws InterruptedException {
86         final GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
87         final GLCapabilities caps = new GLCapabilities(glp);
88     //    caps.setOnscreen(false);
89         caps.setAlphaBits(4);
90 
91         final GLWindow window = createWindow("shape-vbaa0-msaa0", caps, 800, 400);
92         final RenderState rs = RenderState.createRenderState(SVertex.factory());
93 
94         final GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, 0, 0, false, false);
95         demo01Listener.attachInputListenerTo(window);
96         window.addGLEventListener(demo01Listener);
97 
98         final RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01");
99         window.addGLEventListener(listener);
100 
101         listener.setTech(-20, 0, -300, 0f, 2);
102         window.display();
103 
104         listener.setTech(-20, 0, -150, 0f, 3);
105         window.display();
106 
107         listener.setTech(-20, 0,  -50, 0f, 4);
108         window.display();
109 
110         destroyWindow(window);
111     }
112 
113     // @Test
test01RegionRendererNONE02()114     public void test01RegionRendererNONE02() throws InterruptedException {
115         if(Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family) { // FIXME
116             // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
117             // FIXME: Also the GLSL code for VARIABLE_CURVE is not fit for mobile yet!
118             System.err.println("disabled on non desktop (x86) arch for now ..");
119             return;
120         }
121         final GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
122         final GLCapabilities caps = new GLCapabilities(glp);
123         caps.setAlphaBits(4);
124 
125         final GLWindow window = createWindow("shape-vbaa0-msaa0", caps, 800, 400);
126         final RenderState rs = RenderState.createRenderState(SVertex.factory());
127 
128         final GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, Region.VARWEIGHT_RENDERING_BIT, 0, false, false);
129         demo01Listener.attachInputListenerTo(window);
130         window.addGLEventListener(demo01Listener);
131 
132         final RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion02");
133         window.addGLEventListener(listener);
134 
135         listener.setTech(-20, 0, -300, 0f, 2);
136         window.display();
137 
138         listener.setTech(-20, 0, -150, 0f, 3);
139         window.display();
140 
141         listener.setTech(-20, 0,  -50, 0f, 4);
142         window.display();
143 
144         destroyWindow(window);
145     }
146 
147     @Test
test10RegionRendererMSAA01()148     public void test10RegionRendererMSAA01() throws InterruptedException {
149         final GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
150         final GLCapabilities caps = new GLCapabilities(glp);
151     //    caps.setOnscreen(false);
152         caps.setAlphaBits(4);
153         caps.setSampleBuffers(true);
154         caps.setNumSamples(4);
155 
156         final GLWindow window = createWindow("shape-vbaa0-msaa1", caps, 800, 400);
157         final RenderState rs = RenderState.createRenderState(SVertex.factory());
158 
159         final GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, 0, 0, false, false);
160         demo01Listener.attachInputListenerTo(window);
161         window.addGLEventListener(demo01Listener);
162 
163         final RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01");
164         window.addGLEventListener(listener);
165 
166         listener.setTech(-20, 00, -300, 0f, 2);
167         window.display();
168 
169         listener.setTech(-20, 00, -150, 0f, 3);
170         window.display();
171 
172         listener.setTech(-20, 00,  -50, 0f, 4);
173         window.display();
174 
175         destroyWindow(window);
176     }
177 
178     // @Test
test11RegionRendererMSAA02()179     public void test11RegionRendererMSAA02() throws InterruptedException {
180         if(Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family) { // FIXME
181             // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
182             // FIXME: Also the GLSL code for VARIABLE_CURVE is not fit for mobile yet!
183             System.err.println("disabled on non desktop (x86) arch for now ..");
184             return;
185         }
186         final GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
187         final GLCapabilities caps = new GLCapabilities(glp);
188         caps.setAlphaBits(4);
189         caps.setSampleBuffers(true);
190         caps.setNumSamples(4);
191 
192         final GLWindow window = createWindow("shape-vbaa0-msaa1", caps, 800, 400);
193         final RenderState rs = RenderState.createRenderState(SVertex.factory());
194 
195         final GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, Region.VARWEIGHT_RENDERING_BIT, 0, false, false);
196         demo01Listener.attachInputListenerTo(window);
197         window.addGLEventListener(demo01Listener);
198 
199         final RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion02");
200         window.addGLEventListener(listener);
201 
202         listener.setTech(-20, 00, -300, 0f, 2);
203         window.display();
204 
205         listener.setTech(-20, 00, -150, 0f, 3);
206         window.display();
207 
208         listener.setTech(-20, 00,  -50, 0f, 4);
209         window.display();
210 
211         destroyWindow(window);
212     }
213 
214     @Test
test20RegionRendererR2T01()215     public void test20RegionRendererR2T01() throws InterruptedException {
216         if(Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family) { // FIXME
217             // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
218             System.err.println("disabled on non desktop (x86) arch for now ..");
219             return;
220         }
221         final GLProfile glp = GLProfile.getGL2ES2();
222 
223         final GLCapabilities caps = new GLCapabilities(glp);
224         //caps.setOnscreen(false);
225         caps.setAlphaBits(4);
226 
227         final GLWindow window = createWindow("shape-vbaa1-msaa0", caps, 800,400);
228         final RenderState rs = RenderState.createRenderState(SVertex.factory());
229         final GPURegionGLListener02  demo02Listener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT, 4, false, false);
230         demo02Listener.attachInputListenerTo(window);
231         window.addGLEventListener(demo02Listener);
232 
233         final RegionGLListener listener = new RegionGLListener(demo02Listener, window.getTitle(), "GPURegionNewtDemo02");
234         window.addGLEventListener(listener);
235 
236         listener.setTech(-20, 00, -300, 0f, 2);
237         window.display();
238 
239         listener.setTech(-20, 00, -150, 0f, 3);
240         window.display();
241 
242         listener.setTech(-20, 00,  -50, 0f, 4);
243         window.display();
244 
245         destroyWindow(window);
246     }
247 
248     private static class RegionGLListener implements GLEventListener {
249         String winTitle;
250         String name;
251         GPURendererListenerBase01 impl;
252 
RegionGLListener(final GPURendererListenerBase01 impl, final String title, final String name)253         public RegionGLListener(final GPURendererListenerBase01 impl, final String title, final String name) {
254             this.impl = impl;
255             this.winTitle = title;
256             this.name = name;
257         }
258 
setTech(final float xt, final float yt, final int zt, final float angle, final int sampleCount)259         public void setTech(final float xt, final float yt, final int zt, final float angle, final int sampleCount){
260             impl.setMatrix(xt, yt, zt, angle, sampleCount);
261         }
262 
init(final GLAutoDrawable drawable)263         public void init(final GLAutoDrawable drawable) {
264             impl.init(drawable);
265         }
266 
display(final GLAutoDrawable drawable)267         public void display(final GLAutoDrawable drawable) {
268             impl.display(drawable);
269 
270             try {
271                 impl.printScreen(drawable, "./", winTitle, name, false);
272             } catch (final GLException e) {
273                 e.printStackTrace();
274             } catch (final IOException e) {
275                 e.printStackTrace();
276             }
277         }
278 
dispose(final GLAutoDrawable drawable)279         public void dispose(final GLAutoDrawable drawable) {
280             impl.dispose(drawable);
281 
282         }
283 
reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height)284         public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
285             impl.reshape(drawable, x, y, width, height);
286 
287         }
288     }
289 }
290