Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Texture2D.Direct3D.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 // 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 using System;
24 
25 using SharpDX.DXGI;
26 
27 namespace SiliconStudio.Paradox.Graphics
28 {
29  /// <summary>
30  /// A Texture 2D frontend to <see cref="SharpDX.Direct3D11.Texture2D"/>.
31  /// </summary>
32  public partial class Texture2D
33  {
34  /// <summary>
35  /// Initializes a new instance of the <see cref="Texture2DBase" /> class.
36  /// </summary>
37  /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
38  /// <param name="description2D">The description.</param>
39  /// <param name="dataBoxes">A variable-length parameters list containing data rectangles.</param>
40  protected internal Texture2D(GraphicsDevice device, TextureDescription description2D, DataBox[] dataBoxes = null) : base(device, description2D, dataBoxes)
41  {
42  }
43 
44  /// <summary>
45  /// Specialised constructor for use only by derived classes.
46  /// </summary>
47  /// <param name="device">The <see cref="GraphicsDevice" />.</param>
48  /// <param name="texture">The texture.</param>
49  /// <param name="viewType">Type of the view.</param>
50  /// <param name="arraySlice">The array slice.</param>
51  /// <param name="mipMapSlice">The mip map slice.</param>
52  /// <param name="viewFormat">The view format.</param>
53  protected internal Texture2D(GraphicsDevice device, Texture2D texture, ViewType viewType = ViewType.Full, int arraySlice = 0, int mipMapSlice = 0, PixelFormat viewFormat = PixelFormat.None)
54  : base(device, texture, viewType, arraySlice, mipMapSlice, viewFormat)
55  {
56  }
57 
58  /// <summary>
59  /// Specialised constructor for use only by derived classes.
60  /// </summary>
61  /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
62  /// <param name="texture">The texture.</param>
63  protected internal Texture2D(GraphicsDevice device, SharpDX.Direct3D11.Texture2D texture)
64  : base(device, texture)
65  {
66  }
67 
68  public override Texture ToTexture(ViewType viewType, int arraySlice, int mipMapSlice)
69  {
70  return new Texture2D(GraphicsDevice, this, viewType, arraySlice, mipMapSlice);
71  }
72 
73  /// <summary>
74  /// Gets a new instance of a depth stencil buffer linked to this texture.
75  /// </summary>
76  /// <param name="isReadOnly">if set to <c>true</c> the returned depth stencil buffer view is a read-only view, false otherwise..</param>
77  /// <returns>A depth stencil buffer view.</returns>
78  public DepthStencilBuffer ToDepthStencilBuffer(bool isReadOnly)
79  {
80  return new DepthStencilBuffer(GraphicsDevice, this, isReadOnly);
81  }
82 
83  /// <summary>
84  /// Creates a texture that can be used as a ShaderResource from an existing depth texture.
85  /// </summary>
86  /// <returns></returns>
87  public Texture2D ToDepthTextureCompatible()
88  {
89  if ((Description.Flags & TextureFlags.DepthStencil) == 0)
90  throw new NotSupportedException("This texture is not a valid depth stencil texture");
91 
92  var description = Description;
93  description.Format = (PixelFormat)DepthStencilBuffer.ComputeShaderResourceFormat((Format)Description.Format);
94  if (description.Format == PixelFormat.None)
95  throw new NotSupportedException("This depth stencil format is not supported");
96 
97  description.Flags = TextureFlags.ShaderResource;
98  return New(GraphicsDevice, description);
99  }
100  }
101 }
102 #endif
ViewType
Defines how a view is selected from a resource.
Definition: ViewType.cs:31
Same as Deferred mode, except sprites are sorted by texture prior to drawing. This can improve perfor...
PixelFormat
Defines various types of pixel formats.
Definition: PixelFormat.cs:32
The texture dimension is 2D.