ShaderType.hx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package hrt.shgraph;
  2. import hxsl.Ast.Type;
  3. enum SType {
  4. /** Bool **/
  5. Bool;
  6. /** Vector of bools of size 2 **/
  7. VecBool2;
  8. /** Vector of bools of size 3 **/
  9. VecBool3;
  10. /** Vector of bools of size 4 **/
  11. VecBool4;
  12. /** Float **/
  13. Float;
  14. /** Vector of size 2 **/
  15. Vec2;
  16. /** Vector of size 3 **/
  17. Vec3;
  18. /** Vector of size 4 **/
  19. Vec4;
  20. /** Float or Vectors **/
  21. Number;
  22. /** Texture **/
  23. Sampler;
  24. /** Any **/
  25. Variant;
  26. }
  27. class ShaderType {
  28. static public function getType(type : SType) : hxsl.Type {
  29. switch (type) {
  30. case Vec2:
  31. return TVec(2, VFloat);
  32. case Vec3:
  33. return TVec(3, VFloat);
  34. case Vec4:
  35. return TVec(4, VFloat);
  36. case VecBool2:
  37. return TVec(2, VBool);
  38. case VecBool3:
  39. return TVec(3, VBool);
  40. case VecBool4:
  41. return TVec(4, VBool);
  42. case Bool:
  43. return TBool;
  44. case Float:
  45. return TFloat;
  46. case Sampler:
  47. return TSampler2D;
  48. default:
  49. }
  50. return null;
  51. }
  52. static public function getSType(type : hxsl.Type) : SType {
  53. switch (type) {
  54. case TVec(2, VFloat):
  55. return Vec2;
  56. case TVec(3, VFloat):
  57. return Vec3;
  58. case TVec(4, VFloat):
  59. return Vec4;
  60. case TVec(2, VBool):
  61. return VecBool2;
  62. case TVec(3, VBool):
  63. return VecBool3;
  64. case TVec(4, VBool):
  65. return VecBool4;
  66. case TBool:
  67. return Bool;
  68. case TFloat:
  69. return Float;
  70. case TSampler2D:
  71. return Sampler;
  72. default:
  73. }
  74. return Variant;
  75. }
  76. static public function checkCompatibilities (a : SType, b : SType) : Bool {
  77. return (checkConversion(a, b) || checkConversion(b, a));
  78. }
  79. static public function checkConversion(from : SType, to : SType) {
  80. switch (to) {
  81. case Vec2:
  82. return (from == Float || from == Vec2);
  83. case Vec3:
  84. return (from == Float || from == Vec2 || from == Vec3);
  85. case Vec4:
  86. return (from == Float || from == Vec2 || from == Vec3 || from == Vec4);
  87. case Bool:
  88. return (from == Bool);
  89. case VecBool2:
  90. return (from == Bool || from == VecBool2);
  91. case VecBool3:
  92. return (from == Bool || from == VecBool3);
  93. case VecBool4:
  94. return (from == Bool || from == VecBool4);
  95. case Float:
  96. return (from == Float);
  97. case Number:
  98. return (from == Float || from == Vec2 || from == Vec3 || from == Vec4);
  99. case Sampler:
  100. return (from == Sampler);
  101. case Variant:
  102. return true;
  103. default:
  104. return false;
  105. }
  106. }
  107. }