Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
HlslTypes.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Globalization;
5 using SiliconStudio.Shaders.Ast;
6 
7 namespace SiliconStudio.Shaders.Convertor
8 {
9  public static class HlslTypes
10  {
11  /// <summary>
12  /// Gets the type.
13  /// </summary>
14  /// <param name="type">The type.</param>
15  /// <returns>A Typedeclaration and dimensions</returns>
16  public static Tuple<TypeBase, int, int> GetType(string type)
17  {
18  string prefix = null;
19  if (type.StartsWith("matrix"))
20  {
21  var dimStr = type.Substring("matrix".Length);
22  if (dimStr.Length == 0)
23  {
24  return new Tuple<TypeBase, int, int>(new MatrixType(), 4, 4);
25  }
26 
27  return new Tuple<TypeBase, int, int>(new MatrixType(), int.Parse(dimStr[0].ToString()), int.Parse(dimStr[2].ToString()));
28  }
29 
30  TypeBase declaration = null;
31 
32  if (type.StartsWith("float"))
33  {
34  prefix = "float";
35  declaration = ScalarType.Float;
36  }
37  else if (type.StartsWith("int"))
38  {
39  prefix = "int";
40  declaration = ScalarType.Int;
41  }
42  else if (type.StartsWith("half"))
43  {
44  prefix = "half";
45  declaration = ScalarType.Half;
46  }
47  else if (type.StartsWith("uint"))
48  {
49  prefix = "uint";
50  declaration = ScalarType.UInt;
51  }
52  else if (type.StartsWith("bool"))
53  {
54  prefix = "bool";
55  declaration = ScalarType.Bool;
56  }
57  else if (type.StartsWith("double"))
58  {
59  prefix = "double";
60  declaration = ScalarType.Double;
61  }
62 
63  if (prefix == null)
64  {
65  return null;
66  }
67 
68  return new Tuple<TypeBase, int, int>(declaration, int.Parse(type.Substring(prefix.Length, 1)), 0);
69  }
70  }
71 }
static Tuple< TypeBase, int, int > GetType(string type)
Gets the type.
Definition: HlslTypes.cs:16
SiliconStudio.Paradox.Games.Mathematics.Half Half
Base type for all types.
Definition: TypeBase.cs:11