diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java index 790e538f8..372233dd6 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java @@ -1327,6 +1327,7 @@ public final class GLRenderer implements Renderer { + "Only GLSL 1.00 shaders are supported."); } + boolean insertPrecision = false; // Upload shader source. // Merge the defines and source code. stringBuf.setLength(0); @@ -1346,7 +1347,7 @@ public final class GLRenderer implements Renderer { if (source.getType() == ShaderType.Fragment) { // GLES2 requires precision qualifier. - stringBuf.append("precision mediump float;\n"); + insertPrecision = true; } } else { // version 100 does not exist in desktop GLSL. @@ -1365,6 +1366,14 @@ public final class GLRenderer implements Renderer { stringBuf.append(source.getDefines()); stringBuf.append(source.getSource()); + if(insertPrecision){ + // precision token is not a preprocessor dirrective therefore it must be placed after #extension tokens to avoid + // Error P0001: Extension directive must occur before any non-preprocessor tokens + int idx = stringBuf.lastIndexOf("#extension"); + idx = stringBuf.indexOf("\n", idx); + stringBuf.insert(idx + 1, "precision mediump float;\n"); + } + intBuf1.clear(); intBuf1.put(0, stringBuf.length()); gl.glShaderSource(id, new String[]{ stringBuf.toString() }, intBuf1); diff --git a/jme3-core/src/main/resources/Common/ShaderLib/Shadows.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/Shadows.glsllib index baf003f88..c7c6b8851 100644 --- a/jme3-core/src/main/resources/Common/ShaderLib/Shadows.glsllib +++ b/jme3-core/src/main/resources/Common/ShaderLib/Shadows.glsllib @@ -3,7 +3,10 @@ // gather functions are declared to work on shadowmaps #extension GL_ARB_gpu_shader5 : enable #define IVEC2 ivec2 - #ifdef HARDWARE_SHADOWS + #if defined GL_ES + #define SHADOWMAP sampler2D + #define SHADOWCOMPARE(tex,coord) step(coord.z, texture2DProj(tex, coord).r) + #elif defined HARDWARE_SHADOWS #define SHADOWMAP sampler2DShadow #define SHADOWCOMPAREOFFSET(tex,coord,offset) textureProjOffset(tex, coord, offset) #define SHADOWCOMPARE(tex,coord) textureProj(tex, coord) diff --git a/jme3-examples/src/main/java/jme3test/light/TestShadowsPerf.java b/jme3-examples/src/main/java/jme3test/light/TestShadowsPerf.java index f267b1d41..97629117e 100644 --- a/jme3-examples/src/main/java/jme3test/light/TestShadowsPerf.java +++ b/jme3-examples/src/main/java/jme3test/light/TestShadowsPerf.java @@ -69,7 +69,6 @@ public class TestShadowsPerf extends SimpleApplication { @Override public void simpleInitApp() { - Logger.getLogger("com.jme3").setLevel(Level.SEVERE); flyCam.setMoveSpeed(50); flyCam.setEnabled(false); viewPort.setBackgroundColor(ColorRGBA.DarkGray);