aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-05-31 06:34:13 +0200
committerSven Gothel <[email protected]>2013-05-31 06:34:13 +0200
commit81afec4e963ac4372dc2b604d6f91237b81ee6f2 (patch)
tree5dd821981648fe32c5f94d33b5b48aa94b01de86 /src/jogl/classes/jogamp/opengl
parentf650e6b37407aaa3ef6c16e7daf6423103b94ddf (diff)
GLVersionNumber: Fix vendor version parser; Adapt to GlueGen commit 959d6d83ec26152343d538287c02eeebf0dcf238
Adapt to GlueGen commit 959d6d83ec26152343d538287c02eeebf0dcf238: - Use only RegExp and cache default (no wrapped whitespace tokenizer) - String match: Store end-of-match and flag defined components. - Remove manual parsing, utilize VersionNumber - No need to look further for 'updated' GL version, (probably the vendor version), since we utilize the ARB version number as set at creation. Fix vendor version parser: - Cut off GL version part of versionString (fixes case where GL version was interpreted as vendor version) - Loop through remaining string until a valid version number w/ major.minor has been found
Diffstat (limited to 'src/jogl/classes/jogamp/opengl')
-rw-r--r--src/jogl/classes/jogamp/opengl/GLContextImpl.java2
-rw-r--r--src/jogl/classes/jogamp/opengl/GLVersionNumber.java137
2 files changed, 53 insertions, 86 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
index 314db292d..e7eef61e7 100644
--- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
@@ -1050,7 +1050,7 @@ public abstract class GLContextImpl extends GLContext {
if( hasGLSL() ) { // >= ES2 || GL2.0
final String glslVersion = isGLES() ? null : gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION) ; // Use static GLSL version for ES to be safe!
if( null != glslVersion ) {
- ctxGLSLVersion = new VersionNumber(glslVersion, ".");
+ ctxGLSLVersion = new VersionNumber(glslVersion);
if( ctxGLSLVersion.getMajor() < 1 ) {
ctxGLSLVersion = VersionNumber.zeroVersion; // failed ..
}
diff --git a/src/jogl/classes/jogamp/opengl/GLVersionNumber.java b/src/jogl/classes/jogamp/opengl/GLVersionNumber.java
index 990698667..a32fdfa77 100644
--- a/src/jogl/classes/jogamp/opengl/GLVersionNumber.java
+++ b/src/jogl/classes/jogamp/opengl/GLVersionNumber.java
@@ -28,98 +28,62 @@
package jogamp.opengl;
-import java.util.StringTokenizer;
-
-import javax.media.opengl.GLContext;
-
+import com.jogamp.common.util.VersionNumber;
import com.jogamp.common.util.VersionNumberString;
/**
* A class for storing and comparing OpenGL version numbers.
* This only works for desktop OpenGL at the moment.
*/
-class GLVersionNumber extends VersionNumberString {
+public class GLVersionNumber extends VersionNumberString {
private final boolean valid;
- private GLVersionNumber(int[] val, String versionString, boolean valid) {
- super(val[0], val[1], val[2], versionString);
+ private GLVersionNumber(int[] val, int strEnd, short state, String versionString, boolean valid) {
+ super(val[0], val[1], val[2], strEnd, state, versionString);
this.valid = valid;
}
- public static GLVersionNumber create(String versionString) {
+ private static java.util.regex.Pattern getUnderscorePattern() {
+ if( null == _Pattern ) { // volatile dbl-checked-locking OK
+ synchronized( VersionNumber.class ) {
+ if( null == _Pattern ) {
+ _Pattern = getVersionNumberPattern("_");
+ }
+ }
+ }
+ return _Pattern;
+ }
+ private static volatile java.util.regex.Pattern _Pattern = null;
+
+ public static final GLVersionNumber create(String versionString) {
int[] val = new int[] { 0, 0, 0 };
- try {
- if (versionString.startsWith("GL_VERSION_")) {
- StringTokenizer tok = new StringTokenizer(versionString, "_");
- tok.nextToken(); // GL_
- tok.nextToken(); // VERSION_
- if (!tok.hasMoreTokens()) {
- val[0] = 0;
+ int strEnd = 0;
+ short state = 0;
+ if (versionString != null && versionString.length() > 0) {
+ try {
+ final java.util.regex.Pattern versionPattern;
+ if (versionString.startsWith("GL_VERSION_")) {
+ versionPattern = getUnderscorePattern();
} else {
- val[0] = Integer.valueOf(tok.nextToken()).intValue();
- if (!tok.hasMoreTokens()) {
- val[1] = 0;
- } else {
- val[1] = Integer.valueOf(tok.nextToken()).intValue();
- if (!tok.hasMoreTokens()) {
- val[2] = 0;
- } else {
- val[2] = Integer.valueOf(tok.nextToken()).intValue();
- }
- }
+ versionPattern = VersionNumberString.getDefaultVersionNumberPattern();
}
- } else {
- int radix = 10;
- if (versionString.length() > 2) {
- if (Character.isDigit(versionString.charAt(0)) && versionString.charAt(1) == '.' && Character.isDigit(versionString.charAt(2))) {
- val[0] = Character.digit(versionString.charAt(0), radix);
- val[1] = Character.digit(versionString.charAt(2), radix);
- // See if there's version-specific information which might
- // imply a more recent OpenGL version
- StringTokenizer tok = new StringTokenizer(versionString, " ");
- if (tok.hasMoreTokens()) {
- tok.nextToken();
- if (tok.hasMoreTokens()) {
- String token = tok.nextToken();
- int i = 0;
- while (i < token.length() && !Character.isDigit(token.charAt(i))) {
- i++;
- }
- if (i < token.length() - 2 && Character.isDigit(token.charAt(i)) && token.charAt(i + 1) == '.' && Character.isDigit(token.charAt(i + 2))) {
- int altMajor = Character.digit(token.charAt(i), radix);
- int altMinor = Character.digit(token.charAt(i + 2), radix);
- // Avoid possibly confusing situations by putting some
- // constraints on the upgrades we do to the major and
- // minor versions
- if ( (altMajor == val[0] && altMinor > val[1]) || altMajor == val[0] + 1 ) {
- if( GLContext.isValidGLVersion(altMajor, altMinor) ) {
- val[0] = altMajor;
- val[1] = altMinor;
- }
- }
- }
- }
- }
- }
+ final VersionNumberString version = new VersionNumberString(versionString, versionPattern);
+ if( version.hasMajor() && version.hasMinor() ) { // Requires at least a defined major and minor version component!
+ val[0] = version.getMajor();
+ val[1] = version.getMinor();
+ strEnd = version.endOfStringMatch();
+ state = (short) ( ( version.hasMajor() ? VersionNumber.HAS_MAJOR : (short)0 ) |
+ ( version.hasMinor() ? VersionNumber.HAS_MINOR : (short)0 ) );
}
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.err.println("Info: ExtensionAvailabilityCache: FunctionAvailabilityCache.Version.<init>: " + e);
+ val[0] = 1;
+ val[1] = 0;
}
- return new GLVersionNumber(val, versionString, true);
- } catch (Exception e) {
- e.printStackTrace();
- // FIXME: refactor desktop OpenGL dependencies and make this
- // class work properly for OpenGL ES
- System.err.println("Info: ExtensionAvailabilityCache: FunctionAvailabilityCache.Version.<init>: " + e);
- val[0] = 1;
- val[1] = 0;
- /*
- throw (IllegalArgumentException)
- new IllegalArgumentException(
- "Illegally formatted version identifier: \"" + versionString + "\"")
- .initCause(e);
- */
- }
- return new GLVersionNumber(val, versionString, false);
+ }
+ return new GLVersionNumber(val, strEnd, state, versionString, false);
}
public final boolean isValid() {
@@ -131,6 +95,7 @@ class GLVersionNumber extends VersionNumberString {
* <code>GL_VERSION</code> string if exists, otherwise the {@link VersionNumberString#zeroVersion zero version} instance.
* <pre>
* 2.1 Mesa 7.0.3-rc2 -> 7.0.3 (7.0.3-rc2)
+ * 2.1 Mesa 7.12-devel (git-d6c318e) -> 7.12.0 (7.12-devel)
* 4.2.12171 Compatibility Profile Context 9.01.8 -> 9.1.8 (9.01.8)
* 4.2.12198 Compatibility Profile Context 12.102.3.0 -> 12.102.3 (12.102.3.0)
* 4.3.0 NVIDIA 310.32 -> 310.32 (310.32)
@@ -139,19 +104,21 @@ class GLVersionNumber extends VersionNumberString {
public static final VersionNumberString createVendorVersion(String versionString) {
if (versionString == null || versionString.length() <= 0) {
return null;
- }
- final String[] strings = versionString.trim().split("\\s+");
- if ( strings.length <= 0 ) {
- return null;
}
- // Test all segments backwards from [len-1..1], skipping the 1st entry (GL version)
- // If a segment represents a valid VersionNumber - use it.
- for(int i=strings.length-1; i>=1; i--) {
- final String s = strings[i];
- final VersionNumberString version = new VersionNumberString(s, ".");
- if( !version.isZero() ) {
+
+ // Skip the 1st GL version
+ String str;
+ {
+ final GLVersionNumber glv = create(versionString);
+ str = versionString.substring(glv.endOfStringMatch());
+ }
+
+ while ( str.length() > 0 ) {
+ final VersionNumberString version = new VersionNumberString(str, getDefaultVersionNumberPattern());
+ if( version.hasMajor() && version.hasMinor() ) { // Requires at least a defined major and minor version component!
return version;
}
+ str = str.substring(version.endOfStringMatch());
}
return VersionNumberString.zeroVersion;
}