JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTextRendererNEWT21.java
Go to the documentation of this file.
1/**
2 * Copyright 2023-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.File;
31import java.io.IOException;
32
33import com.jogamp.opengl.GLCapabilities;
34import com.jogamp.opengl.GLCapabilitiesImmutable;
35import com.jogamp.opengl.GLException;
36import com.jogamp.opengl.GLProfile;
37
38import jogamp.common.os.PlatformPropsImpl;
39
40import org.junit.Assert;
41import org.junit.BeforeClass;
42import org.junit.Test;
43import org.junit.FixMethodOrder;
44import org.junit.runners.MethodSorters;
45
46import com.jogamp.common.os.Platform;
47import com.jogamp.common.util.VersionUtil;
48import com.jogamp.graph.curve.Region;
49import com.jogamp.graph.font.Font;
50import com.jogamp.graph.font.FontFactory;
51import com.jogamp.newt.opengl.GLWindow;
52import com.jogamp.opengl.test.junit.util.UITestCase;
53import com.jogamp.opengl.util.caps.NonFSAAGLCapsChooser;
54
55
56/**
57 * TestTextRendererNEWT21 Variant
58 * - Using FontViewListener01, a full Glyph Grid using GraphUI
59 * - Renders multiple demo text with multiple fonts
60 * - Used for validation
61 */
62@FixMethodOrder(MethodSorters.NAME_ASCENDING)
63public class TestTextRendererNEWT21 extends UITestCase {
64 static final boolean DEBUG = false;
65 static final boolean TRACE = false;
66 static long duration = 100; // ms
67 static int win_width = 1280;
68 static int win_height = 720;
69 static int[] aaQualitySet = new int[] { 0, 1 };
70 static int[] sampleSet = new int[] { 4 };
71 static Font[] fontSet = new Font[] { };
72 static boolean onlyOne = false;
73
74 @BeforeClass
75 public static void setup() {
76 try {
77 fontSet = FontSet01.getSet00();
78 } catch (final IOException e) {
79 e.printStackTrace();
80 }
81 }
82
83 static int atoi(final String a) {
84 try {
85 return Integer.parseInt(a);
86 } catch (final Exception ex) { throw new RuntimeException(ex); }
87 }
88
89 public static void main(final String args[]) throws IOException {
90 for(int i=0; i<args.length; i++) {
91 if(args[i].equals("-time")) {
92 i++;
93 duration = atoi(args[i]);
94 } else if(args[i].equals("-one")) {
95 onlyOne = true;
96 } else if(args[i].equals("-width")) {
97 i++;
98 win_width = atoi(args[i]);
99 } else if(args[i].equals("-height")) {
100 i++;
101 win_height = atoi(args[i]);
102 } else if(args[i].equals("-font")) {
103 i++;
104 fontSet = new Font[] { FontFactory.get(new File(args[i])) };
105 } else if(args[i].equals("-samples")) {
106 i++;
107 sampleSet = new int[] { atoi(args[i]) };
108 } else if(args[i].equals("-aaq")) {
109 i++;
110 aaQualitySet = new int[] { atoi(args[i]) };
111 }
112 }
113 final String tstname = TestTextRendererNEWT21.class.getName();
114 org.junit.runner.JUnitCore.main(tstname);
115 }
116
117 static void sleep() {
118 try {
119 System.err.println("** new frame ** (sleep: "+duration+"ms)");
120 Thread.sleep(duration);
121 } catch (final InterruptedException ie) {}
122 }
123
124 static void destroyWindow(final GLWindow window) {
125 if(null!=window) {
126 window.destroy();
127 }
128 }
129
130 static GLWindow createWindow(final String title, final GLCapabilitiesImmutable caps, final int width, final int height) {
131 Assert.assertNotNull(caps);
132
133 final GLWindow window = GLWindow.create(caps);
134 if( !caps.getSampleBuffers() ) {
135 // Make sure to not have FSAA if not requested
136 // TODO: Implement in default chooser?
137 window.setCapabilitiesChooser(new NonFSAAGLCapsChooser(true));
138 }
139 window.setSize(width, height);
140 window.setPosition(10, 10);
141 window.setTitle(title);
142 Assert.assertNotNull(window);
143 window.setVisible(true);
144
145 return window;
146 }
147
148 class TestAction implements Runnable {
149 private final GLWindow window;
150 private final int renderModes;
151 private final int graphAAQuality;
152 private final int graphSampleCount;
153 private final Font font;
154 private boolean keepAlive = false;
155
156 public TestAction(final GLWindow window, final int renderModes, final int graphAAQuality, final int graphSampleCount, final Font font) {
157 this.window = window;
158 this.renderModes = renderModes;
159 this.graphAAQuality = graphAAQuality;
160 this.graphSampleCount = graphSampleCount;
161 this.font = font;
162 }
163 public void setKeepAlive(final boolean v) { keepAlive = v; }
164
165 @Override
166 public void run() {
167 final int fsaaSampleCount = window.getChosenGLCapabilities().getNumSamples();
168 if( null != font ) {
169 System.err.printf("Test Run: %s, %s%n",
170 Region.getRenderModeString(renderModes, 0, graphSampleCount, fsaaSampleCount),
171 font.getFullFamilyName());
172 final FontViewListener01 glel = new FontViewListener01(renderModes, graphAAQuality, graphSampleCount, font, '!' /* startCharSymbol */);
173 glel.attachInputListenerTo(window);
174 window.addGLEventListener(glel);
175 window.display();
176 glel.printScreenOnGLThread(window, "./", window.getTitle(), "", false);
177 sleep();
178 if( !keepAlive ) {
179 window.disposeGLEventListener(glel, true);
180 }
181 } else {
182 System.err.printf("Test Skipped: %s, font not available%n",
183 Region.getRenderModeString(renderModes, 0, graphSampleCount, fsaaSampleCount));
184 }
185 }
186 }
187
188 @Test
189 public void test00() throws InterruptedException, GLException, IOException {
190 if( !onlyOne ) {
191 System.err.println("disabled !onlyOne");
192 return;
193 }
194 final GLProfile glp = GLProfile.getGL2ES2();
195
196 final GLCapabilities caps = new GLCapabilities(glp);
197 caps.setAlphaBits(4);
198 System.err.println("Requested: "+caps);
199
200 final GLWindow window = createWindow("TTRN21", caps, win_width, win_height);
201 window.display();
202 System.err.println(VersionUtil.getPlatformInfo());
203 // System.err.println(JoglVersion.getAllAvailableCapabilitiesInfo(window.getScreen().getDisplay().getGraphicsDevice(), null).toString());
204 System.err.println("Chosen: "+window.getChosenGLCapabilities());
205
206 final TestAction ta = new TestAction(window, Region.VBAA_RENDERING_BIT, aaQualitySet[0], sampleSet[0], fontSet[0]);
207 ta.setKeepAlive(true);
208 ta.run();
209 }
210
211 @Test
212 public void test00TextRendererVBAA01() throws InterruptedException, GLException, IOException {
213 if( onlyOne || Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family ) { // FIXME
214 // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
215 System.err.println("disabled on non desktop (x86) arch for now ..");
216 return;
217 }
218 final GLProfile glp = GLProfile.getGL2ES2();
219
220 final GLCapabilities caps = new GLCapabilities(glp);
221 caps.setAlphaBits(4);
222 System.err.println("Requested: "+caps);
223
224 final GLWindow window = createWindow("TTRN21", caps, win_width, win_height);
225 window.display();
226 System.err.println(VersionUtil.getPlatformInfo());
227 // System.err.println(JoglVersion.getAllAvailableCapabilitiesInfo(window.getScreen().getDisplay().getGraphicsDevice(), null).toString());
228 System.err.println("Chosen: "+window.getChosenGLCapabilities());
229
230 for(final Font f : fontSet) {
231 for(final int aaQuality : aaQualitySet ) {
232 for(final int sampleCount : sampleSet ) {
233 new TestAction(window, Region.VBAA_RENDERING_BIT, aaQuality, sampleCount, f).run();
234 }
235 }
236 }
237 destroyWindow(window);
238 }
239
240 @Test
241 public void test10TextRendererMSAA01() throws InterruptedException, GLException, IOException {
242 if( onlyOne || Platform.CPUFamily.X86 != PlatformPropsImpl.CPU_ARCH.family ) { // FIXME
243 // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
244 System.err.println("disabled on non desktop (x86) arch for now ..");
245 return;
246 }
247 final GLProfile glp = GLProfile.getGL2ES2();
248
249 final GLCapabilities caps = new GLCapabilities(glp);
250 caps.setAlphaBits(4);
251 System.err.println("Requested: "+caps);
252
253 final GLWindow window = createWindow("TTRN21", caps, win_width, win_height);
254 window.display();
255 System.err.println("Chosen: "+window.getChosenGLCapabilities());
256
257 for(final Font f : fontSet) {
258 for(final int sampleCount : sampleSet ) {
259 new TestAction(window, Region.MSAA_RENDERING_BIT, -1, sampleCount, f).run();
260 }
261 }
262 destroyWindow(window);
263 }
264
265 @Test
266 public void test20TextRendererFSAA01() throws InterruptedException, GLException, IOException {
267 if( onlyOne ) {
268 return;
269 }
271 final GLCapabilities caps = new GLCapabilities(glp);
272 caps.setAlphaBits(4);
273 caps.setSampleBuffers(true);
274 caps.setNumSamples(4);
275 System.err.println("Requested: "+caps);
276
277 final GLWindow window = createWindow("TTRN21", caps, win_width, win_height);
278 window.display();
279 System.err.println("Chosen: "+window.getChosenGLCapabilities());
280
281 for(final Font f : fontSet) {
282 new TestAction(window, Region.NORM_RENDERING_BIT, -1, 0, f).run();
283 }
284 destroyWindow(window);
285 }
286
287 @Test
288 public void test30TextRendererNoSampling() throws InterruptedException, GLException, IOException {
289 if( onlyOne ) {
290 return;
291 }
293 final GLCapabilities caps = new GLCapabilities(glp);
294 caps.setAlphaBits(4);
295 System.err.println("Requested: "+caps);
296
297 final GLWindow window = createWindow("TTRN21", caps, win_width, win_height);
298 window.display();
299 System.err.println("Chosen: "+window.getChosenGLCapabilities());
300
301 for(final Font f : fontSet) {
302 new TestAction(window, Region.NORM_RENDERING_BIT, -1, 0, f).run();
303 }
304 destroyWindow(window);
305 }
306}
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
Definition: Region.java:62
static final int MSAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:95
static final int NORM_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:79
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:115
The optional property jogamp.graph.font.ctor allows user to specify the FontConstructor implementatio...
static final FontSet get(final int font)
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
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.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
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
Interface wrapper for font implementation.
Definition: Font.java:60
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...