@@ -15,7 +15,7 @@ public ShaderTypeGenerator(Type type, GenerateHLSL attr)
1515
1616 enum PrimitiveType
1717 {
18- Float , Int , UInt
18+ Float , Int , UInt , Bool
1919 } ;
2020
2121 static string PrimitiveToString ( PrimitiveType type , int rows , int cols )
@@ -32,6 +32,9 @@ static string PrimitiveToString(PrimitiveType type, int rows, int cols)
3232 case PrimitiveType . UInt :
3333 text = "uint" ;
3434 break ;
35+ case PrimitiveType . Bool :
36+ text = "bool" ;
37+ break ;
3538 }
3639
3740 if ( rows > 1 )
@@ -171,8 +174,9 @@ void EmitMatrixType(PrimitiveType type, int rows, int cols, string name, string
171174 bool ExtractComplex ( FieldInfo field , List < ShaderFieldInfo > shaderFields )
172175 {
173176 var floatFields = new List < FieldInfo > ( ) ;
174- var intFields = new List < FieldInfo > ( ) ;
175- var uintFields = new List < FieldInfo > ( ) ;
177+ var intFields = new List < FieldInfo > ( ) ;
178+ var uintFields = new List < FieldInfo > ( ) ;
179+ var boolFields = new List < FieldInfo > ( ) ;
176180 var descs = new string [ 4 ] { "x: " , "y: " , "z: " , "w: " } ;
177181 int numFields = 0 ;
178182
@@ -194,6 +198,8 @@ bool ExtractComplex(FieldInfo field, List<ShaderFieldInfo> shaderFields)
194198 intFields . Add ( subField ) ;
195199 else if ( subField . FieldType == typeof ( uint ) )
196200 uintFields . Add ( subField ) ;
201+ else if ( subField . FieldType == typeof ( bool ) )
202+ boolFields . Add ( subField ) ;
197203 else
198204 {
199205 Error ( "'" + fieldName + "' can not be packed into a register, since it contains an unsupported field type '" + subField . FieldType + "'" ) ;
@@ -216,7 +222,7 @@ bool ExtractComplex(FieldInfo field, List<ShaderFieldInfo> shaderFields)
216222
217223 if ( floatFields . Count > 0 )
218224 {
219- if ( intFields . Count + uintFields . Count > 0 )
225+ if ( intFields . Count + uintFields . Count + boolFields . Count > 0 )
220226 {
221227 Error ( mismatchErrorMsg ) ;
222228 return false ;
@@ -225,7 +231,7 @@ bool ExtractComplex(FieldInfo field, List<ShaderFieldInfo> shaderFields)
225231 }
226232 else if ( intFields . Count > 0 )
227233 {
228- if ( floatFields . Count + uintFields . Count > 0 )
234+ if ( floatFields . Count + uintFields . Count + boolFields . Count > 0 )
229235 {
230236 Error ( mismatchErrorMsg ) ;
231237 return false ;
@@ -234,13 +240,22 @@ bool ExtractComplex(FieldInfo field, List<ShaderFieldInfo> shaderFields)
234240 }
235241 else if ( uintFields . Count > 0 )
236242 {
237- if ( floatFields . Count + intFields . Count > 0 )
243+ if ( floatFields . Count + intFields . Count + boolFields . Count > 0 )
238244 {
239245 Error ( mismatchErrorMsg ) ;
240246 return false ;
241247 }
242248 EmitPrimitiveType ( PrimitiveType . UInt , uintFields . Count , field . Name , "" , shaderFields ) ;
243249 }
250+ else if ( boolFields . Count > 0 )
251+ {
252+ if ( floatFields . Count + intFields . Count + uintFields . Count > 0 )
253+ {
254+ Error ( mismatchErrorMsg ) ;
255+ return false ;
256+ }
257+ EmitPrimitiveType ( PrimitiveType . Bool , boolFields . Count , field . Name , "" , shaderFields ) ;
258+ }
244259 else
245260 {
246261 // Empty struct.
@@ -476,6 +491,8 @@ public bool Generate()
476491 EmitPrimitiveType ( PrimitiveType . Int , 1 , field . Name , "" , m_ShaderFields ) ;
477492 else if ( field . FieldType == typeof ( uint ) )
478493 EmitPrimitiveType ( PrimitiveType . UInt , 1 , field . Name , "" , m_ShaderFields ) ;
494+ else if ( field . FieldType == typeof ( bool ) )
495+ EmitPrimitiveType ( PrimitiveType . Bool , 1 , field . Name , "" , m_ShaderFields ) ;
479496 else
480497 {
481498 Error ( "unsupported field type '" + field . FieldType + "'" ) ;
0 commit comments