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

experimental
iwgeric 10 years ago
parent fb04910980
commit 6f4b90feed
  1. 69
      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()); public static int extractVersion(String version) {
if (spaceIdx >= 1) {
versionStr = versionStr.substring(prefixStr.length(), spaceIdx).trim(); Matcher m = VERSION.matcher(version);
} else { if (m.matches()) {
versionStr = versionStr.substring(prefixStr.length()).trim(); int major = Integer.parseInt(m.group(1));
} int minor = Integer.parseInt(m.group(2));
// Find a character which is not a period or digit. return major * 100 + minor * 10;
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;
} else { } else {
return -1; return -1;
} }
@ -194,11 +167,11 @@ public class OGLESShaderRenderer implements Renderer {
powerVr = GLES20.glGetString(GLES20.GL_RENDERER).contains("PowerVR"); powerVr = GLES20.glGetString(GLES20.GL_RENDERER).contains("PowerVR");
//workaround, always assume we support GLSL100 //workaround, always assume we support GLSL100
//some cards just don't report this correctly //some cards just don't report this correctly
caps.add(Caps.GLSL100); caps.add(Caps.GLSL100);
/* /*
// Fix issue in TestRenderToMemory when GL_FRONT is the main // Fix issue in TestRenderToMemory when GL_FRONT is the main
// buffer being used. // buffer being used.
@ -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.
@ -477,7 +450,7 @@ public class OGLESShaderRenderer implements Renderer {
*/ */
if (state.isDepthTest() && !context.depthTestEnabled) { if (state.isDepthTest() && !context.depthTestEnabled) {
GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glEnable(GLES20.GL_DEPTH_TEST);
GLES20.glDepthFunc(convertTestFunction(context.depthFunc)); GLES20.glDepthFunc(convertTestFunction(context.depthFunc));
RendererUtil.checkGLError(); RendererUtil.checkGLError();
context.depthTestEnabled = true; context.depthTestEnabled = true;
} else if (!state.isDepthTest() && context.depthTestEnabled) { } else if (!state.isDepthTest() && context.depthTestEnabled) {
@ -612,7 +585,7 @@ public class OGLESShaderRenderer implements Renderer {
break; break;
case Screen: case Screen:
GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_COLOR); GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_COLOR);
break; break;
case Exclusion: case Exclusion:
GLES20.glBlendFunc(GLES20.GL_ONE_MINUS_DST_COLOR, GLES20.GL_ONE_MINUS_SRC_COLOR); GLES20.glBlendFunc(GLES20.GL_ONE_MINUS_DST_COLOR, GLES20.GL_ONE_MINUS_SRC_COLOR);
break; break;
@ -1095,7 +1068,7 @@ public class OGLESShaderRenderer implements Renderer {
throw new UnsupportedOperationException("Unrecognized test function: " + testFunc); throw new UnsupportedOperationException("Unrecognized test function: " + testFunc);
} }
} }
/*********************************************************************\ /*********************************************************************\
|* Framebuffers *| |* Framebuffers *|
\*********************************************************************/ \*********************************************************************/
@ -2585,10 +2558,10 @@ public class OGLESShaderRenderer implements Renderer {
} }
public void setMainFrameBufferSrgb(boolean srgb) { public void setMainFrameBufferSrgb(boolean srgb) {
//TODO once opglES3.0 is supported maybe.... //TODO once opglES3.0 is supported maybe....
} }
public void setLinearizeSrgbImages(boolean linearize) { public void setLinearizeSrgbImages(boolean linearize) {
//TODO once opglES3.0 is supported maybe.... //TODO once opglES3.0 is supported maybe....
} }
} }

Loading…
Cancel
Save