소스 검색

add Mat2 type (#814)

Monad 5 년 전
부모
커밋
7a0580a098
8개의 변경된 파일28개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 0
      hxsl/AgalOut.hx
  2. 2 0
      hxsl/Ast.hx
  3. 10 0
      hxsl/Checker.hx
  4. 2 0
      hxsl/GlslOut.hx
  5. 9 1
      hxsl/HlslOut.hx
  6. 1 0
      hxsl/MacroParser.hx
  7. 1 1
      hxsl/Macros.hx
  8. 2 1
      hxsl/Serializer.hx

+ 1 - 0
hxsl/AgalOut.hx

@@ -827,6 +827,7 @@ class AgalOut {
 	function regSize( t : Type ) {
 		return switch( t ) {
 		case TInt, TFloat, TVec(_), TBytes(_), TBool: 1;
+		case TMat2: throw "Mat2 is not supported in AGAL";
 		case TMat3, TMat3x4: 3;
 		case TMat4: 4;
 		case TArray(t, SConst(size)), TBuffer(t, SConst(size)): (Tools.size(t) * size + 3) >> 2;

+ 2 - 0
hxsl/Ast.hx

@@ -19,6 +19,7 @@ enum Type {
 	TArray( t : Type, size : SizeDecl );
 	TBuffer( t : Type, size : SizeDecl );
 	TChannel( size : Int );
+	TMat2;
 }
 
 enum VecType {
@@ -500,6 +501,7 @@ class Tools {
 			var s = 0;
 			for( v in vl ) s += size(v.type);
 			return s;
+		case TMat2: 4;
 		case TMat3: 9;
 		case TMat4: 16;
 		case TMat3x4: 12;

+ 10 - 0
hxsl/Checker.hx

@@ -1003,6 +1003,14 @@ class Checker {
 			default:
 				error("Cannot apply " + g.toString() + " to these parameters", pos);
 			}
+		case Mat2:
+			switch( ([for( a in args ) a.t]) ) {
+			case [TMat2]: type = TMat2;
+			case [TVec(2, VFloat), TVec(2, VFloat)]: type = TMat2;
+			case [TFloat, TFloat, TFloat, TFloat]: type = TMat2;
+			default:
+				error("Cannot apply " + g.toString() + " to these parameters", pos);
+			}
 		case Mat3:
 			switch( ([for( a in args ) a.t]) ) {
 			case [TMat3x4 | TMat4]: type = TMat3;
@@ -1114,6 +1122,8 @@ class Checker {
 				vec3;
 			case [OpMult, TVec(3,VFloat), TMat3]:
 				vec3;
+			case [OpMult, TVec(2,VFloat), TMat2]:
+				vec2;
 			case [_, TInt, TInt]: TInt;
 			case [_, TFloat, TFloat]: TFloat;
 			case [_, TInt, TFloat]: toFloat(e1); TFloat;

+ 2 - 0
hxsl/GlslOut.hx

@@ -105,6 +105,8 @@ class GlslOut {
 			}
 			add("vec");
 			add(size);
+		case TMat2:
+			add("mat2");
 		case TMat3:
 			add("mat3");
 		case TMat4:

+ 9 - 1
hxsl/HlslOut.hx

@@ -99,6 +99,8 @@ class HlslOut {
 			case VBool: add("bool");
 			}
 			add(size);
+		case TMat2:
+			add("float2x2");
 		case TMat3:
 			add("float3x3");
 		case TMat4:
@@ -316,6 +318,12 @@ class HlslOut {
 				decl("float3x3 mat3( float4x4 m ) { return (float3x3)m; }");
 				decl("float3x3 mat3( float4x3 m ) { return (float3x3)m; }");
 				decl("float3x3 mat3( float3 a, float3 b, float3 c ) { float3x3 m; m._m00_m10_m20 = a; m._m01_m11_m21 = b; m._m02_m12_m22 = c; return m; }");
+			case Mat2:
+				decl("float2x2 mat2( float4x4 m ) { return (float2x2)m; }");
+				decl("float2x2 mat2( float4x3 m ) { return (float2x2)m; }");
+				decl("float2x2 mat2( float3x3 m ) { return (float2x2)m; }");
+				decl("float2x2 mat2( float2 a, float2 b ) { float2x2 m; m._m00_m10 = a; m._m01_m11 = b; return m; }");
+				decl("float2x2 mat2( float c00, float c01, float c10, float c11 ) { float2x2 m = { c00, c10, c01, c11 }; return m; }");
 			case Mod:
 				declMods();
 			case Pow:
@@ -401,7 +409,7 @@ class HlslOut {
 				add(",1.),");
 				addValue(e2, tabs);
 				add(")");
-			case [OpMult, TVec(_), TMat3 | TMat4]:
+			case [OpMult, TVec(_), TMat2 | TMat3 | TMat4]:
 				add("mul(");
 				addValue(e1, tabs);
 				add(",");

+ 1 - 0
hxsl/MacroParser.hx

@@ -82,6 +82,7 @@ class MacroParser {
 			case "Mat4": return TMat4;
 			case "Mat3": return TMat3;
 			case "Mat3x4": return TMat3x4;
+			case "Mat2": return TMat2;
 			case "String": return TString;
 			case "Sampler2D": return TSampler2D;
 			case "Sampler2DArray": return TSampler2DArray;

+ 1 - 1
hxsl/Macros.hx

@@ -32,7 +32,7 @@ class Macros {
 			macro : hxsl.Types.Sampler2DArray;
 		case TSamplerCube:
 			macro : hxsl.Types.SamplerCube;
-		case TMat3, TMat3x4, TMat4:
+		case TMat2, TMat3, TMat3x4, TMat4:
 			macro : hxsl.Types.Matrix;
 		case TString:
 			macro : String;

+ 2 - 1
hxsl/Serializer.hx

@@ -94,7 +94,7 @@ class Serializer {
 			}
 		case TChannel(size):
 			out.addByte(size);
-		case TVoid, TInt, TBool, TFloat, TString, TMat3, TMat4, TMat3x4, TSampler2D, TSampler2DArray, TSamplerCube:
+		case TVoid, TInt, TBool, TFloat, TString, TMat2, TMat3, TMat4, TMat3x4, TSampler2D, TSampler2DArray, TSamplerCube:
 		}
 	}
 
@@ -141,6 +141,7 @@ class Serializer {
 			TBuffer(t, v == null ? SConst(readVarInt()) : SVar(v));
 		case 17:
 			TChannel(input.readByte());
+		case 18: TMat2;
 		default:
 			throw "assert";
 		}