Browse Source

add Shader.setParamIndexValue to avoid using Reflect for shader animations

trethaller 3 years ago
parent
commit
d56dc6602c
2 changed files with 35 additions and 0 deletions
  1. 27 0
      hxsl/Macros.hx
  2. 8 0
      hxsl/Shader.hx

+ 27 - 0
hxsl/Macros.hx

@@ -309,6 +309,31 @@ class Macros {
 			}),
 			access : [AOverride],
 		});
+		index = 0;
+		fields.push( {
+			name : "setParamIndexValue",
+			pos : pos,
+			kind : FFun( {
+				args : [ { name : "index", type : macro : Int }, { name : "val", type : macro : Dynamic } ],
+				expr : {
+					expr : ESwitch(macro index, [for( p in eparams ) { values : [macro $v{ index++ } ], expr : macro $p = val } ], macro {}),
+					pos : pos,
+				},
+			}),
+			access : [AOverride],
+		});
+		fields.push( {
+			name : "setParamIndexFloatValue",
+			pos : pos,
+			kind : FFun( {
+				args : [ { name : "index", type : macro : Int }, { name : "val", type : macro : Float } ],
+				expr : {
+					expr : ESwitch(macro index, [for( i in 0...tparams.length ) if( tparams[i] == TFloat ) { values : [macro $v{i}], expr : macro ${eparams[i]} = val }], macro {}),
+					pos : pos,
+				},
+			}),
+			access : [AOverride],
+		});
 		if( params.length > 0 ) {
 			var cexpr = [];
 			var type = Context.getLocalClass().toString().split(".").pop();
@@ -385,6 +410,8 @@ class Macros {
 							supFields.remove("updateConstants");
 							supFields.remove("getParamValue");
 							supFields.remove("getParamFloatValue");
+							supFields.remove("setParamValue");
+							supFields.remove("setParamFloatValue");
 							supFields.remove("clone");
 							csup = tsup.superClass;
 						} while( true);

+ 8 - 0
hxsl/Shader.hx

@@ -50,6 +50,14 @@ class Shader {
 		throw "assert"; // will be subclassed in sub shaders
 		return 0.;
 	}
+	
+	public function setParamIndexValue( index : Int, val : Dynamic ) {
+		throw "assert"; // will be subclassed in sub shaders
+	}
+
+	public function setParamIndexFloatValue( index : Int, val : Float ) {
+		throw "assert"; // will be subclassed in sub shaders
+	}
 
 	public function updateConstants( globals : Globals ) {
 		throw "assert";