Temporary fix for searching for version strings until URA is done.

experimental
iwgeric 10 years ago
parent fb04910980
commit 6f4b90feed
  1. 49
      jme3-android/src/main/java/com/jme3/renderer/android/OGLESShaderRenderer.java

@ -77,6 +77,8 @@ import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jme3tools.shader.ShaderDebug; import jme3tools.shader.ShaderDebug;
public class OGLESShaderRenderer implements Renderer { public class OGLESShaderRenderer implements Renderer {
@ -142,45 +144,16 @@ public class OGLESShaderRenderer implements Renderer {
return caps; return caps;
} }
private static int extractVersion(String prefixStr, String versionStr) { private static final Pattern VERSION = Pattern.compile(".*?(\\d+)\\.(\\d+).*");
if (versionStr != null) {
int spaceIdx = versionStr.indexOf(" ", prefixStr.length());
if (spaceIdx >= 1) {
versionStr = versionStr.substring(prefixStr.length(), spaceIdx).trim();
} else {
versionStr = versionStr.substring(prefixStr.length()).trim();
}
// Find a character which is not a period or digit.
for (int i = 0; i < versionStr.length(); i++) {
char c = versionStr.charAt(i);
if (c != '.' && (c < '0' || c > '9')) {
versionStr = versionStr.substring(0, i);
break;
}
}
// Pivot on first point. public static int extractVersion(String version) {
int firstPoint = versionStr.indexOf(".");
// Remove everything after second point.
int secondPoint = versionStr.indexOf(".", firstPoint + 1);
if (secondPoint != -1) {
versionStr = versionStr.substring(0, secondPoint);
}
String majorVerStr = versionStr.substring(0, firstPoint);
String minorVerStr = versionStr.substring(firstPoint + 1);
if (minorVerStr.endsWith("0") && minorVerStr.length() > 1) {
minorVerStr = minorVerStr.substring(0, minorVerStr.length() - 1);
}
int majorVer = Integer.parseInt(majorVerStr); Matcher m = VERSION.matcher(version);
int minorVer = Integer.parseInt(minorVerStr); if (m.matches()) {
int major = Integer.parseInt(m.group(1));
int minor = Integer.parseInt(m.group(2));
return majorVer * 100 + minorVer * 10; return major * 100 + minor * 10;
} else { } else {
return -1; return -1;
} }
@ -213,14 +186,14 @@ public class OGLESShaderRenderer implements Renderer {
*/ */
// Check OpenGL version // Check OpenGL version
int openGlVer = extractVersion("OpenGL ES ", GLES20.glGetString(GLES20.GL_VERSION)); int openGlVer = extractVersion(GLES20.glGetString(GLES20.GL_VERSION));
if (openGlVer == -1) { if (openGlVer == -1) {
glslVer = -1; glslVer = -1;
throw new UnsupportedOperationException("OpenGL ES 2.0+ is required for OGLESShaderRenderer!"); throw new UnsupportedOperationException("OpenGL ES 2.0+ is required for OGLESShaderRenderer!");
} }
// Check shader language version // Check shader language version
glslVer = extractVersion("OpenGL ES GLSL ", GLES20.glGetString(GLES20.GL_SHADING_LANGUAGE_VERSION)); glslVer = extractVersion(GLES20.glGetString(GLES20.GL_SHADING_LANGUAGE_VERSION));
switch (glslVer) { switch (glslVer) {
// TODO: When new versions of OpenGL ES shader language come out, // TODO: When new versions of OpenGL ES shader language come out,
// update this. // update this.

Loading…
Cancel
Save