Update
This commit is contained in:
@ -6,25 +6,32 @@ import haxe.macro.Expr.Field;
|
||||
import haxe.Serializer;
|
||||
#if macro
|
||||
import sys.io.File;
|
||||
import sys.FileSystem;
|
||||
#end
|
||||
|
||||
using StringTools;
|
||||
|
||||
class ShadersBuilder {
|
||||
#if macro
|
||||
public static var files: Array<Dynamic>;
|
||||
@:persistent static var cache: {time: Float, fields: Array<Field>} = null;
|
||||
static var debug = false;
|
||||
#end
|
||||
|
||||
macro static public function build(): Array<Field> {
|
||||
var fields = Context.getBuildFields();
|
||||
|
||||
var manifestPath = AssetsBuilder.findResources() + "files.json";
|
||||
var content = Json.parse(File.getContent(manifestPath));
|
||||
|
||||
final fields = Context.getBuildFields();
|
||||
final manifestPath = AssetsBuilder.findResources() + "files.json";
|
||||
// rebuild Shaders module whenever manifest file is changed
|
||||
Context.registerModuleDependency(Context.getLocalModule(), manifestPath);
|
||||
|
||||
files = content.files;
|
||||
final time = FileSystem.stat(manifestPath).mtime.getTime();
|
||||
if (cache != null && time == cache.time) {
|
||||
return cache.fields;
|
||||
}
|
||||
|
||||
final content = Json.parse(File.getContent(manifestPath));
|
||||
final files: Array<Dynamic> = content.files;
|
||||
if (debug)
|
||||
trace("invalidate Shaders");
|
||||
|
||||
var init = macro {};
|
||||
|
||||
@ -56,7 +63,7 @@ class ShadersBuilder {
|
||||
doc: null,
|
||||
meta: [],
|
||||
access: [APublic, AStatic],
|
||||
kind: FVar(macro : kha.compute.Shader, macro null),
|
||||
kind: FVar(macro : kha.graphics4.ComputeShader, macro null),
|
||||
pos: Context.currentPos()
|
||||
});
|
||||
|
||||
@ -69,7 +76,7 @@ class ShadersBuilder {
|
||||
var bytes: haxe.io.Bytes = haxe.Unserializer.run(data);
|
||||
blobs.push(kha.Blob.fromBytes(bytes));
|
||||
}
|
||||
$i{fixedName} = new kha.compute.Shader(blobs, $v{filenames});
|
||||
$i{fixedName} = new kha.graphics4.ComputeShader(blobs, $v{filenames});
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -204,6 +211,10 @@ class ShadersBuilder {
|
||||
}),
|
||||
pos: Context.currentPos()
|
||||
});
|
||||
cache = {
|
||||
fields: fields,
|
||||
time: time,
|
||||
};
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user