JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestRegionRendererNEWT01.java
Go to the documentation of this file.
1/**
2 * Copyright 2011-2024 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 */
28package com.jogamp.opengl.test.junit.graph;
29
30import java.io.IOException;
31
32import com.jogamp.opengl.GLAutoDrawable;
33import com.jogamp.opengl.GLCapabilities;
34import com.jogamp.opengl.GLCapabilitiesImmutable;
35import com.jogamp.opengl.GLEventListener;
36import com.jogamp.opengl.GLException;
37import com.jogamp.opengl.GLProfile;
38
39import jogamp.common.os.PlatformPropsImpl;
40
41import org.junit.Assert;
42import org.junit.Test;
43import org.junit.FixMethodOrder;
44import org.junit.runners.MethodSorters;
45
46import com.jogamp.common.os.Platform;
47import com.jogamp.graph.curve.Region;
48import com.jogamp.newt.opengl.GLWindow;
49import com.jogamp.opengl.test.junit.util.UITestCase;
50
51
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
54
55 public static void main(final String args[]) throws IOException {
56 final String tstname = TestRegionRendererNEWT01.class.getName();
57 org.junit.runner.JUnitCore.main(tstname);
58 }
59
60 static void destroyWindow(final GLWindow window) {
61 if(null!=window) {
62 window.destroy();
63 }
64 }
65
66 static GLWindow createWindow(final String title, final GLCapabilitiesImmutable caps, final int width, final int height) {
67 Assert.assertNotNull(caps);
68
69 final GLWindow window = GLWindow.create(caps);
70 window.setSize(width, height);
71 window.setPosition(10, 10);
72 window.setTitle(title);
73 Assert.assertNotNull(window);
74 window.setVisible(true);
75
76 return window;
77 }
78
79 // @Test
80 public void test00RegionRendererNONE01() throws InterruptedException {
82 final GLCapabilities caps = new GLCapabilities(glp);
83 // caps.setOnscreen(false);
84 caps.setAlphaBits(4);
85
86 final GLWindow window = createWindow("t00-shape-vbaa0-msaa0", caps, 800, 400);
87
88 final GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (0, Region.DEFAULT_AA_QUALITY, 0, false, false);
89 demo01Listener.attachInputListenerTo(window);
90 window.addGLEventListener(demo01Listener);
91
92 final RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01");
93 window.addGLEventListener(listener);
94
95 listener.setTech(-20, 0, -300, 0f, 2);
96 window.display();
97
98 listener.setTech(-20, 0, -150, 0f, 3);
99 window.display();
100
101 listener.setTech(-20, 0, -50, 0f, 4);
102 window.display();
103
104 destroyWindow(window);
105 }
106
107 // @Test
108 public void test01RegionRendererNONE02() throws InterruptedException {
109 if(Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family) { // FIXME
110 // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
111 // FIXME: Also the GLSL code for VARIABLE_CURVE is not fit for mobile yet!
112 System.err.println("disabled on non desktop (x86) arch for now ..");
113 return;
114 }
116 final GLCapabilities caps = new GLCapabilities(glp);
117 caps.setAlphaBits(4);
118
119 final GLWindow window = createWindow("t01-shape-vbaa0-msaa0", caps, 800, 400);
120
122 demo01Listener.attachInputListenerTo(window);
123 window.addGLEventListener(demo01Listener);
124
125 final RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion02");
126 window.addGLEventListener(listener);
127
128 listener.setTech(-20, 0, -300, 0f, 2);
129 window.display();
130
131 listener.setTech(-20, 0, -150, 0f, 3);
132 window.display();
133
134 listener.setTech(-20, 0, -50, 0f, 4);
135 window.display();
136
137 destroyWindow(window);
138 }
139
140 @Test
141 public void test10RegionRendererMSAA01() throws InterruptedException {
143 final GLCapabilities caps = new GLCapabilities(glp);
144 // caps.setOnscreen(false);
145 caps.setAlphaBits(4);
146 caps.setSampleBuffers(true);
147 caps.setNumSamples(4);
148
149 final GLWindow window = createWindow("t10-shape-vbaa0-msaa1", caps, 800, 400);
150
151 final GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (0, Region.DEFAULT_AA_QUALITY, 0, false, false);
152 demo01Listener.attachInputListenerTo(window);
153 window.addGLEventListener(demo01Listener);
154
155 final RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01");
156 window.addGLEventListener(listener);
157
158 listener.setTech(-20, 00, -300, 0f, 2);
159 window.display();
160
161 listener.setTech(-20, 00, -150, 0f, 3);
162 window.display();
163
164 listener.setTech(-20, 00, -50, 0f, 4);
165 window.display();
166
167 destroyWindow(window);
168 }
169
170 // @Test
171 public void test11RegionRendererMSAA02() throws InterruptedException {
172 if(Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family) { // FIXME
173 // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
174 // FIXME: Also the GLSL code for VARIABLE_CURVE is not fit for mobile yet!
175 System.err.println("disabled on non desktop (x86) arch for now ..");
176 return;
177 }
179 final GLCapabilities caps = new GLCapabilities(glp);
180 caps.setAlphaBits(4);
181 caps.setSampleBuffers(true);
182 caps.setNumSamples(4);
183
184 final GLWindow window = createWindow("t11-shape-vbaa0-msaa1", caps, 800, 400);
185
187 demo01Listener.attachInputListenerTo(window);
188 window.addGLEventListener(demo01Listener);
189
190 final RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion02");
191 window.addGLEventListener(listener);
192
193 listener.setTech(-20, 00, -300, 0f, 2);
194 window.display();
195
196 listener.setTech(-20, 00, -150, 0f, 3);
197 window.display();
198
199 listener.setTech(-20, 00, -50, 0f, 4);
200 window.display();
201
202 destroyWindow(window);
203 }
204
205 @Test
206 public void test20RegionRendererR2T01() throws InterruptedException {
207 if(Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family) { // FIXME
208 // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
209 System.err.println("disabled on non desktop (x86) arch for now ..");
210 return;
211 }
212 final GLProfile glp = GLProfile.getGL2ES2();
213
214 final GLCapabilities caps = new GLCapabilities(glp);
215 //caps.setOnscreen(false);
216 caps.setAlphaBits(4);
217
218 final GLWindow window = createWindow("t20-shape-vbaa1-msaa0", caps, 800,400);
220 demo02Listener.attachInputListenerTo(window);
221 window.addGLEventListener(demo02Listener);
222
223 final RegionGLListener listener = new RegionGLListener(demo02Listener, window.getTitle(), "GPURegionNewtDemo02");
224 window.addGLEventListener(listener);
225
226 listener.setTech(-20, 00, -300, 0f, 2);
227 window.display();
228
229 listener.setTech(-20, 00, -150, 0f, 3);
230 window.display();
231
232 listener.setTech(-20, 00, -50, 0f, 4);
233 window.display();
234
235 destroyWindow(window);
236 }
237
238 private void test30RegionRendererShapesImpl(final GLCapabilities caps, final int shape_ctor_mode) throws InterruptedException {
239 final GLWindow window = createWindow("t30-shape0"+shape_ctor_mode+"-vbaa0-msaa1", caps, 800, 400);
240
241 final GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (shape_ctor_mode, 0, Region.DEFAULT_AA_QUALITY, 0, false, false);
242 demo01Listener.attachInputListenerTo(window);
243 window.addGLEventListener(demo01Listener);
244
245 final RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01");
246 window.addGLEventListener(listener);
247
248 // listener.setTech(-20, 00, -300, 0f, 2);
249 listener.setTech(-20, 00, -50, 0f, 4);
250 window.display();
251
252 destroyWindow(window);
253 }
254
255 @Test
256 public void test30RegionRendererShapes() throws InterruptedException {
258 final GLCapabilities caps = new GLCapabilities(glp);
259 // caps.setOnscreen(false);
260 caps.setAlphaBits(4);
261 caps.setSampleBuffers(true);
262 caps.setNumSamples(4);
263
264 test30RegionRendererShapesImpl(caps, 1);
265 test30RegionRendererShapesImpl(caps, 2);
266 test30RegionRendererShapesImpl(caps, 3);
267 test30RegionRendererShapesImpl(caps, 4);
268 }
269
270 private static class RegionGLListener implements GLEventListener {
271 String winTitle;
272 String name;
274
275 public RegionGLListener(final GPURendererListenerBase01 impl, final String title, final String name) {
276 this.impl = impl;
277 this.winTitle = title;
278 this.name = name;
279 }
280
281 public void setTech(final float xt, final float yt, final int zt, final float angle, final int sampleCount){
282 impl.setMatrix(xt, yt, zt, angle);
283 impl.getRenderer().setSampleCount(sampleCount);
284 }
285
286 @Override
287 public void init(final GLAutoDrawable drawable) {
288 impl.init(drawable);
289 }
290
291 @Override
292 public void display(final GLAutoDrawable drawable) {
293 impl.display(drawable);
294
295 try {
296 impl.printScreen(drawable, "./", winTitle, name, false);
297 } catch (final GLException e) {
298 e.printStackTrace();
299 } catch (final IOException e) {
300 e.printStackTrace();
301 }
302 }
303
304 @Override
305 public void dispose(final GLAutoDrawable drawable) {
306 impl.dispose(drawable);
307
308 }
309
310 @Override
311 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
312 impl.reshape(drawable, x, y, width, height);
313
314 }
315 }
316}
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
Definition: Region.java:62
static final int VARWEIGHT_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:131
static final int DEFAULT_AA_QUALITY
Default pass2 AA-quality rendering {@value} for Graph Region AA render-modes: VBAA_RENDERING_BIT.
Definition: Region.java:168
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:115
final int setSampleCount(final int v)
Sets pass2 AA sample count clipped to the range [Region#MIN_AA_SAMPLE_COUNT..Region#MAX_AA_SAMPLE_COU...
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
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 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.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
Demonstrate the rendering of multiple outlines into one region/OutlineShape These Outlines are not ne...
Demonstrate the rendering of multiple OutlineShapes into one region.
void setMatrix(final float xtrans, final float ytrans, final float zTran, final float angle)
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha)
void attachInputListenerTo(final GLWindow window)
Attach the input listener to the window.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void display(GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.