Operation.hx 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package hrt.shgraph;
  2. using hxsl.Ast;
  3. class Operation extends ShaderNode {
  4. @input("A", true) var a = SType.Number;
  5. @input("B", true) var b = SType.Number;
  6. @output("") var output = SType.Number;
  7. var operation : Binop;
  8. public function new(operation : Binop) {
  9. this.operation = operation;
  10. }
  11. override public function computeOutputs() {
  12. if (a != null && !a.isEmpty() && b != null && !b.isEmpty())
  13. addOutput("output", a.getVar(b.getType()).t);
  14. else if (a != null && !a.isEmpty() )
  15. addOutput("output", a.getType());
  16. else if (b != null && !b.isEmpty())
  17. addOutput("output", b.getType());
  18. else
  19. removeOutput("output");
  20. }
  21. override public function build(key : String) : TExpr {
  22. return { e: TBinop(OpAssign, {
  23. e: TVar(output),
  24. p: null,
  25. t: output.type
  26. }, {
  27. e: TBinop(operation,
  28. a.getVar(b.getType()),
  29. b.getVar(a.getType())),
  30. p: null,
  31. t: output.type
  32. }),
  33. p: null,
  34. t: output.type
  35. };
  36. }
  37. }