Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
VertexArrayLayout.Direct3D.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.Collections.Generic;
4 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D
5 using System;
6 using SharpDX.Direct3D11;
7 using SiliconStudio.Core;
8 
9 namespace SiliconStudio.Paradox.Graphics
10 {
11  internal partial class VertexArrayLayout
12  {
13  private static readonly Dictionary<VertexArrayLayout, VertexArrayLayout> RegisteredLayouts = new Dictionary<VertexArrayLayout, VertexArrayLayout>();
14 
15  private VertexArrayLayout()
16  {
17  }
18 
19  private readonly int hashCode;
20  public readonly InputElement[] InputElements;
21 
22  /// <summary>
23  /// Initializes a new instance of the <see cref="VertexArrayLayout"/> class.
24  /// </summary>
25  /// <param name="inputElements">The input elements.</param>
26  /// <exception cref="System.ArgumentNullException">inputElements</exception>
27  public VertexArrayLayout(InputElement[] inputElements)
28  {
29  if (inputElements == null) throw new ArgumentNullException("inputElements");
30 
31  this.InputElements = inputElements;
32  hashCode = inputElements.Length;
33  for (int i = 0; i < inputElements.Length; i++)
34  {
35  hashCode = (hashCode * 397) ^ inputElements[i].GetHashCode();
36  }
37  }
38 
39  /// <summary>
40  /// Gets the original create layout.
41  /// </summary>
42  /// <param name="layout">The layout.</param>
43  /// <returns>VertexArrayLayout.</returns>
44  public static VertexArrayLayout GetOrCreateLayout(VertexArrayLayout layout)
45  {
46  VertexArrayLayout registeredLayout;
47  lock (RegisteredLayouts)
48  {
49  if (!RegisteredLayouts.TryGetValue(layout, out registeredLayout))
50  {
51  RegisteredLayouts.Add(layout, layout);
52  registeredLayout = layout;
53  }
54  }
55  return registeredLayout;
56  }
57 
58  public bool Equals(VertexArrayLayout other)
59  {
60  if (ReferenceEquals(this, other))
61  return true;
62  return hashCode == other.hashCode && Utilities.Compare(InputElements, other.InputElements);
63  }
64 
65  public override int GetHashCode()
66  {
67  return hashCode;
68  }
69 
70  public override bool Equals(object obj)
71  {
72  if (ReferenceEquals(null, obj)) return false;
73  if (ReferenceEquals(this, obj)) return true;
74  if (obj.GetType() != this.GetType()) return false;
75  return Equals((VertexArrayLayout)obj);
76  }
77 
78  public override string ToString()
79  {
80  var description = " Input Parameters: ";
81 
82  for (int i = 0; i < InputElements.Length; i++)
83  {
84  description += InputElements[i].SemanticName + InputElements[i].SemanticIndex;
85 
86  if (i != InputElements.Length - 1)
87  description += ", ";
88  }
89 
90  return description;
91  }
92  }
93 }
94 #endif