@@ -65,7 +65,7 @@ class ShaderMacro
6565 all have a second argument which, if true, will use `processGLSLText` to convert the text to be compatible with the current GLSL version.
6666 Defaults to false to prevent converting user-defined GLSL.
6767 **/
68- var shouldProcess = meta .params .length > 1 && cast (meta .params [1 ].getValue (), Bool );
68+ var shouldProcess = /* meta.params.length > 1 && cast(meta.params[1].getValue(), Bool)*/ true ;
6969
7070 switch (meta .name )
7171 {
@@ -174,7 +174,7 @@ class ShaderMacro
174174 all have a second argument which, if true, will use `processGLSLText` to convert the text to be compatible with the current GLSL version.
175175 Defaults to false to prevent converting user-defined GLSL.
176176 **/
177- var shouldProcess = meta .params .length > 1 && cast (meta .params [1 ].getValue (), Bool );
177+ var shouldProcess = /* meta.params.length > 1 && cast(meta.params[1].getValue(), Bool)*/ true ;
178178
179179 switch (meta .name )
180180 {
@@ -257,6 +257,9 @@ class ShaderMacro
257257 glVersion = getDefaultGLVersion ();
258258 }
259259
260+ glVertexHeader = buildGLSLHeaders (glVersion ) + glVertexHeader ;
261+ glFragmentHeader = buildGLSLHeaders (glVersion ) + glFragmentHeader ;
262+
260263 glVertexExtensions = buildGLSLExtensions (glVertexExtensions , glVersion , false );
261264 glFragmentExtensions = buildGLSLExtensions (glFragmentExtensions , glVersion , true );
262265
@@ -265,14 +268,14 @@ class ShaderMacro
265268 if (glFragmentSource != null && glFragmentHeader != null && glFragmentBody != null )
266269 {
267270 glFragmentSourceRaw = glFragmentSource ;
268- glFragmentSource = StringTools .replace (glFragmentSource , " #pragma header" , buildGLSLHeaders ( glVersion ) + glFragmentHeader );
271+ glFragmentSource = StringTools .replace (glFragmentSource , " #pragma header" , glFragmentHeader );
269272 glFragmentSource = StringTools .replace (glFragmentSource , " #pragma body" , glFragmentBody );
270273 }
271274
272275 if (glVertexSource != null && glVertexHeader != null && glVertexBody != null )
273276 {
274277 glVertexSourceRaw = glVertexSource ;
275- glVertexSource = StringTools .replace (glVertexSource , " #pragma header" , buildGLSLHeaders ( glVersion ) + glVertexHeader );
278+ glVertexSource = StringTools .replace (glVertexSource , " #pragma header" , glVertexHeader );
276279 glVertexSource = StringTools .replace (glVertexSource , " #pragma body" , glVertexBody );
277280 }
278281
@@ -441,7 +444,7 @@ class ShaderMacro
441444 {
442445 // Specify the default glVersion.
443446 // We can use compile defines to guess the value that prevents crashes in the majority of cases.
444- return " 100 " ;
447+ return " 300 es " ;
445448 }
446449
447450 /**
@@ -453,32 +456,21 @@ class ShaderMacro
453456 */
454457 private static function processGLSLText (source : String , glVersion : String , isFragment : Bool )
455458 {
456- if (glVersion == " " || glVersion == null ) return processGLSLText (source , getDefaultGLVersion (), isFragment );
457-
458- // No processing needed on "compatibility" profile
459- if (StringTools .endsWith (glVersion , " compatibility" )) return source ;
460- if (StringTools .endsWith (glVersion , " core" )) return processGLSLText (source , StringTools .replace (glVersion , " core" , " " ), isFragment );
459+ if (glVersion == null || glVersion == " " ) return processGLSLText (source , getDefaultGLVersion (), isFragment );
461460
462- // Recall: Attribute values are per-vertex, varying values are per-fragment
463- // Thus, an `out` value in the vertex shader is an `in` value in the fragment shader
464- var attributeKeyword : EReg = ~/ attribute ([A-Za-z0-9 ] + ) ([A-Za-z0-9 _] + )/ g ; // g to match all
465- var varyingKeyword : EReg = ~/ varying ([A-Za-z0-9 ] + ) ([A-Za-z0-9 _] + )/ g ; // g to match all
466-
467- var texture2DKeyword : EReg = ~/ texture2D/ g ;
468- var glFragColorKeyword : EReg = ~/ gl_FragColor/ g ;
461+ var attributeKeyword : EReg = ~/ \b attribute\s + ([A-Za-z0-9 _] + )\s + ([A-Za-z0-9 _] + )/ g ;
462+ var varyingKeyword : EReg = ~/ \b varying\s + (?:lowp| mediump| highp\s + )? ([A-Za-z0-9 _] + )\s + ([A-Za-z0-9 _] + )/ g ;
463+ var texture2DKeyword : EReg = ~/ \b texture2D\b / g ;
464+ var glFragColorKeyword : EReg = ~/ \b gl_FragColor\b / g ;
469465
470466 switch (glVersion )
471467 {
472468 default :
473- // Don't make any changes to undefined versions.
474- return source ;
475-
476- case " 100" , " 110" , " 120" , " 130" , " 140" , " 150" :
477469 return source ;
478470
479- case " 300 es" :
471+ case " 300 es" , " 310 es " , " 320 es " :
480472 var result = source ;
481- // Migrate, replacing "attribute" with "in" and "varying" with "out".
473+
482474 if (isFragment )
483475 {
484476 result = varyingKeyword .replace (result , " in $1 $2" );
@@ -488,81 +480,29 @@ class ShaderMacro
488480 result = attributeKeyword .replace (result , " in $1 $2" );
489481 result = varyingKeyword .replace (result , " out $1 $2" );
490482 }
491- result = texture2DKeyword .replace (result , " texture" );
492- result = glFragColorKeyword .replace (result , " fragColor" );
493- return result ;
494483
495- case " 310 es" , " 320 es" :
496- var result = processGLSLText (source , " 300 es" , isFragment );
497- return result ;
498-
499- case " 330" :
500- #if desktop
501- var result = processGLSLText (source , " 300 es" , isFragment );
502- #else
503- var result = source ;
504- #end
505- return result ;
484+ result = texture2DKeyword .replace (result , " texture" );
485+ result = glFragColorKeyword .replace (result , " openfl_FragColor" );
506486
507- case " 400" , " 410" , " 420" , " 430" , " 440" , " 450" , " 460" :
508- var result = processGLSLText (source , " 330" , isFragment );
509487 return result ;
510488 }
511489 }
512490
513491 private static function buildGLSLHeaders (glVersion : String ): String
514492 {
515- if (StringTools .endsWith (glVersion , " compatibility" )) return " " ;
516- if (StringTools .endsWith (glVersion , " core" )) return buildGLSLHeaders (StringTools .replace (glVersion , " core" , " " ));
517-
518- return switch (glVersion )
493+ switch (glVersion )
519494 {
520- #if desktop
521- case " 300 es" : " layout (location = 0) out vec4 fragColor;\n " ;
522- #else
523- case " 300 es" : " out vec4 fragColor;\n " ;
524- #end
525-
526- case " 310 es" , " 320 es" , " 330" , " 400" , " 410" , " 420" , " 430" , " 440" , " 450" , " 460" :
527- buildGLSLHeaders (" 300 es" );
528-
529- // Don't add any default headers to undefined versions
530- default : " " ;
495+ case " 300 es" , " 310 es" , " 320 es" :
496+ return " out vec4 openfl_FragColor;\n " ;
497+ default :
498+ return " " ;
531499 };
532500 }
533501
534502 private static function buildGLSLExtensions (glExtensions : Array <{name : String , behavior : String }>, glVersion : String ,
535503 isFragment : Bool ): Array <{name : String , behavior : String }>
536504 {
537- if (StringTools .endsWith (glVersion , " compatibility" )) return glExtensions ;
538- if (StringTools .endsWith (glVersion , " core" )) return buildGLSLExtensions (glExtensions , StringTools .replace (glVersion , " core" , " " ), isFragment );
539-
540- switch (glVersion )
541- {
542- // Don't add any extensions to undefined versions
543- default :
544- return glExtensions ;
545-
546- #if desktop
547- case " 300 es" , " 310 es" , " 320 es" , " 330" :
548- var hasSeparateShaderObjects = false ;
549- for (extension in glExtensions )
550- {
551- if (extension .name == " GL_ARB_separate_shader_objects" ) hasSeparateShaderObjects = true ;
552- if (extension .name == " GL_EXT_separate_shader_objects" ) hasSeparateShaderObjects = true ;
553- }
554-
555- if (! hasSeparateShaderObjects )
556- {
557- #if linux
558- return glExtensions .concat ([{name : " GL_EXT_separate_shader_objects" , behavior : " require" }]);
559- #else
560- return glExtensions .concat ([{name : " GL_ARB_separate_shader_objects" , behavior : " require" }]);
561- #end
562- }
563- return glExtensions ;
564- #end
565- }
505+ return glExtensions ;
566506 }
567507
568508 private static function processFields (source : String , storageType : String , fields : Array <Field >, pos : Position ): Void
0 commit comments