hard to diagnose error in shader
This may be flixel's fault, but I noticed that this:
class SimpleShader extends flixel.system.FlxAssets.FlxShader
{
@:glFragmentSource('
#pragmaheader // Note the missing space between pragma and header
void main()
{
gl_FragColor = texture2D(bitmap, openfl_TextureCoordv);
}
')
public function new()
{
super();
}
}
Causes extremely different errors than simple omitting the pragma header line altogether, the latter throws a glsl parsing error, where the former causes shader.bitmap to be null, I'm wondering why that is, and whether the resulting error can be less cryptic
It's not flixel's fault. The #pragma header directive is preprocessed by a simple string replace, here:
https://github.com/openfl/openfl/blob/e1fd1a04a09ad43950d0d84e490166e05d152171/src/openfl/utils/_internal/ShaderMacro.hx#L106
Missing the space means that the substitution won't take place, and the resulting shader string is sent as-is to the opengl driver. The error message is GPU-vendor-dependent: and some vendors might also treat it as a warning and/or just skip the faulty line, so you could have a shader working fine on your GPU and then failing for some of your players.
Probably the only way to catch this type of errors independently of opengl drivers is to use a Haxe based GLSL parser/compiler like Heaps' HXSL.
I'm mainly surprised it's not giving this error:
'pragmaheader' : invalid directive name
Could OpenFL check if #pragma header is in the source via something like StringTools.contains and warn/error if it isn't?