3838import com .jme3 .material .TechniqueDef ;
3939import com .jme3 .shader .Shader .ShaderType ;
4040import java .util .List ;
41+ import java .util .regex .*;
4142
4243/**
4344 * This class is the base for a shader generator using the ShaderNodes system,
@@ -59,7 +60,11 @@ public abstract class ShaderGenerator {
5960 /**
6061 * the technique def to use for the shader generation
6162 */
62- protected TechniqueDef techniqueDef = null ;
63+ protected TechniqueDef techniqueDef = null ;
64+ /**
65+ * Extension pattern
66+ */
67+ Pattern extensions = Pattern .compile ("(#extension.*\\ s+)" );
6368
6469 /**
6570 * Build a shaderGenerator
@@ -142,7 +147,23 @@ protected String buildShader(List<ShaderNode> shaderNodes, ShaderGenerationInfo
142147
143148 sourceDeclaration .append (source );
144149
145- return sourceDeclaration .toString ();
150+ return moveExtensionsUp (sourceDeclaration );
151+ }
152+
153+ /**
154+ * parses the source and moves all the extensions at the top of the shader source as having extension declarations
155+ * in the middle of a shader is against the specs and not supported by all drivers.
156+ * @param sourceDeclaration
157+ * @return
158+ */
159+ private String moveExtensionsUp (StringBuilder sourceDeclaration ) {
160+ Matcher m = extensions .matcher ( sourceDeclaration .toString ());
161+ StringBuilder finalSource = new StringBuilder ();
162+ while (m .find ()){
163+ finalSource .append (m .group ());
164+ }
165+ finalSource .append (m .replaceAll ("" ));
166+ return finalSource .toString ();
146167 }
147168
148169 /**
0 commit comments