Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SamplerStateDescription.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.Mathematics;
7 using SiliconStudio.Core.Serialization;
8 
9 namespace SiliconStudio.Paradox.Graphics
10 {
11  /// <summary>
12  /// Describes a sampler state.
13  /// </summary>
14  [DataContract]
15  [StructLayout(LayoutKind.Sequential)]
16  public struct SamplerStateDescription : IEquatable<SamplerStateDescription>
17  {
18  /// <summary>
19  /// Initializes a new instance of the <see cref="SamplerStateDescription"/> class.
20  /// </summary>
21  /// <param name="filter">The filter.</param>
22  /// <param name="addressMode">The address mode.</param>
23  public SamplerStateDescription(TextureFilter filter, TextureAddressMode addressMode) : this()
24  {
25  SetDefaults();
26  Filter = filter;
27  AddressU = AddressV = AddressW = addressMode;
28  }
29 
30  /// <summary>
31  /// Gets or sets filtering method to use when sampling a texture (see <see cref="TextureFilter"/>).
32  /// </summary>
34 
35  /// <summary>
36  /// Gets or sets method to use for resolving a u texture coordinate that is outside the 0 to 1 range (see <see cref="TextureAddressMode"/>).
37  /// </summary>
39 
40  /// <summary>
41  /// Gets or sets method to use for resolving a v texture coordinate that is outside the 0 to 1 range.
42  /// </summary>
44 
45  /// <summary>
46  /// Gets or sets method to use for resolving a w texture coordinate that is outside the 0 to 1 range.
47  /// </summary>
49 
50  /// <summary>
51  /// Gets or sets offset from the calculated mipmap level.
52  /// For example, if Direct3D calculates that a texture should be sampled at mipmap level 3 and MipLODBias is 2, then the texture will be sampled at mipmap level 5.
53  /// </summary>
55 
56  /// <summary>
57  /// Gets or sets clamping value used if Anisotropy or ComparisonAnisotropy is specified in Filter. Valid values are between 1 and 16.
58  /// </summary>
59  public int MaxAnisotropy;
60 
61  /// <summary>
62  /// Gets or sets a function that compares sampled data against existing sampled data. The function options are listed in <see cref="CompareFunction"/>.
63  /// </summary>
65 
66  /// <summary>
67  /// Gets or sets border color to use if <see cref="TextureAddressMode.Border"/> is specified for AddressU, AddressV, or AddressW. Range must be between 0.0 and 1.0 inclusive.
68  /// </summary>
70 
71  /// <summary>
72  /// Gets or sets lower end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed.
73  /// </summary>
74  public float MinMipLevel;
75 
76  /// <summary>
77  /// Gets or sets upper end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed. This value must be greater than or equal to MinLOD. To have no upper limit on LOD set this to a large value such as D3D11_FLOAT32_MAX.
78  /// </summary>
79  public float MaxMipLevel;
80 
81  /// <summary>
82  /// Gets default values for this instance.
83  /// </summary>
84  public static SamplerStateDescription Default
85  {
86  get
87  {
88  var desc = new SamplerStateDescription();
89  desc.SetDefaults();
90  return desc;
91  }
92  }
93 
94  public bool Equals(SamplerStateDescription other)
95  {
96  return Filter == other.Filter && AddressU == other.AddressU && AddressV == other.AddressV && AddressW == other.AddressW && MipMapLevelOfDetailBias.Equals(other.MipMapLevelOfDetailBias) && MaxAnisotropy == other.MaxAnisotropy && CompareFunction == other.CompareFunction && BorderColor.Equals(other.BorderColor) && MinMipLevel.Equals(other.MinMipLevel) && MaxMipLevel.Equals(other.MaxMipLevel);
97  }
98 
99  public override bool Equals(object obj)
100  {
101  if (ReferenceEquals(null, obj)) return false;
102  return obj is SamplerStateDescription && Equals((SamplerStateDescription)obj);
103  }
104 
105  public override int GetHashCode()
106  {
107  unchecked
108  {
109  int hashCode = (int)Filter;
110  hashCode = (hashCode * 397) ^ (int)AddressU;
111  hashCode = (hashCode * 397) ^ (int)AddressV;
112  hashCode = (hashCode * 397) ^ (int)AddressW;
113  hashCode = (hashCode * 397) ^ MipMapLevelOfDetailBias.GetHashCode();
114  hashCode = (hashCode * 397) ^ MaxAnisotropy;
115  hashCode = (hashCode * 397) ^ (int)CompareFunction;
116  hashCode = (hashCode * 397) ^ BorderColor.GetHashCode();
117  hashCode = (hashCode * 397) ^ MinMipLevel.GetHashCode();
118  hashCode = (hashCode * 397) ^ MaxMipLevel.GetHashCode();
119  return hashCode;
120  }
121  }
122 
123  private void SetDefaults()
124  {
125  Filter = TextureFilter.Linear;
126  AddressU = TextureAddressMode.Clamp;
127  AddressV = TextureAddressMode.Clamp;
128  AddressW = TextureAddressMode.Clamp;
129  BorderColor = new Color4();
130  MaxAnisotropy = 16;
131  MinMipLevel = -float.MaxValue;
132  MaxMipLevel = float.MaxValue;
133  MipMapLevelOfDetailBias = 0.0f;
134  CompareFunction = CompareFunction.Never;
135  }
136  }
137 }
TextureAddressMode AddressW
Gets or sets method to use for resolving a w texture coordinate that is outside the 0 to 1 range...
Color4 BorderColor
Gets or sets border color to use if TextureAddressMode.Border is specified for AddressU, AddressV, or AddressW. Range must be between 0.0 and 1.0 inclusive.
float MinMipLevel
Gets or sets lower end of the mipmap range to clamp access to, where 0 is the largest and most detail...
TextureFilter Filter
Gets or sets filtering method to use when sampling a texture (see TextureFilter). ...
SamplerStateDescription(TextureFilter filter, TextureAddressMode addressMode)
Initializes a new instance of the SamplerStateDescription class.
TextureAddressMode
Identify a technique for resolving texture coordinates that are outside of the boundaries of a textur...
TextureFilter
Filtering options during texture sampling.
TextureAddressMode AddressV
Gets or sets method to use for resolving a v texture coordinate that is outside the 0 to 1 range...
Represents a color in the form of rgba.
Definition: Color4.cs:42
Use the default mode depending on the type of the field/property.
CompareFunction CompareFunction
Gets or sets a function that compares sampled data against existing sampled data. The function option...
CompareFunction
Comparison options.
TextureAddressMode AddressU
Gets or sets method to use for resolving a u texture coordinate that is outside the 0 to 1 range (see...
float MaxMipLevel
Gets or sets upper end of the mipmap range to clamp access to, where 0 is the largest and most detail...
int MaxAnisotropy
Gets or sets clamping value used if Anisotropy or ComparisonAnisotropy is specified in Filter...
float MipMapLevelOfDetailBias
Gets or sets offset from the calculated mipmap level. For example, if Direct3D calculates that a text...