Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
VectorType.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 
5 namespace SiliconStudio.Shaders.Ast
6 {
7  /// <summary>
8  /// Base class for all vector types
9  /// </summary>
10  public class VectorType : GenericType<TypeBase, Literal>
11  {
12  #region Constants and Fields
13 
14  /// <summary>
15  /// A Int2
16  /// </summary>
17  public static readonly VectorType Int2 = new VectorType(ScalarType.Int, 2);
18 
19  /// <summary>
20  /// A Int3
21  /// </summary>
22  public static readonly VectorType Int3 = new VectorType(ScalarType.Int, 3);
23 
24  /// <summary>
25  /// A Int4
26  /// </summary>
27  public static readonly VectorType Int4 = new VectorType(ScalarType.Int, 4);
28 
29  /// <summary>
30  /// A UInt2
31  /// </summary>
32  public static readonly VectorType UInt2 = new VectorType(ScalarType.UInt, 2);
33 
34  /// <summary>
35  /// A UInt3
36  /// </summary>
37  public static readonly VectorType UInt3 = new VectorType(ScalarType.UInt, 3);
38 
39  /// <summary>
40  /// A UInt4
41  /// </summary>
42  public static readonly VectorType UInt4 = new VectorType(ScalarType.UInt, 4);
43 
44  /// <summary>
45  /// A Float2
46  /// </summary>
47  public static readonly VectorType Float2 = new VectorType(ScalarType.Float, 2);
48 
49  /// <summary>
50  /// A Float3
51  /// </summary>
52  public static readonly VectorType Float3 = new VectorType(ScalarType.Float, 3);
53 
54  /// <summary>
55  /// A Float4
56  /// </summary>
57  public static readonly VectorType Float4 = new VectorType(ScalarType.Float, 4);
58 
59  /// <summary>
60  /// A Double2
61  /// </summary>
62  public static readonly VectorType Double2 = new VectorType(ScalarType.Double, 2);
63 
64  /// <summary>
65  /// A Double3
66  /// </summary>
67  public static readonly VectorType Double3 = new VectorType(ScalarType.Double, 3);
68 
69  /// <summary>
70  /// A Double4
71  /// </summary>
72  public static readonly VectorType Double4 = new VectorType(ScalarType.Double, 4);
73 
74 
75  #endregion
76 
77  #region Constructors and Destructors
78 
79  /// <summary>
80  /// Initializes a new instance of the <see cref = "VectorType" /> class.
81  /// </summary>
82  public VectorType()
83  : base("vector")
84  {
85  }
86 
87  /// <summary>
88  /// Initializes a new instance of the <see cref="VectorType"/> class.
89  /// </summary>
90  /// <param name="type">
91  /// The type.
92  /// </param>
93  /// <param name="dimension">
94  /// The dimension.
95  /// </param>
96  public VectorType(ScalarType type, int dimension)
97  : this()
98  {
99  Type = type;
100  Dimension = dimension;
101  }
102 
103  #endregion
104 
105  #region Public Properties
106 
107  /// <summary>
108  /// Gets or sets the dimension.
109  /// </summary>
110  /// <value>
111  /// The dimension.
112  /// </value>
113  public int Dimension
114  {
115  get
116  {
117  return (int)((Literal)Parameters[1]).Value;
118  }
119 
120  set
121  {
122  Parameters[1] = new Literal(value);
123  }
124  }
125 
126  /// <summary>
127  /// Gets or sets the type.
128  /// </summary>
129  /// <value>
130  /// The type.
131  /// </value>
132  public TypeBase Type
133  {
134  get
135  {
136  return (TypeBase)Parameters[0];
137  }
138 
139  set
140  {
141  Parameters[0] = value;
142  }
143  }
144 
145  #endregion
146 
147  /// <inheritdoc/>
148  public bool Equals(VectorType other)
149  {
150  return base.Equals(other);
151  }
152 
153  /// <inheritdoc/>
154  public override bool Equals(object obj)
155  {
156  if (ReferenceEquals(null, obj))
157  {
158  return false;
159  }
160  if (ReferenceEquals(this, obj))
161  {
162  return true;
163  }
164  return Equals(obj as VectorType);
165  }
166 
167  /// <inheritdoc/>
168  public override int GetHashCode()
169  {
170  return base.GetHashCode();
171  }
172 
173  /// <summary>
174  /// Implements the operator ==.
175  /// </summary>
176  /// <param name="left">The left.</param>
177  /// <param name="right">The right.</param>
178  /// <returns>
179  /// The result of the operator.
180  /// </returns>
181  public static bool operator ==(VectorType left, VectorType right)
182  {
183  return Equals(left, right);
184  }
185 
186  /// <summary>
187  /// Implements the operator !=.
188  /// </summary>
189  /// <param name="left">The left.</param>
190  /// <param name="right">The right.</param>
191  /// <returns>
192  /// The result of the operator.
193  /// </returns>
194  public static bool operator !=(VectorType left, VectorType right)
195  {
196  return !Equals(left, right);
197  }
198  }
199 }
Base class for all vector types
Definition: VectorType.cs:10
override bool Equals(object obj)
Definition: VectorType.cs:154
static readonly ScalarType Int
Scalar int.
Definition: ScalarType.cs:37
VectorType()
Initializes a new instance of the VectorType class.
Definition: VectorType.cs:82
static readonly ScalarType UInt
Scalar unsigned int.
Definition: ScalarType.cs:42
static readonly ScalarType Float
Sclar float.
Definition: ScalarType.cs:27
VectorType(ScalarType type, int dimension)
Initializes a new instance of the VectorType class.
Definition: VectorType.cs:96
Base type for all types.
Definition: TypeBase.cs:11
static readonly ScalarType Double
Scalar double.
Definition: ScalarType.cs:22
Base class for all generic types.
Definition: GenericType.cs:14
bool Equals(VectorType other)
Definition: VectorType.cs:148
A field of a struct.
Definition: Literal.cs:13