From 6f4b90feed149d3f8ed5d8dd2b57c19d138eeefc Mon Sep 17 00:00:00 2001 From: iwgeric Date: Mon, 8 Dec 2014 22:41:45 -0500 Subject: [PATCH] Temporary fix for searching for version strings until URA is done. --- .../renderer/android/OGLESShaderRenderer.java | 69 ++++++------------- 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/jme3-android/src/main/java/com/jme3/renderer/android/OGLESShaderRenderer.java b/jme3-android/src/main/java/com/jme3/renderer/android/OGLESShaderRenderer.java index f6bd6508c..b12c7fea7 100644 --- a/jme3-android/src/main/java/com/jme3/renderer/android/OGLESShaderRenderer.java +++ b/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.logging.Level; import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import jme3tools.shader.ShaderDebug; public class OGLESShaderRenderer implements Renderer { @@ -142,45 +144,16 @@ public class OGLESShaderRenderer implements Renderer { return caps; } - private static int extractVersion(String prefixStr, String versionStr) { - 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. - 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); - int minorVer = Integer.parseInt(minorVerStr); - - return majorVer * 100 + minorVer * 10; + private static final Pattern VERSION = Pattern.compile(".*?(\\d+)\\.(\\d+).*"); + + public static int extractVersion(String version) { + + Matcher m = VERSION.matcher(version); + if (m.matches()) { + int major = Integer.parseInt(m.group(1)); + int minor = Integer.parseInt(m.group(2)); + + return major * 100 + minor * 10; } else { return -1; } @@ -194,11 +167,11 @@ public class OGLESShaderRenderer implements Renderer { powerVr = GLES20.glGetString(GLES20.GL_RENDERER).contains("PowerVR"); - + //workaround, always assume we support GLSL100 //some cards just don't report this correctly caps.add(Caps.GLSL100); - + /* // Fix issue in TestRenderToMemory when GL_FRONT is the main // buffer being used. @@ -213,14 +186,14 @@ public class OGLESShaderRenderer implements Renderer { */ // Check OpenGL version - int openGlVer = extractVersion("OpenGL ES ", GLES20.glGetString(GLES20.GL_VERSION)); + int openGlVer = extractVersion(GLES20.glGetString(GLES20.GL_VERSION)); if (openGlVer == -1) { glslVer = -1; throw new UnsupportedOperationException("OpenGL ES 2.0+ is required for OGLESShaderRenderer!"); } // 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) { // TODO: When new versions of OpenGL ES shader language come out, // update this. @@ -477,7 +450,7 @@ public class OGLESShaderRenderer implements Renderer { */ if (state.isDepthTest() && !context.depthTestEnabled) { GLES20.glEnable(GLES20.GL_DEPTH_TEST); - GLES20.glDepthFunc(convertTestFunction(context.depthFunc)); + GLES20.glDepthFunc(convertTestFunction(context.depthFunc)); RendererUtil.checkGLError(); context.depthTestEnabled = true; } else if (!state.isDepthTest() && context.depthTestEnabled) { @@ -612,7 +585,7 @@ public class OGLESShaderRenderer implements Renderer { break; case Screen: GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_COLOR); - break; + break; case Exclusion: GLES20.glBlendFunc(GLES20.GL_ONE_MINUS_DST_COLOR, GLES20.GL_ONE_MINUS_SRC_COLOR); break; @@ -1095,7 +1068,7 @@ public class OGLESShaderRenderer implements Renderer { throw new UnsupportedOperationException("Unrecognized test function: " + testFunc); } } - + /*********************************************************************\ |* Framebuffers *| \*********************************************************************/ @@ -2585,10 +2558,10 @@ public class OGLESShaderRenderer implements Renderer { } public void setMainFrameBufferSrgb(boolean srgb) { - //TODO once opglES3.0 is supported maybe.... + //TODO once opglES3.0 is supported maybe.... } public void setLinearizeSrgbImages(boolean linearize) { - //TODO once opglES3.0 is supported maybe.... + //TODO once opglES3.0 is supported maybe.... } }