JOGL v2.6.0-rc-20250706
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.opengl.GLCapabilities;
32import com.jogamp.opengl.GLProfile;
33
34public class CommandlineOptions {
38 public int sceneMSAASamples = 0;
39 /** Sample count for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link Region#VBAA_RENDERING_BIT} or {@link Region#MSAA_RENDERING_BIT} */
40 public int graphAASamples = 0;
41 /** Pass2 AA-quality rendering for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link #VBAA_RENDERING_BIT}. Defaults to {@link Region#DEFAULT_AA_QUALITY}. */
43 public boolean exclusiveContext = false;
44 public boolean wait_to_start = false;
45 public boolean keepRunning = false;
46 public boolean stayOpen = false;
47 public int swapInterval = -1; // auto
48 public float total_duration = 0f; // [s]
49
50 static {
51 GLProfile.initSingleton(); // ensure JOGL is completely initialized
52 }
53
54 /**
55 * Commandline options
56 * @param width viewport width in pixels
57 * @param height viewport height in pixels
58 * @param renderModes {@link Region#getRenderModes()}, if {@link Region#isGraphAA(int)} {@link #graphAASamples} is set to {@code 4}.
59 */
60 public CommandlineOptions(final int width, final int height, final int renderModes) {
61 this(width, height, renderModes, Region.DEFAULT_AA_QUALITY, Region.isGraphAA(renderModes) ? 4 : 0, 0);
62 }
63
64 /**
65 * Commandline options
66 * @param width viewport width in pixels
67 * @param height viewport height in pixels
68 * @param renderModes {@link Region#getRenderModes()}
69 * @param graphAAQuality if {@link Region#VBAA_RENDERING_BIT} this is the AA-quality shader selection, clipped via {@link Region#clipAAQuality(int)}
70 * @param graphAASamples if {@link Region#isGraphAA(int)} this is the graph sample count, clipped via {@link Region#clipAASampleCount(int)}
71 * @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.
72 */
73 public CommandlineOptions(final int width, final int height, final int renderModes, final int graphAAQuality, final int graphAASamples, final int sceneMSAASamples) {
74 this.surface_width = width;
75 this.surface_height = height;
76 this.renderModes = renderModes;
77 this.graphAASamples = Region.clipAASampleCount(graphAASamples);
78 this.graphAAQuality = Region.clipAAQuality(graphAAQuality);
79 this.sceneMSAASamples = !Region.isGraphAA(renderModes) ? sceneMSAASamples : 0;
80 }
81 public void parse(final String[] args) {
82 final int[] idx = { 0 };
83 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
84 parse(args, idx);
85 }
86 }
87 public boolean parse(final String[] args, final int[] idx) {
88 if( 0 > idx[0] || idx[0] >= args.length ) {
89 return false;
90 }
91 boolean res = true;
92 if (args[idx[0]].equals("-hhd")) {
93 surface_width = 1280;
94 surface_height = 720;
95 } else if (args[idx[0]].equals("-fhd")) {
96 surface_width = 1920;
97 surface_height = 1080;
98 } else if (args[idx[0]].equals("-w")) {
99 ++idx[0];
100 surface_width = MiscUtils.atoi(args[idx[0]], surface_width);
101 } else if (args[idx[0]].equals("-h")) {
102 ++idx[0];
104 } else if(args[idx[0]].equals("-es2")) {
106 } else if(args[idx[0]].equals("-es3")) {
108 } else if(args[idx[0]].equals("-gl2")) {
110 } else if(args[idx[0]].equals("-gl3bc")) {
112 } else if(args[idx[0]].equals("-gl3")) {
114 } else if(args[idx[0]].equals("-gl4")) {
116 } else if(args[idx[0]].equals("-gl4bc")) {
118 } else if(args[idx[0]].equals("-gldef")) {
119 glProfileName = null;
120 } else if(args[idx[0]].equals("-gnone")) {
122 graphAASamples = 0;
124 } else if(args[idx[0]].equals("-color")) {
126 } else if(args[idx[0]].equals("-no-color")) {
128 } else if(args[idx[0]].equals("-smsaa")) {
129 ++idx[0];
130 graphAASamples = 0;
131 sceneMSAASamples = MiscUtils.atoi(args[idx[0]], 4);
133 } else if(args[idx[0]].equals("-gmsaa")) {
134 ++idx[0];
136 graphAASamples = MiscUtils.atoi(args[idx[0]], 4);
139 } else if(args[idx[0]].equals("-gvbaa")) {
140 ++idx[0];
142 graphAASamples = MiscUtils.atoi(args[idx[0]], 4);
145 } else if(args[idx[0]].equals("-gaaq")) {
146 ++idx[0];
148 } else if(args[idx[0]].equals("-exclusiveContext")) {
149 exclusiveContext = true;
150 } else if(args[idx[0]].equals("-wait")) {
151 wait_to_start = true;
152 } else if (args[idx[0]].equals("-keep")) {
153 keepRunning = true;
154 stayOpen = true;
155 } else if (args[idx[0]].equals("-stay")) {
156 stayOpen = true;
157 } else if (args[idx[0]].equals("-swapInterval")) {
158 ++idx[0];
159 swapInterval = MiscUtils.atoi(args[idx[0]], swapInterval);
160 } else if (args[idx[0]].equals("-duration")) {
161 ++idx[0];
163 } else {
164 res = false;
165 }
166 return res;
167 }
170 }
172 final GLProfile glp = getGLProfile();
173 final GLCapabilities caps = new GLCapabilities(glp);
174 caps.setAlphaBits(4);
175 if( sceneMSAASamples > 0 ) {
176 caps.setSampleBuffers(true);
178 }
179 return caps;
180 }
181
182 @Override
183 public String toString() {
184 return "Options{surface[width "+surface_width+" x "+surface_height+"], glp "+glProfileName+
185 ", renderModes "+Region.getRenderModeString(renderModes)+", aa-q "+graphAAQuality+
186 ", gmsaa "+graphAASamples+", smsaa "+sceneMSAASamples+
187 ", exclusiveContext "+exclusiveContext+", wait "+wait_to_start+", keep "+keepRunning+", stay "+stayOpen+", swap-ival "+swapInterval+", dur "+total_duration+"s"+
188 "}";
189 }
190}
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
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.
CommandlineOptions(final int width, final int height, final int renderModes)
Commandline options.
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.
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