aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmake/scripts/tests.sh5
-rw-r--r--src/jogl/classes/jogamp/opengl/GLContextImpl.java2
-rw-r--r--src/jogl/classes/jogamp/opengl/GLVersionNumber.java137
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLVersionParsing00NEWT.java170
4 files changed, 226 insertions, 88 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index 840414c54..8fd7d2852 100755
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -87,7 +87,7 @@ function jrun() {
#D_ARGS="-Djogl.debug.DebugGL -Djogl.debug.FBObject"
#D_ARGS="-Djogl.debug.FBObject -Djogl.debug.TraceGL -Djogl.debug.GLBufferStateTracker"
#D_ARGS="-Djogl.debug.FBObject"
- D_ARGS="-Djogl.debug.GLSLCode"
+ #D_ARGS="-Djogl.debug.GLSLCode"
#D_ARGS="-Djogl.debug.GLSLCode -Djogl.debug.DebugGL -Djogl.debug.TraceGL"
#D_ARGS="-Djogl.debug.GLContext -Dnativewindow.debug.JAWT -Dnewt.debug.Window"
#D_ARGS="-Dnativewindow.debug.JAWT -Djogamp.debug.TaskBase.TraceSource"
@@ -312,6 +312,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestFloatUtil01MatrixMatrixMultNOUI $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestPMVMatrix01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestPMVMatrix02NEWT $*
+testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLVersionParsing00NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestNEWTCloseX11DisplayBug565 $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestMainVersionGLWindowNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLProfile00NEWT $*
@@ -549,7 +550,7 @@ function testawtswt() {
#
#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT10 $*
#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT00 $*
-testnoawt com.jogamp.opengl.test.junit.graph.TestRegionRendererNEWT01 $*
+#testnoawt com.jogamp.opengl.test.junit.graph.TestRegionRendererNEWT01 $*
#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT01 $*
#testnoawt com.jogamp.opengl.test.junit.graph.demos.ui.UINewtDemo01 $*
#testnoawt com.jogamp.opengl.test.junit.graph.demos.GPUTextNewtDemo01 $*
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;
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLVersionParsing00NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLVersionParsing00NEWT.java
new file mode 100644
index 000000000..394772135
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLVersionParsing00NEWT.java
@@ -0,0 +1,170 @@
+/**
+ * Copyright 2013 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.acore;
+
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import jogamp.opengl.GLVersionNumber;
+
+import com.jogamp.common.util.VersionNumberString;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+public class TestGLVersionParsing00NEWT extends UITestCase {
+
+ public static final String[] glVersionStrings00 = new String[] {
+ "GL_VERSION_2_1 DummyTool 1.2.3", // 0
+ "2.1 Mesa 7.0.3-rc2",
+ "4.2.12171 Compatibility Profile Context 9.01.8",
+ "4.2.12198 Compatibility Profile Context 12.102.3.0",
+ "2.1 Mesa 7.0.3-rc2 post odd",
+ "4.2.12171 Compatibility Profile Context 9.01.8 post odd",
+ "4.2.12198 Compatibility Profile Context 12.102.3.0 post odd",
+ "OpenGL ES 2.0 Mesa 9.1.1", // 7
+ "OpenGL ES 2.0 14.10.1",
+ "OpenGL ES GLSL ES 2.0 14.10.1", // 9
+ "OpenGL ES 2.0 3Com L3 11.33.44" // 10
+ };
+ public static final String[] glVersionStrings01 = new String[] {
+ "GL_VERSION_2_1 Dummy Tool 1.2", // 0
+ "2.1 Mesa 7.12",
+ "2.1 Mesa 7.12-devel",
+ "2.1 Mesa 7.12-devel (git-d6c318e)",
+ "2.1 Mesa 7.12-devel la1 la2 li3",
+ "4.3.0 NVIDIA 310.32",
+ "OpenGL ES 2.0 Mesa 9.1", // 6
+ "OpenGL ES 2.0 14.10",
+ "OpenGL ES GLSL ES 2.0 14.10", // 8
+ "OpenGL ES 2.0 3Com L3 11.33" // 9
+ };
+ public static final String[] glVersionStrings02 = new String[] {
+ "GL_VERSION_2_1", // 0
+ "OpenGL ES 2.0", // 1
+ "OpenGL ES GLSL ES 2.0" // 2
+ };
+
+ public static final VersionNumberString[] glVersionNumbers = new VersionNumberString[] {
+ new VersionNumberString(2, 1, 0, glVersionStrings00[0]),
+ new VersionNumberString(2, 1, 0, glVersionStrings00[1]),
+ new VersionNumberString(4, 2, 0, glVersionStrings00[2]),
+ new VersionNumberString(4, 2, 0, glVersionStrings00[3]),
+ new VersionNumberString(2, 1, 0, glVersionStrings00[4]),
+ new VersionNumberString(4, 2, 0, glVersionStrings00[5]),
+ new VersionNumberString(4, 2, 0, glVersionStrings00[6]),
+ new VersionNumberString(2, 0, 0, glVersionStrings00[7]),
+ new VersionNumberString(2, 0, 0, glVersionStrings00[8]),
+ new VersionNumberString(2, 0, 0, glVersionStrings00[9]),
+ new VersionNumberString(2, 0, 0, glVersionStrings00[10]),
+
+ new VersionNumberString(2, 1, 0, glVersionStrings01[0]),
+ new VersionNumberString(2, 1, 0, glVersionStrings01[1]),
+ new VersionNumberString(2, 1, 0, glVersionStrings01[2]),
+ new VersionNumberString(2, 1, 0, glVersionStrings01[3]),
+ new VersionNumberString(2, 1, 0, glVersionStrings01[4]),
+ new VersionNumberString(4, 3, 0, glVersionStrings01[5]),
+ new VersionNumberString(2, 0, 0, glVersionStrings01[6]),
+ new VersionNumberString(2, 0, 0, glVersionStrings01[7]),
+ new VersionNumberString(2, 0, 0, glVersionStrings01[8]),
+ new VersionNumberString(2, 0, 0, glVersionStrings01[9]),
+
+ new VersionNumberString(2, 1, 0, glVersionStrings02[0]),
+ new VersionNumberString(2, 0, 0, glVersionStrings02[1]),
+ new VersionNumberString(2, 0, 0, glVersionStrings02[1])
+ };
+ public static final VersionNumberString[] glVendorVersionNumbersWithSub = new VersionNumberString[] {
+ new VersionNumberString(1, 2, 3, glVersionStrings00[0]),
+ new VersionNumberString(7, 0, 3, glVersionStrings00[1]),
+ new VersionNumberString(9, 1, 8, glVersionStrings00[2]),
+ new VersionNumberString(12, 102, 3, glVersionStrings00[3]),
+ new VersionNumberString(7, 0, 3, glVersionStrings00[4]),
+ new VersionNumberString(9, 1, 8, glVersionStrings00[5]),
+ new VersionNumberString(12, 102, 3, glVersionStrings00[6]),
+ new VersionNumberString(9, 1, 1, glVersionStrings00[7]),
+ new VersionNumberString(14, 10, 1, glVersionStrings00[8]),
+ new VersionNumberString(14, 10, 1, glVersionStrings00[9]),
+ new VersionNumberString(11, 33, 44, glVersionStrings00[10])
+ };
+ public static final VersionNumberString[] glVendorVersionNumbersNoSub = new VersionNumberString[] {
+ new VersionNumberString(1, 2, 0, glVersionStrings01[0]),
+ new VersionNumberString(7, 12, 0, glVersionStrings01[1]),
+ new VersionNumberString(7, 12, 0, glVersionStrings01[2]),
+ new VersionNumberString(7, 12, 0, glVersionStrings01[3]),
+ new VersionNumberString(7, 12, 0, glVersionStrings01[4]),
+ new VersionNumberString(310, 32, 0, glVersionStrings01[5]),
+ new VersionNumberString(9, 1, 0, glVersionStrings01[6]),
+ new VersionNumberString(14, 10, 0, glVersionStrings01[7]),
+ new VersionNumberString(14, 10, 0, glVersionStrings01[8]),
+ new VersionNumberString(11, 33, 0, glVersionStrings01[9])
+ };
+ public static final VersionNumberString[] glVendorVersionNumbersNone = new VersionNumberString[] {
+ new VersionNumberString(0, 0, 0, glVersionStrings02[0]),
+ new VersionNumberString(0, 0, 0, glVersionStrings02[1]),
+ new VersionNumberString(0, 0, 0, glVersionStrings02[2])
+ };
+
+ @Test
+ public void test01GLVersion() throws InterruptedException {
+ for(int i=0; i<glVersionNumbers.length; i++) {
+ final VersionNumberString exp = glVersionNumbers[i];
+ final VersionNumberString has = GLVersionNumber.create(exp.getVersionString());
+ System.err.println("Test["+i+"]: "+exp+" -> "+has+", define ["+has.hasMajor()+":"+has.hasMinor()+":"+has.hasSub()+"]");
+ Assert.assertTrue(has.hasMajor());
+ Assert.assertTrue(has.hasMinor());
+ Assert.assertTrue(!has.hasSub());
+ Assert.assertEquals(exp, has);
+ }
+ }
+
+ private void testGLVendorVersionImpl(VersionNumberString[] versionNumberString, boolean withMajor, boolean withMinor, boolean withSub) throws InterruptedException {
+ for(int i=0; i<versionNumberString.length; i++) {
+ final VersionNumberString exp = versionNumberString[i];
+ final VersionNumberString has = GLVersionNumber.createVendorVersion(exp.getVersionString());
+ System.err.println("Test["+withMajor+":"+withMinor+":"+withSub+"]["+i+"]: "+exp+" -> "+has+", define ["+has.hasMajor()+":"+has.hasMinor()+":"+has.hasSub()+"]");
+ Assert.assertEquals(withMajor, has.hasMajor());
+ Assert.assertEquals(withMinor, has.hasMinor());
+ Assert.assertEquals(withSub, has.hasSub());
+ Assert.assertEquals(exp, has);
+ }
+ }
+
+ @Test
+ public void test02GLVendorVersion() throws InterruptedException {
+ testGLVendorVersionImpl(glVendorVersionNumbersWithSub, true, true, true);
+ testGLVendorVersionImpl(glVendorVersionNumbersNoSub, true, true, false);
+ testGLVendorVersionImpl(glVendorVersionNumbersNone, false, false, false);
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestGLVersionParsing00NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+} \ No newline at end of file