Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
VertexElement.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 //
4 // Copyright (c) 2010-2012 SharpDX - Alexandre Mutel
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 
24 using System;
25 using System.Globalization;
26 using System.Text.RegularExpressions;
27 using SiliconStudio.Core;
28 using SiliconStudio.Core.Mathematics;
29 using SiliconStudio.Core.Serialization;
30 using SiliconStudio.Core.Serialization.Serializers;
31 
32 namespace SiliconStudio.Paradox.Graphics
33 {
34  /// <summary>
35  /// A description of a single element for the input-assembler stage. This structure is related to <see cref="Direct3D11.InputElement"/>.
36  /// </summary>
37  /// <remarks>
38  /// Because <see cref="Direct3D11.InputElement"/> requires to have the same <see cref="VertexBufferLayout.SlotIndex"/>, <see cref="VertexBufferLayout.VertexClassification"/> and <see cref="VertexBufferLayout.instanceDataStepRate"/>,
39  /// the <see cref="VertexBufferLayout"/> structure encapsulates a set of <see cref="VertexElement"/> for a particular slot, classification and instance data step rate.
40  /// Unlike the default <see cref="Direct3D11.InputElement"/>, this structure accepts a semantic name with a postfix number that will be automatically extracted to the semantic index.
41  /// </remarks>
42  /// <seealso cref="VertexBufferLayout"/>
43  [DataContract]
44  [DataSerializer(typeof(Serializer))]
45  public struct VertexElement : IEquatable<VertexElement>
46  {
47  internal string semanticName;
48 
49  internal int semanticIndex;
50 
51  internal PixelFormat format;
52 
53  internal int alignedByteOffset;
54 
55  internal int hashCode;
56 
57  // Match the last digit of a semantic name.
58  internal static readonly Regex MatchSemanticIndex = new Regex(@"(.*)(\d+)$");
59 
60  /// <summary>
61  /// Returns a value that can be used for the offset parameter of an InputElement to indicate that the element
62  /// should be aligned directly after the previous element, including any packing if neccessary.
63  /// </summary>
64  /// <returns>A value used to align input elements.</returns>
65  public const int AppendAligned = -1;
66 
67  /// <summary>
68  /// Initializes a new instance of the <see cref="VertexElement" /> struct.
69  /// </summary>
70  /// <param name="semanticName">Name of the semantic.</param>
71  /// <param name="format">The format.</param>
72  /// <remarks>
73  /// If the semantic name contains a postfix number, this number will be used as a semantic index.
74  /// </remarks>
75  public VertexElement(string semanticName, PixelFormat format)
76  : this()
77  {
78  if (semanticName == null)
79  throw new ArgumentNullException("semanticName");
80 
81  // All semantics will be upper case.
82  semanticName = semanticName.ToUpperInvariant();
83 
84  var match = MatchSemanticIndex.Match(semanticName);
85  if (match.Success)
86  {
87  // Convert to singleton string in order to speed up things.
88  this.semanticName = match.Groups[1].Value;
89  semanticIndex = int.Parse(match.Groups[2].Value);
90  }
91  else
92  {
93  this.semanticName = semanticName;
94  }
95 
96  this.format = format;
97  alignedByteOffset = AppendAligned;
98 
99  // Precalculate hashcode
100  hashCode = ComputeHashCode();
101  }
102 
103  /// <summary>
104  /// Initializes a new instance of the <see cref="VertexElement" /> struct.
105  /// </summary>
106  /// <param name="semanticName">Name of the semantic.</param>
107  /// <param name="semanticIndex">Index of the semantic.</param>
108  /// <param name="format">The format.</param>
109  /// <param name="alignedByteOffset">The aligned byte offset.</param>
110  public VertexElement(string semanticName, int semanticIndex, PixelFormat format, int alignedByteOffset = AppendAligned)
111  : this()
112  {
113  if (semanticName == null)
114  throw new ArgumentNullException("semanticName");
115 
116  // All semantics will be upper case.
117  semanticName = semanticName.ToUpperInvariant();
118 
119  var match = MatchSemanticIndex.Match(semanticName);
120  if (match.Success)
121  throw new ArgumentException("Semantic name cannot a semantic index when using constructor with explicit semantic index. Use implicit semantic index constructor.");
122 
123  // Convert to singleton string in order to speed up things.
124  this.semanticName = semanticName;
125  this.semanticIndex = semanticIndex;
126  this.format = format;
127  this.alignedByteOffset = alignedByteOffset;
128 
129  // Precalculate hashcode
130  hashCode = ComputeHashCode();
131  }
132 
133  /// <summary>
134  /// <dd> <p>The HLSL semantic associated with this element in a shader input-signature.</p> </dd>
135  /// </summary>
136  public string SemanticName
137  {
138  get
139  {
140  return semanticName;
141  }
142  }
143 
144  /// <summary>
145  /// <dd> <p>The HLSL semantic associated with this element in a shader input-signature.</p> </dd>
146  /// </summary>
147  public string SemanticAsText
148  {
149  get
150  {
151  if (semanticIndex == 0)
152  return semanticName;
153  return string.Format("{0}{1}", semanticName, semanticIndex.ToString(CultureInfo.InvariantCulture));
154  }
155  }
156 
157  /// <summary>
158  /// <dd> <p>The semantic index for the element. A semantic index modifies a semantic, with an integer index number. A semantic index is only needed in a case where there is more than one element with the same semantic. For example, a 4x4 matrix would have four components each with the semantic name </p> <pre><code>matrix</code></pre> <p>, however each of the four component would have different semantic indices (0, 1, 2, and 3).</p> </dd>
159  /// </summary>
160  public int SemanticIndex
161  {
162  get
163  {
164  return semanticIndex;
165  }
166  }
167 
168  /// <summary>
169  /// <dd> <p>The data type of the element data. See <strong><see cref="SharpDX.DXGI.Format"/></strong>.</p> </dd>
170  /// </summary>
171  public PixelFormat Format
172  {
173  get
174  {
175  return format;
176  }
177  }
178 
179  /// <summary>
180  /// <dd> <p>Optional. Offset (in bytes) between each element. Use D3D11_APPEND_ALIGNED_ELEMENT for convenience to define the current element directly after the previous one, including any packing if necessary.</p> </dd>
181  /// </summary>
182  public int AlignedByteOffset
183  {
184  get
185  {
186  return alignedByteOffset;
187  }
188  }
189 
190  public bool Equals(VertexElement other)
191  {
192  // First use hashCode to compute
193  return hashCode == other.hashCode && semanticName.Equals(other.semanticName) && semanticIndex == other.semanticIndex && format == other.format && alignedByteOffset == other.alignedByteOffset;
194  }
195 
196  public override bool Equals(object obj)
197  {
198  if (ReferenceEquals(null, obj)) return false;
199  return obj is VertexElement && Equals((VertexElement)obj);
200  }
201 
202  public override int GetHashCode()
203  {
204  return hashCode;
205  }
206 
207  internal int ComputeHashCode()
208  {
209  unchecked
210  {
211  int localHashCode = semanticName.GetHashCode();
212  localHashCode = (localHashCode * 397) ^ semanticIndex;
213  localHashCode = (localHashCode * 397) ^ format.GetHashCode();
214  localHashCode = (localHashCode * 397) ^ alignedByteOffset;
215  return localHashCode;
216  }
217  }
218 
219  public static bool operator ==(VertexElement left, VertexElement right)
220  {
221  return left.Equals(right);
222  }
223 
224  public static bool operator !=(VertexElement left, VertexElement right)
225  {
226  return !left.Equals(right);
227  }
228 
229  public override string ToString()
230  {
231  return string.Format("{0}{1},{2},{3}", semanticName, semanticIndex == 0 ? string.Empty : string.Empty + semanticIndex, format, alignedByteOffset);
232  }
233 
234  /// <summary>
235  /// Declares a VertexElement with the semantic "COLOR".
236  /// </summary>
237  /// <typeparam name="T">Type of the Color semantic.</typeparam>
238  /// <param name="semanticIndex">The semantic index.</param>
239  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
240  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
241  public static VertexElement Color<T>(int semanticIndex = 0, int offsetInBytes = AppendAligned) where T : struct
242  {
243  return Color(semanticIndex, ConvertTypeToFormat<T>(), offsetInBytes);
244  }
245 
246  /// <summary>
247  /// Declares a VertexElement with the semantic "COLOR".
248  /// </summary>
249  /// <param name="format">Format of this element.</param>
250  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
251  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
252  public static VertexElement Color(PixelFormat format, int offsetInBytes = AppendAligned)
253  {
254  return Color(0, format, offsetInBytes);
255  }
256 
257  /// <summary>
258  /// Declares a VertexElement with the semantic "COLOR".
259  /// </summary>
260  /// <param name="semanticIndex">The semantic index.</param>
261  /// <param name="format">Format of this element.</param>
262  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
263  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
264  public static VertexElement Color(int semanticIndex, PixelFormat format, int offsetInBytes = AppendAligned)
265  {
266  return new VertexElement("COLOR", semanticIndex, format, offsetInBytes);
267  }
268 
269  /// <summary>
270  /// Declares a VertexElement with the semantic "NORMAL".
271  /// </summary>
272  /// <typeparam name="T">Type of the Normal semantic.</typeparam>
273  /// <param name="semanticIndex">The semantic index.</param>
274  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
275  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
276  public static VertexElement Normal<T>(int semanticIndex = 0, int offsetInBytes = AppendAligned) where T : struct
277  {
278  return Normal(semanticIndex, ConvertTypeToFormat<T>(), offsetInBytes);
279  }
280 
281  /// <summary>
282  /// Declares a VertexElement with the semantic "NORMAL".
283  /// </summary>
284  /// <param name="format">Format of this element.</param>
285  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
286  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
287  public static VertexElement Normal(PixelFormat format, int offsetInBytes = AppendAligned)
288  {
289  return Normal(0, format, offsetInBytes);
290  }
291 
292  /// <summary>
293  /// Declares a VertexElement with the semantic "NORMAL".
294  /// </summary>
295  /// <param name="semanticIndex">The semantic index.</param>
296  /// <param name="format">Format of this element.</param>
297  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
298  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
299  public static VertexElement Normal(int semanticIndex, PixelFormat format, int offsetInBytes = AppendAligned)
300  {
301  return new VertexElement("NORMAL", semanticIndex, format, offsetInBytes);
302  }
303 
304  /// <summary>
305  /// Declares a VertexElement with the semantic "POSITION".
306  /// </summary>
307  /// <typeparam name="T">Type of the Position semantic.</typeparam>
308  /// <param name="semanticIndex">The semantic index.</param>
309  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
310  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
311  public static VertexElement Position<T>(int semanticIndex = 0, int offsetInBytes = AppendAligned) where T : struct
312  {
313  return Position(semanticIndex, ConvertTypeToFormat<T>(), offsetInBytes);
314  }
315 
316  /// <summary>
317  /// Declares a VertexElement with the semantic "POSITION".
318  /// </summary>
319  /// <param name="format">Format of this element.</param>
320  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
321  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
322  public static VertexElement Position(PixelFormat format, int offsetInBytes = AppendAligned)
323  {
324  return Position(0, format, offsetInBytes);
325  }
326 
327  /// <summary>
328  /// Declares a VertexElement with the semantic "POSITION".
329  /// </summary>
330  /// <param name="semanticIndex">The semantic index.</param>
331  /// <param name="format">Format of this element.</param>
332  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
333  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
334  public static VertexElement Position(int semanticIndex, PixelFormat format, int offsetInBytes = AppendAligned)
335  {
336  return new VertexElement("POSITION", semanticIndex, format, offsetInBytes);
337  }
338 
339  /// <summary>
340  /// Declares a VertexElement with the semantic "SV_POSITION".
341  /// </summary>
342  /// <typeparam name="T">Type of the PositionTransformed semantic.</typeparam>
343  /// <param name="semanticIndex">The semantic index.</param>
344  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
345  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
346  public static VertexElement PositionTransformed<T>(int semanticIndex = 0, int offsetInBytes = AppendAligned) where T : struct
347  {
348  return PositionTransformed(semanticIndex, ConvertTypeToFormat<T>(), offsetInBytes);
349  }
350 
351  /// <summary>
352  /// Declares a VertexElement with the semantic "SV_POSITION".
353  /// </summary>
354  /// <param name="format">Format of this element.</param>
355  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
356  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
357  public static VertexElement PositionTransformed(PixelFormat format, int offsetInBytes = AppendAligned)
358  {
359  return PositionTransformed(0, format, offsetInBytes);
360  }
361 
362  /// <summary>
363  /// Declares a VertexElement with the semantic "SV_POSITION".
364  /// </summary>
365  /// <param name="semanticIndex">The semantic index.</param>
366  /// <param name="format">Format of this element.</param>
367  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
368  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
369  public static VertexElement PositionTransformed(int semanticIndex, PixelFormat format, int offsetInBytes = AppendAligned)
370  {
371  return new VertexElement("SV_POSITION", semanticIndex, format, offsetInBytes);
372  }
373 
374  /// <summary>
375  /// Declares a VertexElement with the semantic "TEXCOORD".
376  /// </summary>
377  /// <typeparam name="T">Type of the TextureCoordinate semantic.</typeparam>
378  /// <param name="semanticIndex">The semantic index.</param>
379  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
380  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
381  public static VertexElement TextureCoordinate<T>(int semanticIndex = 0, int offsetInBytes = AppendAligned) where T : struct
382  {
383  return TextureCoordinate(semanticIndex, ConvertTypeToFormat<T>(), offsetInBytes);
384  }
385 
386  /// <summary>
387  /// Declares a VertexElement with the semantic "TEXCOORD".
388  /// </summary>
389  /// <param name="format">Format of this element.</param>
390  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
391  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
392  public static VertexElement TextureCoordinate(PixelFormat format, int offsetInBytes = AppendAligned)
393  {
394  return TextureCoordinate(0, format, offsetInBytes);
395  }
396 
397  /// <summary>
398  /// Declares a VertexElement with the semantic "TEXCOORD".
399  /// </summary>
400  /// <param name="semanticIndex">The semantic index.</param>
401  /// <param name="format">Format of this element.</param>
402  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
403  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
404  public static VertexElement TextureCoordinate(int semanticIndex, PixelFormat format, int offsetInBytes = AppendAligned)
405  {
406  return new VertexElement("TEXCOORD", semanticIndex, format, offsetInBytes);
407  }
408 
409  /// <summary>
410  /// Declares a VertexElement with the semantic "TANGENT".
411  /// </summary>
412  /// <typeparam name="T">Type of the Tangent semantic.</typeparam>
413  /// <param name="semanticIndex">The semantic index.</param>
414  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
415  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
416  public static VertexElement Tangent<T>(int semanticIndex = 0, int offsetInBytes = AppendAligned) where T : struct
417  {
418  return Tangent(semanticIndex, ConvertTypeToFormat<T>(), offsetInBytes);
419  }
420 
421  /// <summary>
422  /// Declares a VertexElement with the semantic "TANGENT".
423  /// </summary>
424  /// <param name="format">Format of this element.</param>
425  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
426  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
427  public static VertexElement Tangent(PixelFormat format, int offsetInBytes = AppendAligned)
428  {
429  return Tangent(0, format, offsetInBytes);
430  }
431 
432  /// <summary>
433  /// Declares a VertexElement with the semantic "TANGENT".
434  /// </summary>
435  /// <param name="semanticIndex">The semantic index.</param>
436  /// <param name="format">Format of this element.</param>
437  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
438  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
439  public static VertexElement Tangent(int semanticIndex, PixelFormat format, int offsetInBytes = AppendAligned)
440  {
441  return new VertexElement("TANGENT", semanticIndex, format, offsetInBytes);
442  }
443 
444  /// <summary>
445  /// Declares a VertexElement with the semantic "BITANGENT".
446  /// </summary>
447  /// <typeparam name="T">Type of the BiTangent semantic.</typeparam>
448  /// <param name="semanticIndex">The semantic index.</param>
449  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
450  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
451  public static VertexElement BiTangent<T>(int semanticIndex = 0, int offsetInBytes = AppendAligned) where T : struct
452  {
453  return BiTangent(semanticIndex, ConvertTypeToFormat<T>(), offsetInBytes);
454  }
455 
456  /// <summary>
457  /// Declares a VertexElement with the semantic "BITANGENT".
458  /// </summary>
459  /// <param name="format">Format of this element.</param>
460  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
461  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
462  public static VertexElement BiTangent(PixelFormat format, int offsetInBytes = AppendAligned)
463  {
464  return BiTangent(0, format, offsetInBytes);
465  }
466 
467  /// <summary>
468  /// Declares a VertexElement with the semantic "BITANGENT".
469  /// </summary>
470  /// <param name="semanticIndex">The semantic index.</param>
471  /// <param name="format">Format of this element.</param>
472  /// <param name="offsetInBytes">The offset in bytes of this element. Use <see cref="AppendAligned"/> to compute automatically the offset from previous elements.</param>
473  /// <returns>A new instance of <see cref="VertexElement" /> that represents this semantic.</returns>
474  public static VertexElement BiTangent(int semanticIndex, PixelFormat format, int offsetInBytes = AppendAligned)
475  {
476  return new VertexElement("BITANGENT", semanticIndex, format, offsetInBytes);
477  }
478 
479  private static PixelFormat ConvertTypeToFormat<T>() where T : struct
480  {
481  return ConvertTypeToFormat(typeof(T));
482  }
483 
484  /// <summary>
485  /// Converts a type to a <see cref="SharpDX.DXGI.Format"/>.
486  /// </summary>
487  /// <param name="typeT">The type T.</param>
488  /// <returns>The equivalent Format.</returns>
489  /// <exception cref="System.NotSupportedException">If the convertion for this type is not supported.</exception>
490  private static PixelFormat ConvertTypeToFormat(Type typeT)
491  {
492  if (typeof(Vector4) == typeT || typeof(Color4) == typeT)
493  return PixelFormat.R32G32B32A32_Float;
494  if (typeof(Vector3) == typeT || typeof(Color3) == typeT)
495  return PixelFormat.R32G32B32_Float;
496  if (typeof(Vector2) == typeT)
497  return PixelFormat.R32G32_Float;
498  if (typeof(float) == typeT)
499  return PixelFormat.R32_Float;
500 
501  if (typeof(Color) == typeT)
502  return PixelFormat.R8G8B8A8_UNorm;
503  if (typeof(ColorBGRA) == typeT)
504  return PixelFormat.B8G8R8A8_UNorm;
505 
506  if (typeof(Half4) == typeT)
507  return PixelFormat.R16G16B16A16_Float;
508  if (typeof(Half2) == typeT)
509  return PixelFormat.R16G16_Float;
510  if (typeof(Half) == typeT)
511  return PixelFormat.R16_Float;
512 
513  if (typeof(Int4) == typeT)
514  return PixelFormat.R32G32B32A32_UInt;
515  if (typeof(Int3) == typeT)
516  return PixelFormat.R32G32B32_UInt;
517  if (typeof(int) == typeT)
518  return PixelFormat.R32_UInt;
519  if (typeof(uint) == typeT)
520  return PixelFormat.R32_UInt;
521 
522  //if (typeof(Bool4) == typeT)
523  // return PixelFormat.R32G32B32A32_UInt;
524 
525  //if (typeof(Bool) == typeT)
526  // return PixelFormat.R32_UInt;
527 
528  throw new NotSupportedException(string.Format("Type [{0}] is not supported. You must specify an explicit DXGI.Format", typeT.Name));
529  }
530 
531  internal class Serializer : DataSerializer<VertexElement>
532  {
533  public override void Serialize(ref VertexElement obj, ArchiveMode mode, SerializationStream stream)
534  {
535  if (mode == ArchiveMode.Deserialize)
536  {
537  obj.semanticName = stream.ReadString();
538  obj.semanticIndex = stream.ReadInt32();
539  obj.format = stream.Read<PixelFormat>();
540  obj.alignedByteOffset = stream.ReadInt32();
541  obj.ComputeHashCode();
542  }
543  else
544  {
545  stream.Write(obj.semanticName);
546  stream.Write(obj.semanticIndex);
547  stream.Write(obj.format);
548  stream.Write(obj.alignedByteOffset);
549  }
550  }
551  }
552  }
553 }
static VertexElement Color(PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "COLOR".
static VertexElement TextureCoordinate(int semanticIndex, PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "TEXCOORD".
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
VertexElement(string semanticName, PixelFormat format)
Initializes a new instance of the VertexElement struct.
VertexElement(string semanticName, int semanticIndex, PixelFormat format, int alignedByteOffset=AppendAligned)
Initializes a new instance of the VertexElement struct.
static VertexElement Tangent(PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "TANGENT".
static VertexElement TextureCoordinate(PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "TEXCOORD".
static VertexElement Normal(int semanticIndex, PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "NORMAL".
Represents a color in the form of rgb.
Definition: Color3.cs:41
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
Represents a 32-bit color (4 bytes) in the form of BGRA (in byte order: B, G, B, A).
Definition: ColorBGRA.cs:16
TextureCoordinate
The texture coordinate.
Represents a three dimensional mathematical vector.
Definition: Int3.cs:41
static VertexElement Position(int semanticIndex, PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "POSITION".
Represents a color in the form of rgba.
Definition: Color4.cs:42
static VertexElement BiTangent(int semanticIndex, PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "BITANGENT".
static VertexElement PositionTransformed(int semanticIndex, PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "SV_POSITION".
Base class for implementation of SerializationStream.
static VertexElement BiTangent(PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "BITANGENT".
A half precision (16 bit) floating point value.
Definition: Half.cs:37
static VertexElement Normal(PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "NORMAL".
Represents a four dimensional mathematical vector.
Definition: Vector4.cs:42
static VertexElement Tangent(int semanticIndex, PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "TANGENT".
SiliconStudio.Core.Mathematics.Color Color
Definition: ColorPicker.cs:14
Represents a four dimensional mathematical vector.
Definition: Int4.cs:35
Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A).
Definition: Color.cs:16
The normal style (One line per item, structured by space).
static VertexElement Position(PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "POSITION".
static VertexElement Color(int semanticIndex, PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "COLOR".
Describes how to serialize and deserialize an object without knowing its type. Used as a common base ...
ArchiveMode
Enumerates the different mode of serialization (either serialization or deserialization).
Definition: ArchiveMode.cs:8
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Definition: DirectXTexP.h:175
Defines a two component vector, using half precision floating point coordinates.
Definition: Half2.cs:34
static VertexElement PositionTransformed(PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "SV_POSITION".
Defines a four component vector, using half precision floating point coordinates. ...
Definition: Half4.cs:36
PixelFormat
Defines various types of pixel formats.
Definition: PixelFormat.cs:32
A description of a single element for the input-assembler stage. This structure is related to Direct3...