Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
EffectSignatureLayout.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 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D
4 using System.Linq;
5 using SharpDX.Direct3D11;
6 
7 namespace SiliconStudio.Paradox.Graphics
8 {
9  class EffectSignatureLayout
10  {
11  public InputElement[] InputElements { get; private set; }
12 
13  public byte[] ShaderSignature { get; private set; }
14 
15  private readonly int inputElementsHashCode = 0;
16 
17  public EffectSignatureLayout(InputElement[] inputElements, byte[] signature)
18  {
19  InputElements = inputElements;
20  ShaderSignature = signature;
21  inputElementsHashCode = InputElements.Aggregate(InputElements.Length, (current, inputElement) => (current * 397) ^ inputElement.GetHashCode());
22  inputElementsHashCode = (inputElementsHashCode * 397) ^ ShaderSignature.GetHashCode();
23  }
24 
25  public bool Equals(EffectSignatureLayout other)
26  {
27  if (ReferenceEquals(null, other)) return false;
28  if (ReferenceEquals(this, other)) return true;
29 
30  // Check the number of elements
31  if (InputElements.Length != other.InputElements.Length)
32  return false;
33 
34  // Check the signature pointer
35  if (ShaderSignature != other.ShaderSignature)
36  return false;
37 
38  return !InputElements.Where((t, i) => t != other.InputElements[i]).Any();
39  }
40 
41  public override bool Equals(object obj)
42  {
43  if (ReferenceEquals(null, obj)) return false;
44  if (ReferenceEquals(this, obj)) return true;
45  if (obj.GetType() != typeof(EffectSignatureLayout)) return false;
46  return Equals((EffectSignatureLayout)obj);
47  }
48 
49  public override int GetHashCode()
50  {
51  return inputElementsHashCode;
52  }
53 
54  public static bool operator ==(EffectSignatureLayout left, EffectSignatureLayout right)
55  {
56  return Equals(left, right);
57  }
58 
59  public static bool operator !=(EffectSignatureLayout left, EffectSignatureLayout right)
60  {
61  return !Equals(left, right);
62  }
63  }
64 }
65 #endif