-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
157 lines (115 loc) · 4.88 KB
/
Utils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#define FXMaths
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX.D3DCompiler;
using SharpDX;
#if FXMaths
using FxMaths.Vector;
#endif
using System.Runtime.InteropServices;
namespace FXFramework
{
public static class Utils
{
/// <summary>
/// Check if the variable type in c# is compatible with the type in shader
/// </summary>
/// <param name="c_sharp_type"></param>
/// <param name="shaderType"></param>
/// <returns></returns>
public static bool CheckCompatibilityOfType<T>( T c_sharp_type, ShaderTypeDescription varDesc ) where T : struct
{
/// check if the class is matrix
if ( varDesc.Class == ShaderVariableClass.MatrixColumns ) {
#region SharpDX Matrix
if ( c_sharp_type is Matrix ) {
return ( varDesc.Type == ShaderVariableType.Float );
}
#endregion
}
/// check if is vector
if ( varDesc.Class == ShaderVariableClass.Vector ) {
#region SharpDX vectors
if ( c_sharp_type is Vector2 ) {
return (varDesc.Type == ShaderVariableType.Float) && varDesc.ColumnCount == 2;
}
if ( c_sharp_type is Vector3 ) {
return (varDesc.Type == ShaderVariableType.Float) && varDesc.ColumnCount == 3;
}
if ( c_sharp_type is Vector4 ) {
return (varDesc.Type == ShaderVariableType.Float) && varDesc.ColumnCount == 4;
}
#endregion
#if FXMaths
#region FxVector float
if ( c_sharp_type is FxVector2f ) {
return (varDesc.Type == ShaderVariableType.Float) && varDesc.ColumnCount == 2;
}
if ( c_sharp_type is FxVector3f ) {
return (varDesc.Type == ShaderVariableType.Float) && varDesc.ColumnCount == 3;
}
if ( c_sharp_type is FxVector4f ) {
return (varDesc.Type == ShaderVariableType.Float) && varDesc.ColumnCount == 4;
}
#endregion
#region FxVector int
if ( c_sharp_type is FxVector2i ) {
return (varDesc.Type == ShaderVariableType.Int) && varDesc.ColumnCount == 2;
}
if ( c_sharp_type is FxVector3i ) {
return (varDesc.Type == ShaderVariableType.Int) && varDesc.ColumnCount == 3;
}
if ( c_sharp_type is FxVector4i ) {
return (varDesc.Type == ShaderVariableType.Int) && varDesc.ColumnCount == 4;
}
#endregion
#region FxVector float
if ( c_sharp_type is FxVector2b ) {
return (varDesc.Type == ShaderVariableType.UInt8) && varDesc.ColumnCount == 2;
}
if ( c_sharp_type is FxVector3b ) {
return (varDesc.Type == ShaderVariableType.UInt8) && varDesc.ColumnCount == 3;
}
if ( c_sharp_type is FxVector4b ) {
return (varDesc.Type == ShaderVariableType.UInt8) && varDesc.ColumnCount == 4;
}
#endregion
#endif
}
/// check if the class is scalar
if ( varDesc.Class == ShaderVariableClass.Scalar ) {
#region c# scalar
// find the type of variable
if ( c_sharp_type is int || c_sharp_type is Int32 ) {
return ( varDesc.Type == ShaderVariableType.Int );
}
if ( c_sharp_type is float) {
return ( varDesc.Type == ShaderVariableType.Float );
}
if ( c_sharp_type is double ) {
return ( varDesc.Type == ShaderVariableType.Double );
}
if ( c_sharp_type is uint ) {
return ( varDesc.Type == ShaderVariableType.UInt );
}
if ( c_sharp_type is byte) {
return ( varDesc.Type == ShaderVariableType.UInt8 );
}
#endregion
}
if ( varDesc.Class == ShaderVariableClass.Struct ) {
// get the size of the struct of c#
int size = Marshal.SizeOf( typeof( T ) )/4; // in 4byte form
// check the size
if (size == varDesc.ColumnCount)
return true;
else
return false;
}
throw new System.ApplicationException( "The type is not exist in the function.... something is not right!!!" );
return false;
}
}
}