SyntaxHub frontend for glsl shaders
This commit is contained in:
1
extraParams.hxml
Normal file
1
extraParams.hxml
Normal file
@@ -0,0 +1 @@
|
||||
--macro kiss_flixel.ShaderFrontend.use()
|
||||
@@ -7,4 +7,5 @@
|
||||
-lib openfl
|
||||
-cp ${SCOPE_DIR}/..//src/
|
||||
-D kiss-flixel=0.0.0
|
||||
${SCOPE_DIR}/..//extraParams.hxml
|
||||
--macro Sys.println("haxe_libraries/kiss-flixel.hxml:9: [Warning] Using dev version of library kiss-flixel")
|
||||
7
shader-test/source/CShader.f.glsl
Normal file
7
shader-test/source/CShader.f.glsl
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma header
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = flixel_texture2D(bitmap, openfl_TextureCoordv);
|
||||
gl_FragColor = vec4((1.0 - color.r) * color.a, (1.0 - color.g) * color.a, (1.0 - color.b) * color.a, color.a);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import flixel.system.FlxAssets.FlxShader;
|
||||
|
||||
class CShader extends FlxShader {
|
||||
@:glFragmentSource('
|
||||
#pragma header
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = flixel_texture2D(bitmap, openfl_TextureCoordv);
|
||||
gl_FragColor = vec4((1.0 - color.r) * color.a, (1.0 - color.g) * color.a, (1.0 - color.b) * color.a, color.a);
|
||||
}'
|
||||
)
|
||||
|
||||
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
64
src/kiss_flixel/ShaderFrontend.hx
Normal file
64
src/kiss_flixel/ShaderFrontend.hx
Normal file
@@ -0,0 +1,64 @@
|
||||
package kiss_flixel;
|
||||
|
||||
import tink.syntaxhub.*;
|
||||
import haxe.macro.Expr;
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr.ImportMode;
|
||||
using StringTools;
|
||||
using tink.MacroApi;
|
||||
|
||||
class ShaderFrontend implements FrontendPlugin {
|
||||
|
||||
public function new() {}
|
||||
|
||||
var vertexExtensions = ["v.glsl", "vert"];
|
||||
var fragmentExtensions = ["f.glsl", "frag"];
|
||||
|
||||
public function extensions() {
|
||||
return vertexExtensions.concat(fragmentExtensions).iterator();
|
||||
}
|
||||
|
||||
public function parse(file:String, context:FrontendContext):Void {
|
||||
var extension = file.substr(file.indexOf(".") + 1);
|
||||
trace(extension);
|
||||
|
||||
final type = context.getType();
|
||||
var parentClass = 'flixel.system.FlxAssets.FlxShader';
|
||||
type.kind = TDClass(parentClass.asTypePath(), [], false, false, false);
|
||||
|
||||
var pos = Context.makePosition({ file: file, min: 0, max: 0 });
|
||||
|
||||
var metaName = if (vertexExtensions.contains(extension))
|
||||
":glVertexSource"
|
||||
else if (fragmentExtensions.contains(extension))
|
||||
":glFragmentSource"
|
||||
else
|
||||
throw "Unknown extension";
|
||||
|
||||
var meta = {
|
||||
pos: pos,
|
||||
name: metaName,
|
||||
params: [
|
||||
{
|
||||
pos: pos,
|
||||
expr: EConst(CString(sys.io.File.getContent(file)))
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
type.fields.push({
|
||||
pos: pos,
|
||||
name: "new",
|
||||
meta: [meta],
|
||||
kind: FFun({
|
||||
args: [],
|
||||
expr: macro { super(); }
|
||||
}),
|
||||
access: [APublic]
|
||||
});
|
||||
}
|
||||
|
||||
static function use() {
|
||||
tink.SyntaxHub.frontends.whenever(new ShaderFrontend());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user