Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
TextureDescription.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 Common description for all textures.
31  /// </summary>
32  [StructLayout(LayoutKind.Sequential)]
33  public struct TextureDescription : IEquatable<TextureDescription>
34  {
35  /// <summary>
36  /// The dimension of a texture.
37  /// </summary>
39 
40  /// <summary>
41  /// <dd> <p>Texture width (in texels). The range is from 1 to <see cref="SharpDX.Direct3D11.Resource.MaximumTexture1DSize"/> (16384). However, the range is actually constrained by the feature level at which you create the rendering device. For more information about restrictions, see Remarks.</p> </dd>
42  /// </summary>
43  /// <remarks>
44  /// This field is valid for all textures: <see cref="Texture1D"/>, <see cref="Texture2D"/>, <see cref="Texture3D"/> and <see cref="TextureCube"/>.
45  /// </remarks>
46  public int Width;
47 
48  /// <summary>
49  /// <dd> <p>Texture height (in texels). The range is from 1 to <see cref="SharpDX.Direct3D11.Resource.MaximumTexture3DSize"/> (2048). However, the range is actually constrained by the feature level at which you create the rendering device. For more information about restrictions, see Remarks.</p> </dd>
50  /// </summary>
51  /// <remarks>
52  /// This field is only valid for <see cref="Texture2D"/>, <see cref="Texture3D"/> and <see cref="TextureCube"/>.
53  /// </remarks>
54  public int Height;
55 
56  /// <summary>
57  /// <dd> <p>Texture depth (in texels). The range is from 1 to <see cref="SharpDX.Direct3D11.Resource.MaximumTexture3DSize"/> (2048). However, the range is actually constrained by the feature level at which you create the rendering device. For more information about restrictions, see Remarks.</p> </dd>
58  /// </summary>
59  /// <remarks>
60  /// This field is only valid for <see cref="Texture3D"/>.
61  /// </remarks>
62  public int Depth;
63 
64  /// <summary>
65  /// <dd> <p>Number of textures in the array. The range is from 1 to <see cref="SharpDX.Direct3D11.Resource.MaximumTexture1DArraySize"/> (2048). However, the range is actually constrained by the feature level at which you create the rendering device. For more information about restrictions, see Remarks.</p> </dd>
66  /// </summary>
67  /// <remarks>
68  /// This field is only valid for <see cref="Texture1D"/>, <see cref="Texture2D"/> and <see cref="TextureCube"/>
69  /// </remarks>
70  /// <remarks>
71  /// This field is only valid for textures: <see cref="Texture1D"/>, <see cref="Texture2D"/> and <see cref="TextureCube"/>.
72  /// </remarks>
73  public int ArraySize;
74 
75  /// <summary>
76  /// <dd> <p>The maximum number of mipmap levels in the texture. See the remarks in <strong><see cref="SharpDX.Direct3D11.ShaderResourceViewDescription.Texture1DResource"/></strong>. Use 1 for a multisampled texture; or 0 to generate a full set of subtextures.</p> </dd>
77  /// </summary>
78  public int MipLevels;
79 
80  /// <summary>
81  /// <dd> <p>Texture format (see <strong><see cref="SharpDX.DXGI.Format"/></strong>).</p> </dd>
82  /// </summary>
84 
85  /// <summary>
86  /// <dd> <p>Structure that specifies multisampling parameters for the texture. See <strong><see cref="SharpDX.DXGI.SampleDescription"/></strong>.</p> </dd>
87  /// </summary>
88  /// <remarks>
89  /// This field is only valid for <see cref="Texture2D"/>.
90  /// </remarks>
91  public MSAALevel Level;
92 
93  /// <summary>
94  /// <dd> <p>Value that identifies how the texture is to be read from and written to. The most common value is <see cref="SharpDX.Direct3D11.ResourceUsage.Default"/>; see <strong><see cref="SharpDX.Direct3D11.ResourceUsage"/></strong> for all possible values.</p> </dd>
95  /// </summary>
97 
98  /// <summary>
99  /// <dd> <p>Flags (see <strong><see cref="SharpDX.Direct3D11.BindFlags"/></strong>) for binding to pipeline stages. The flags can be combined by a logical OR. For a 1D texture, the allowable values are: <see cref="SharpDX.Direct3D11.BindFlags.ShaderResource"/>, <see cref="SharpDX.Direct3D11.BindFlags.RenderTarget"/> and <see cref="SharpDX.Direct3D11.BindFlags.DepthStencil"/>.</p> </dd>
100  /// </summary>
102 
103  /// <summary>
104  /// Gets the staging description for this instance..
105  /// </summary>
106  /// <returns>A Staging description</returns>
108  {
109  var copy = this;
110  copy.Flags = TextureFlags.None;
111  copy.Usage = GraphicsResourceUsage.Staging;
112  return copy;
113  }
114 
115  /// <summary>
116  /// Performs an explicit conversion from <see cref="ImageDescription"/> to <see cref="TextureDescription"/>.
117  /// </summary>
118  /// <param name="description">The image description.</param>
119  /// <returns>The result of the conversion.</returns>
120  public static implicit operator TextureDescription(ImageDescription description)
121  {
122  return new TextureDescription()
123  {
124  Dimension = description.Dimension,
125  Width = description.Width,
126  Height = description.Height,
127  Depth = description.Depth,
128  ArraySize = description.ArraySize,
129  MipLevels = description.MipLevels,
130  Format = description.Format,
131  Flags = TextureFlags.None,
132  Level = MSAALevel.None
133  };
134  }
135 
136  /// <summary>
137  /// Performs an explicit conversion from <see cref="ImageDescription"/> to <see cref="TextureDescription"/>.
138  /// </summary>
139  /// <param name="description">The image description.</param>
140  /// <returns>The result of the conversion.</returns>
141  public static implicit operator ImageDescription(TextureDescription description)
142  {
143  return new ImageDescription()
144  {
145  Dimension = description.Dimension,
146  Width = description.Width,
147  Height = description.Height,
148  Depth = description.Depth,
149  ArraySize = description.ArraySize,
150  MipLevels = description.MipLevels,
151  Format = description.Format,
152  };
153  }
154 
155  public bool Equals(TextureDescription other)
156  {
157  return Dimension == other.Dimension && Width == other.Width && Height == other.Height && Depth == other.Depth && ArraySize == other.ArraySize && MipLevels == other.MipLevels && Format == other.Format && Level == other.Level && Usage == other.Usage && Flags == other.Flags;
158  }
159 
160  public override bool Equals(object obj)
161  {
162  if (ReferenceEquals(null, obj)) return false;
163  return obj is TextureDescription && Equals((TextureDescription)obj);
164  }
165 
166  /// <inheritdoc/>
167  public override int GetHashCode()
168  {
169  unchecked
170  {
171  int hashCode = (int)Dimension;
172  hashCode = (hashCode * 397) ^ Width;
173  hashCode = (hashCode * 397) ^ Height;
174  hashCode = (hashCode * 397) ^ Depth;
175  hashCode = (hashCode * 397) ^ ArraySize;
176  hashCode = (hashCode * 397) ^ MipLevels;
177  hashCode = (hashCode * 397) ^ (int)Format;
178  hashCode = (hashCode * 397) ^ (int)Level;
179  hashCode = (hashCode * 397) ^ (int)Usage;
180  hashCode = (hashCode * 397) ^ (int)Flags;
181  return hashCode;
182  }
183  }
184 
185  /// <summary>
186  /// Implements the operator ==.
187  /// </summary>
188  /// <param name="left">The left.</param>
189  /// <param name="right">The right.</param>
190  /// <returns>The result of the operator.</returns>
191  public static bool operator ==(TextureDescription left, TextureDescription right)
192  {
193  return left.Equals(right);
194  }
195 
196  /// <summary>
197  /// Implements the operator !=.
198  /// </summary>
199  /// <param name="left">The left.</param>
200  /// <param name="right">The right.</param>
201  /// <returns>The result of the operator.</returns>
202  public static bool operator !=(TextureDescription left, TextureDescription right)
203  {
204  return !left.Equals(right);
205  }
206  }
207 }
GraphicsResourceUsage
Identifies expected resource use during rendering. The usage directly reflects whether a resource is ...
MSAALevel
Multisample count level.
Definition: MSAALevel.cs:29
TextureDescription ToStagingDescription()
Gets the staging description for this instance..
TextureDimension
Defines the dimension of a texture.
Flags
Enumeration of the new Assimp's flags.
A Common description for all textures.
TextureDimension Dimension
The dimension of a texture.
PixelFormat
Defines various types of pixel formats.
Definition: PixelFormat.cs:32