JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
GLNameResolver.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
3 * Copyright (c) 2010 JogAmp Community. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * - Redistribution of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistribution in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of Sun Microsystems, Inc. or the names of
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * This software is provided "AS IS," without a warranty of any kind. ALL
21 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
22 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
23 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
24 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
25 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
27 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
28 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
29 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
30 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
31 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * You acknowledge that this software is not designed or intended for use
34 * in the design, construction, operation or maintenance of any nuclear
35 * facility.
36 *
37 */
38package com.jogamp.gluegen.runtime.opengl;
39
40/** Runtime utility identify and resolve extension names, which may be subsumed to core. */
41public class GLNameResolver {
42 //GL_XYZ : GL_XYZ, GL_XYZ_GL2, GL_XYZ_ARB, GL_XYZ_OES, GL_XYZ_OML
43 //GL_XYZ : GL_XYZ, GL_GL2_XYZ, GL_ARB_XYZ, GL_OES_XYZ, GL_OML_XYZ
44 //
45 // Pass-1 Unify ARB extensions with the same value
46 // Pass-2 Unify vendor extensions,
47 // if exist as an ARB extension with the same value.
48 // Pass-3 Emit
49
50 private static final String[] extensionsARB = { "ARB", "GL2", "OES", "KHR", "OML" };
51 private static final String[] extensionsVEN = { "3DFX",
52 "AMD",
53 "ANDROID",
54 "ANGLE",
55 "ARM",
56 "APPLE",
57 "ATI",
58 "EXT",
59 "FJ",
60 "HI",
61 "HP",
62 "IBM",
63 "IMG",
64 "INGR",
65 "INTEL",
66 "MESA",
67 "MESAX",
68 "NV",
69 "PGI",
70 "QCOM",
71 "SGI",
72 "SGIS",
73 "SGIX",
74 "SUN",
75 "VIV",
76 "WIN" };
77
78 public static final boolean isGLFunction(final String str) {
79 return str.startsWith("gl") || /* str.startsWith("glu") || str.startsWith("glX") || */
80 str.startsWith("egl") || str.startsWith("wgl") || str.startsWith("agl") ||
81 str.startsWith("cgl") ;
82 }
83
84 public static final boolean isGLEnumeration(final String str) {
85 return str.startsWith("GL_") || str.startsWith("GLU_") || str.startsWith("GLX_") ||
86 str.startsWith("EGL_") || str.startsWith("WGL_") || str.startsWith("AGL_") ||
87 str.startsWith("CGL_") ;
88 }
89
90 public static final int getExtensionIdx(final String[] extensions, final String str, final boolean isGLFunc) {
91 if(isGLFunc) {
92 for(int i = extensions.length - 1 ; i>=0 ; i--) {
93 if( str.endsWith(extensions[i]) ) {
94 return i;
95 }
96 }
97 } else {
98 for(int i = extensions.length - 1 ; i>=0 ; i--) {
99 if( str.endsWith("_"+extensions[i]) ) {
100 return i;
101 }
102 }
103 }
104 return -1;
105 }
106
107 public static final boolean isExtension(final String[] extensions, final String str, final boolean isGLFunc) {
108 return getExtensionIdx(extensions, str, isGLFunc)>=0;
109 }
110
111 public static final String getExtensionSuffix(final String str, final boolean isGLFunc) {
112 int idx = getExtensionIdx(extensionsARB, str, isGLFunc);
113 if(idx>=0) {
114 return extensionsARB[idx];
115 }
116 idx = getExtensionIdx(extensionsVEN, str, isGLFunc);
117 if(idx>=0) {
118 return extensionsVEN[idx];
119 }
120 return null;
121 }
122
123 public static final String normalize(final String[] extensions, String str, final boolean isGLFunc) {
124 boolean touched = false;
125 for(int i = extensions.length - 1 ; !touched && i>=0 ; i--) {
126 if(isGLFunc) {
127 if(str.endsWith(extensions[i])) {
128 // functions
129 str = str.substring(0, str.length()-extensions[i].length());
130 touched=true;
131 }
132 } else {
133 if(str.endsWith("_"+extensions[i])) {
134 // enums
135 str = str.substring(0, str.length()-1-extensions[i].length());
136 touched=true;
137 }
138 }
139 }
140 return str;
141 }
142 public static final String normalizeARB(final String str, final boolean isGLFunc) {
143 return normalize(extensionsARB, str, isGLFunc);
144 }
145 public static final boolean isExtensionARB(final String str, final boolean isGLFunc) {
146 return isExtension(extensionsARB, str, isGLFunc);
147 }
148 public static final String normalizeVEN(final String str, final boolean isGLFunc) {
149 return normalize(extensionsVEN, str, isGLFunc);
150 }
151 public static final boolean isExtensionVEN(final String str, final boolean isGLFunc) {
152 return isExtension(extensionsVEN, str, isGLFunc);
153 }
154 public static final String normalize(final String str, final boolean isGLFunc) {
155 if (isExtensionARB(str, isGLFunc)) {
156 return normalizeARB(str, isGLFunc);
157 }
158 if (isExtensionVEN(str, isGLFunc)) {
159 return normalizeVEN(str, isGLFunc);
160 }
161 return str;
162 }
163 public static final boolean isExtension(final String str, final boolean isGLFunc) {
164 return isExtension(extensionsARB, str, isGLFunc) ||
165 isExtension(extensionsVEN, str, isGLFunc);
166 }
167
168 public static final int getFuncNamePermutationNumber(final String name) {
169 if(isExtensionARB(name, true) || isExtensionVEN(name, true)) {
170 // no name permutation, if it's already a known extension
171 return 1;
172 }
173 return 1 + extensionsARB.length + extensionsVEN.length;
174 }
175
176 public static final String getFuncNamePermutation(final String name, int i) {
177 // identity
178 if(i==0) {
179 return name;
180 }
181 if(0>i || i>=(1+extensionsARB.length + extensionsVEN.length)) {
182 throw new RuntimeException("Index out of range [0.."+(1+extensionsARB.length+extensionsVEN.length-1)+"]: "+i);
183 }
184 // ARB
185 i-=1;
186 if(i<extensionsARB.length) {
187 return name+extensionsARB[i];
188 }
189 // VEN
190 i-=extensionsARB.length;
191 return name+extensionsVEN[i];
192 }
193}
194
Runtime utility identify and resolve extension names, which may be subsumed to core.
static final String normalize(final String str, final boolean isGLFunc)
static final boolean isExtensionVEN(final String str, final boolean isGLFunc)
static final String getExtensionSuffix(final String str, final boolean isGLFunc)
static final String getFuncNamePermutation(final String name, int i)
static final boolean isGLFunction(final String str)
static final int getExtensionIdx(final String[] extensions, final String str, final boolean isGLFunc)
static final String normalize(final String[] extensions, String str, final boolean isGLFunc)
static final String normalizeVEN(final String str, final boolean isGLFunc)
static final boolean isExtension(final String str, final boolean isGLFunc)
static final String normalizeARB(final String str, final boolean isGLFunc)
static final int getFuncNamePermutationNumber(final String name)
static final boolean isExtensionARB(final String str, final boolean isGLFunc)
static final boolean isGLEnumeration(final String str)
static final boolean isExtension(final String[] extensions, final String str, final boolean isGLFunc)