Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
MipMapCount.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.Runtime.InteropServices;
26 
27 namespace SiliconStudio.Paradox.Graphics
28 {
29  /// <summary>
30  /// A simple wrapper to specify number of mipmaps.
31  /// Set to true to specify all mipmaps or sets an integer value >= 1
32  /// to specify the exact number of mipmaps.
33  /// </summary>
34  /// <remarks>
35  /// This structure use implicit conversion:
36  /// <ul>
37  /// <li>Set to <c>true</c> to specify all mipmaps.</li>
38  /// <li>Set to <c>false</c> to specify a single mipmap.</li>
39  /// <li>Set to an integer value >=1 to specify an exact count of mipmaps.</li>
40  /// </ul>
41  /// </remarks>
42  [StructLayout(LayoutKind.Sequential, Size = 4)]
43  public struct MipMapCount : IEquatable<MipMapCount>
44  {
45  /// <summary>
46  /// Automatic mipmap level based on texture size.
47  /// </summary>
48  public readonly static MipMapCount Auto = new MipMapCount(true);
49 
50  /// <summary>
51  /// Initializes a new instance of the <see cref="MipMapCount" /> struct.
52  /// </summary>
53  /// <param name="allMipMaps">if set to <c>true</c> generates all mip maps.</param>
54  public MipMapCount(bool allMipMaps)
55  {
56  this.Count = allMipMaps ? 0 : 1;
57  }
58 
59  /// <summary>
60  /// Initializes a new instance of the <see cref="MipMapCount" /> struct.
61  /// </summary>
62  /// <param name="count">The count.</param>
63  public MipMapCount(int count)
64  {
65  if (count < 0)
66  throw new ArgumentException("mipCount must be >= 0");
67  this.Count = count;
68  }
69 
70  /// <summary>
71  /// Number of mipmaps.
72  /// </summary>
73  /// <remarks>
74  /// Zero(0) means generate all mipmaps. One(1) generates a single mipmap... etc.
75  /// </remarks>
76  public readonly int Count;
77 
78  public bool Equals(MipMapCount other)
79  {
80  return this.Count == other.Count;
81  }
82 
83  public override bool Equals(object obj)
84  {
85  if (ReferenceEquals(null, obj))
86  return false;
87  return obj is MipMapCount && Equals((MipMapCount)obj);
88  }
89 
90  public override int GetHashCode()
91  {
92  return this.Count;
93  }
94 
95  public static bool operator ==(MipMapCount left, MipMapCount right)
96  {
97  return left.Equals(right);
98  }
99 
100  public static bool operator !=(MipMapCount left, MipMapCount right)
101  {
102  return !left.Equals(right);
103  }
104 
105  /// <summary>
106  /// Performs an explicit conversion from <see cref="MipMapCount"/> to <see cref="bool"/>.
107  /// </summary>
108  /// <param name="mipMap">The value.</param>
109  /// <returns>The result of the conversion.</returns>
110  public static implicit operator bool(MipMapCount mipMap)
111  {
112  return mipMap.Count == 0;
113  }
114 
115  /// <summary>
116  /// Performs an explicit conversion from <see cref="bool"/> to <see cref="MipMapCount"/>.
117  /// </summary>
118  /// <param name="mipMapAll">True to generate all mipmaps, false to use a single mipmap.</param>
119  /// <returns>The result of the conversion.</returns>
120  public static implicit operator MipMapCount(bool mipMapAll)
121  {
122  return new MipMapCount(mipMapAll);
123  }
124 
125  /// <summary>
126  /// Performs an explicit conversion from <see cref="MipMapCount"/> to <see cref="int"/>.
127  /// </summary>
128  /// <param name="mipMap">The value.</param>
129  /// <returns>The count of mipmap (0 means all mipmaps).</returns>
130  public static implicit operator int(MipMapCount mipMap)
131  {
132  return mipMap.Count;
133  }
134 
135  /// <summary>
136  /// Performs an explicit conversion from <see cref="int"/> to <see cref="MipMapCount"/>.
137  /// </summary>
138  /// <param name="mipMapCount">True to generate all mipmaps, false to use a single mipmap.</param>
139  /// <returns>The result of the conversion.</returns>
140  public static implicit operator MipMapCount(int mipMapCount)
141  {
142  return new MipMapCount(mipMapCount);
143  }
144  }
145 }
A simple wrapper to specify number of mipmaps. Set to true to specify all mipmaps or sets an integer ...
Definition: MipMapCount.cs:43
override bool Equals(object obj)
Definition: MipMapCount.cs:83
MipMapCount(int count)
Initializes a new instance of the MipMapCount struct.
Definition: MipMapCount.cs:63
MipMapCount(bool allMipMaps)
Initializes a new instance of the MipMapCount struct.
Definition: MipMapCount.cs:54
_In_ size_t count
Definition: DirectXTexP.h:174
readonly int Count
Number of mipmaps.
Definition: MipMapCount.cs:76