Skip to content

Commit 6b2af99

Browse files
committed
Fixes post shadows compilation issue on android
1 parent c72b73e commit 6b2af99

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,7 @@ public void updateShaderSourceData(ShaderSource source) {
13271327
+ "Only GLSL 1.00 shaders are supported.");
13281328
}
13291329

1330+
boolean insertPrecision = false;
13301331
// Upload shader source.
13311332
// Merge the defines and source code.
13321333
stringBuf.setLength(0);
@@ -1346,7 +1347,7 @@ public void updateShaderSourceData(ShaderSource source) {
13461347

13471348
if (source.getType() == ShaderType.Fragment) {
13481349
// GLES2 requires precision qualifier.
1349-
stringBuf.append("precision mediump float;\n");
1350+
insertPrecision = true;
13501351
}
13511352
} else {
13521353
// version 100 does not exist in desktop GLSL.
@@ -1365,6 +1366,14 @@ public void updateShaderSourceData(ShaderSource source) {
13651366
stringBuf.append(source.getDefines());
13661367
stringBuf.append(source.getSource());
13671368

1369+
if(insertPrecision){
1370+
// precision token is not a preprocessor dirrective therefore it must be placed after #extension tokens to avoid
1371+
// Error P0001: Extension directive must occur before any non-preprocessor tokens
1372+
int idx = stringBuf.lastIndexOf("#extension");
1373+
idx = stringBuf.indexOf("\n", idx);
1374+
stringBuf.insert(idx + 1, "precision mediump float;\n");
1375+
}
1376+
13681377
intBuf1.clear();
13691378
intBuf1.put(0, stringBuf.length());
13701379
gl.glShaderSource(id, new String[]{ stringBuf.toString() }, intBuf1);

jme3-core/src/main/resources/Common/ShaderLib/Shadows.glsllib

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// gather functions are declared to work on shadowmaps
44
#extension GL_ARB_gpu_shader5 : enable
55
#define IVEC2 ivec2
6-
#ifdef HARDWARE_SHADOWS
6+
#if defined GL_ES
7+
#define SHADOWMAP sampler2D
8+
#define SHADOWCOMPARE(tex,coord) step(coord.z, texture2DProj(tex, coord).r)
9+
#elif defined HARDWARE_SHADOWS
710
#define SHADOWMAP sampler2DShadow
811
#define SHADOWCOMPAREOFFSET(tex,coord,offset) textureProjOffset(tex, coord, offset)
912
#define SHADOWCOMPARE(tex,coord) textureProj(tex, coord)

jme3-examples/src/main/java/jme3test/light/TestShadowsPerf.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public static void main(String[] args) {
6969

7070
@Override
7171
public void simpleInitApp() {
72-
Logger.getLogger("com.jme3").setLevel(Level.SEVERE);
7372
flyCam.setMoveSpeed(50);
7473
flyCam.setEnabled(false);
7574
viewPort.setBackgroundColor(ColorRGBA.DarkGray);

0 commit comments

Comments
 (0)