Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ShaderMacro.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.Runtime.InteropServices;
5 using SiliconStudio.Core;
6 using SiliconStudio.Core.Serialization;
7 
8 namespace SiliconStudio.Paradox.Shaders
9 {
10  /// <summary>
11  /// Preprocessor macro.
12  /// </summary>
13  [StructLayout(LayoutKind.Sequential, Pack = 4)]
14  [DataContract]
15  public struct ShaderMacro : IEquatable<ShaderMacro>
16  {
17  /// <summary>
18  /// Initializes a new instance of the <see cref="ShaderMacro"/> struct.
19  /// </summary>
20  /// <param name="name">The name.</param>
21  /// <param name="definition">The definition.</param>
22  public ShaderMacro(string name, object definition)
23  {
24  this.Name = name;
25  this.Definition = definition == null ? "" : definition.ToString();
26  }
27 
28  /// <summary>
29  /// Name of the macro to set.
30  /// </summary>
31  [MarshalAs(UnmanagedType.LPStr)]
32  public string Name;
33 
34  /// <summary>
35  /// Value of the macro to set.
36  /// </summary>
37  [MarshalAs(UnmanagedType.LPStr)]
38  public string Definition;
39 
40  /// <summary>
41  /// Indicates whether the current object is equal to another object of the same type.
42  /// </summary>
43  /// <param name="other">An object to compare with this object.</param>
44  /// <returns>
45  /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
46  /// </returns>
47  public bool Equals(ShaderMacro other)
48  {
49  return Equals(other.Name, Name) && Equals(other.Definition, Definition);
50  }
51 
52  /// <summary>
53  /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
54  /// </summary>
55  /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
56  /// <returns>
57  /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
58  /// </returns>
59  public override bool Equals(object obj)
60  {
61  if (ReferenceEquals(null, obj)) return false;
62  if (obj.GetType() != typeof(ShaderMacro)) return false;
63  return Equals((ShaderMacro)obj);
64  }
65 
66  /// <summary>
67  /// Returns a hash code for this instance.
68  /// </summary>
69  /// <returns>
70  /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
71  /// </returns>
72  public override int GetHashCode()
73  {
74  unchecked
75  {
76  return ((Name != null ? Name.GetHashCode() : 0) * 397) ^ (Definition != null ? Definition.GetHashCode() : 0);
77  }
78  }
79  }
80 }
override bool Equals(object obj)
Determines whether the specified System.Object is equal to this instance.
Definition: ShaderMacro.cs:59
string Definition
Value of the macro to set.
Definition: ShaderMacro.cs:38
ShaderMacro(string name, object definition)
Initializes a new instance of the ShaderMacro struct.
Definition: ShaderMacro.cs:22
override int GetHashCode()
Returns a hash code for this instance.
Definition: ShaderMacro.cs:72
string Name
Name of the macro to set.
Definition: ShaderMacro.cs:32
bool Equals(ShaderMacro other)
Indicates whether the current object is equal to another object of the same type. ...
Definition: ShaderMacro.cs:47