Shader issue: #extension repeated in shader

Johan Vos johan.vos at
Wed Dec 30 12:33:42 UTC 2015

When upgrading a Nexus 6 from Android 5.1.1 to Android 6, the JavaFX 3D
stopped working.
The relevant error is this:

java.lang.RuntimeException: Error creating fragment shader

The shader compilation failed with this error:
GLSL compile error:  Extension directives must occur before any
non-preprocessor tokens.
which occurs in

When debugging this, it seems the fragment shader passed
to glCtx.compileShader is created by ES2PhongShader.getShader() which
starts from main1Light.frag and which will do a replaceAll for a number of
statements which will replace those statements with other shader code that
also contains an #extension directive.

As a result, the resulting shader source contains a number of identical
#extension directives. It seems the latest drivers on Android are much more
strict in compiling shaders, and they complain about the position of the
extension directives.

It seems to me some post-processing needs to be done on the result of the
replaceAll() statements when creating the fragment shader in
ES2PhongShader.getShader(ES2MeshView meshView, ES2Context context)

I did a quick and dirty workaround for this in the 8u-dev-tree on

With this patch, JavaFX 3D works again on Android, but it is not the best
post-processing solution.

Another solution might be to remove the extension directives from the
individual files in glsl and add them at the end of the processing chain?

- Johan

More information about the openjfx-dev mailing list