JOGL v2.6.0-rc-20250822
JOGL, High-Performance Graphics Binding for Java™ (public API).
CommandlineOptions.java
Go to the documentation of this file.
1/**
2 * Copyright 2023 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.demos.util;
29
30import com.jogamp.graph.curve.Region;
31import com.jogamp.math.FloatUtil;
32import com.jogamp.opengl.GLCapabilities;
33import com.jogamp.opengl.GLProfile;
34
35public class CommandlineOptions {
36 /**
37 * Default DPI threshold value to disable {@link Region#VBAA_RENDERING_BIT VBAA}: {@value} dpi
38 * @see #UISceneDemo20(float)
39 * @see #UISceneDemo20(float, boolean, boolean)
40 */
41 public static final float DefaultNoAADPIThreshold = 200f;
42
47 public int sceneMSAASamples = 0;
48 /** Sample count for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link Region#VBAA_RENDERING_BIT} or {@link Region#MSAA_RENDERING_BIT} */
49 public int graphAASamples = 0;
50 /** Pass2 AA-quality rendering for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link #VBAA_RENDERING_BIT}. Defaults to {@link Region#DEFAULT_AA_QUALITY}. */
52 public boolean exclusiveContext = false;
53 public boolean wait_to_start = false;
54 public boolean keepRunning = false;
55 public boolean stayOpen = false;
56 public int swapInterval = -1; // auto
57 public float total_duration = 0f; // [s]
58 /** Is true if values haven't changed throug parse() */
59 public boolean default_setting = true;
60 /** Is true if AA values haven't changed through parse() */
61 public boolean default_aa_setting = true;
62
63 static {
64 GLProfile.initSingleton(); // ensure JOGL is completely initialized
65 }
66
67 /**
68 * Commandline options defining default_setting and default_aa_setting
69 * @param width viewport width in pixels
70 * @param height viewport height in pixels
71 * @param renderModes {@link Region#getRenderModes()}, if {@link Region#isGraphAA(int)} {@link #graphAASamples} is set to {@code 4}.
72 */
73 public CommandlineOptions(final int width, final int height, final int renderModes) {
74 this(width, height, renderModes, Region.DEFAULT_AA_QUALITY, Region.isGraphAA(renderModes) ? 4 : 0, 0);
75 }
76
77 /**
78 * Commandline options defining default_setting and default_aa_setting
79 * @param width viewport width in pixels
80 * @param height viewport height in pixels
81 * @param renderModes {@link Region#getRenderModes()}
82 * @param graphAAQuality if {@link Region#VBAA_RENDERING_BIT} this is the AA-quality shader selection, clipped via {@link Region#clipAAQuality(int)}
83 * @param graphAASamples if {@link Region#isGraphAA(int)} this is the graph sample count, clipped via {@link Region#clipAASampleCount(int)}
84 * @param sceneMSAASamples if !{@link Region#isGraphAA(int)} and this value is > 0, it enables scene (fullscreen) MSAA mode by the GPU, usually 4 and 8 is good.
85 */
86 public CommandlineOptions(final int width, final int height, final int renderModes, final int graphAAQuality, final int graphAASamples, final int sceneMSAASamples) {
87 this.surface_width = width;
88 this.surface_height = height;
89 this.renderModes = renderModes;
90 this.graphAASamples = Region.clipAASampleCount(graphAASamples);
91 this.graphAAQuality = Region.clipAAQuality(graphAAQuality);
92 this.sceneMSAASamples = !Region.isGraphAA(renderModes) ? sceneMSAASamples : 0;
93 }
94 public void parse(final String[] args) {
95 final int[] idx = { 0 };
96 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
97 parse(args, idx);
98 }
99 }
100 public boolean parse(final String[] args, final int[] idx) {
101 if( 0 > idx[0] || idx[0] >= args.length ) {
102 return false;
103 }
104 boolean res = true;
105 if (args[idx[0]].equals("-hhd")) {
106 surface_width = 1280;
107 surface_height = 720;
108 } else if (args[idx[0]].equals("-fhd")) {
109 surface_width = 1920;
110 surface_height = 1080;
111 } else if (args[idx[0]].equals("-w")) {
112 ++idx[0];
113 surface_width = MiscUtils.atoi(args[idx[0]], surface_width);
114 } else if (args[idx[0]].equals("-h")) {
115 ++idx[0];
117 } else if(args[idx[0]].equals("-es2")) {
119 } else if(args[idx[0]].equals("-es3")) {
121 } else if(args[idx[0]].equals("-gl2")) {
123 } else if(args[idx[0]].equals("-gl3bc")) {
125 } else if(args[idx[0]].equals("-gl3")) {
127 } else if(args[idx[0]].equals("-gl4")) {
129 } else if(args[idx[0]].equals("-gl4bc")) {
131 } else if(args[idx[0]].equals("-gldef")) {
132 glProfileName = null;
133 } else if(args[idx[0]].equals("-gnone")) {
135 graphAASamples = 0;
137 default_aa_setting = false;
138 } else if(args[idx[0]].equals("-smsaa")) {
139 ++idx[0];
140 graphAASamples = 0;
141 sceneMSAASamples = MiscUtils.atoi(args[idx[0]], 4);
143 default_aa_setting = false;
144 } else if(args[idx[0]].equals("-gmsaa")) {
145 ++idx[0];
147 graphAASamples = MiscUtils.atoi(args[idx[0]], 4);
150 default_aa_setting = false;
151 } else if(args[idx[0]].equals("-gvbaa")) {
152 ++idx[0];
154 graphAASamples = MiscUtils.atoi(args[idx[0]], 4);
157 default_aa_setting = false;
158 } else if(args[idx[0]].equals("-color")) {
160 } else if(args[idx[0]].equals("-no-color")) {
162 } else if(args[idx[0]].equals("-gaaq")) {
163 ++idx[0];
165 } else if(args[idx[0]].equals("-exclusiveContext")) {
166 exclusiveContext = true;
167 } else if(args[idx[0]].equals("-wait")) {
168 wait_to_start = true;
169 } else if (args[idx[0]].equals("-keep")) {
170 keepRunning = true;
171 stayOpen = true;
172 } else if (args[idx[0]].equals("-stay")) {
173 stayOpen = true;
174 } else if (args[idx[0]].equals("-swapInterval")) {
175 ++idx[0];
176 swapInterval = MiscUtils.atoi(args[idx[0]], swapInterval);
177 } else if (args[idx[0]].equals("-duration")) {
178 ++idx[0];
180 } else {
181 res = false;
182 }
184 return res;
185 }
188 }
189 public void setGLProfile(final String name) {
190 glProfileName = name;
191 }
193 final GLProfile glp = getGLProfile();
194 final GLCapabilities caps = new GLCapabilities(glp);
195 caps.setAlphaBits(4);
196 if( sceneMSAASamples > 0 ) {
197 caps.setSampleBuffers(true);
199 }
200 return caps;
201 }
202
203 /**
204 * Fix AA rendering bit.
205 * @param force even fix renderModes if any Region.AA_RENDERING_MASK bits is already set
206 * @param dpiV display vertical DPI
207 * @return the previous renderModes
208 */
209 public int fixAARenderModeWithDPIThreshold(final boolean force, final float dpiV) {
210 final int o = renderModes;
212 if( dpiV >= noAADPIThreshold ) {
214 } else if( !Region.isGraphAA(renderModes) ) {
216 }
217 }
218 return o;
219 }
220 /**
221 * Fix default AA rendering bit, forced if having default_aa_setting is true
222 * @param dpiV display vertical DPI
223 * @return the previous renderModes
224 */
225 public int fixDefaultAARenderModeWithDPIThreshold(final float dpiV) {
227 }
228
229 @Override
230 public String toString() {
231 return "Options{surface[width "+surface_width+" x "+surface_height+"], glp "+glProfileName+
232 ", renderModes "+Region.getRenderModeString(renderModes)+", aa-q "+graphAAQuality+
233 ", gmsaa "+graphAASamples+", smsaa "+sceneMSAASamples+
234 ", exclusiveContext "+exclusiveContext+", wait "+wait_to_start+", keep "+keepRunning+", stay "+stayOpen+", swap-ival "+swapInterval+", dur "+total_duration+"s"+
235 "}";
236 }
237}
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 clipAAQuality(final int v)
Returns clipped AA quality value to [Region#MIN_AA_QUALITY..Region#MAX_AA_QUALITY].
Definition: Region.java:170
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 COLORCHANNEL_RENDERING_BIT
Rendering-Mode bit for Region to optionally enable a color-channel per vertex.
Definition: Region.java:148
static final int clipAASampleCount(final int v)
Returns clipped AA sample-count to [Region#MIN_AA_SAMPLE_COUNT..Region#MAX_AA_SAMPLE_COUNT].
Definition: Region.java:179
static String getRenderModeString(final int renderModes)
Returns a unique technical description string for renderModes as follows:
Definition: Region.java:251
static final int AA_RENDERING_MASK
2-pass rendering bit-mask including MSAA_RENDERING_BIT and VBAA_RENDERING_BIT.
Definition: Region.java:118
static boolean isGraphAA(final int renderModes)
Returns true if given renderModes has any of Region#AA_RENDERING_MASK set.
Definition: Region.java:208
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
Basic Float math utility functions.
Definition: FloatUtil.java:83
static boolean isZero(final float a, final float epsilon)
Returns true if value is zero, i.e.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
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 GLES3
The embedded OpenGL profile ES 3.x, with x >= 0.
Definition: GLProfile.java:588
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
static final String GL3
The desktop OpenGL core profile 3.x, with x >= 1.
Definition: GLProfile.java:576
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
Definition: GLProfile.java:585
static final String GL4bc
The desktop OpenGL compatibility profile 4.x, with x >= 0, ie GL2 plus GL4.
Definition: GLProfile.java:566
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL3bc
The desktop OpenGL compatibility profile 3.x, with x >= 1, ie GL2 plus GL3.
Definition: GLProfile.java:573
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
Definition: GLProfile.java:579
static void initSingleton()
Static initialization of JOGL.
Definition: GLProfile.java:204
static final String GL4
The desktop OpenGL core profile 4.x, with x >= 0.
Definition: GLProfile.java:569
CommandlineOptions(final int width, final int height, final int renderModes, final int graphAAQuality, final int graphAASamples, final int sceneMSAASamples)
Commandline options defining default_setting and default_aa_setting.
int fixDefaultAARenderModeWithDPIThreshold(final float dpiV)
Fix default AA rendering bit, forced if having default_aa_setting is true.
CommandlineOptions(final int width, final int height, final int renderModes)
Commandline options defining default_setting and default_aa_setting.
static final float DefaultNoAADPIThreshold
Default DPI threshold value to disable VBAA: {@value} dpi.
boolean default_setting
Is true if values haven't changed throug parse()
int graphAASamples
Sample count for Graph Region AA render-modes: Region#VBAA_RENDERING_BIT or Region#MSAA_RENDERING_BIT...
boolean parse(final String[] args, final int[] idx)
int graphAAQuality
Pass2 AA-quality rendering for Graph Region AA render-modes: VBAA_RENDERING_BIT.
int fixAARenderModeWithDPIThreshold(final boolean force, final float dpiV)
Fix AA rendering bit.
boolean default_aa_setting
Is true if AA values haven't changed through parse()
static int atoi(final String str, final int def)
Definition: MiscUtils.java:60
static float atof(final String str, final float def)
Definition: MiscUtils.java:78