3 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D
7 using SharpDX.Direct3D;
8 using SharpDX.Direct3D11;
10 using SiliconStudio.Core;
11 using SiliconStudio.Core.ReferenceCounting;
14 namespace SiliconStudio.
Paradox.Graphics
19 public partial class DepthStencilBuffer
21 internal DepthStencilView NativeDepthStencilView;
23 internal bool HasStencil;
25 private readonly
bool isReadOnly;
27 internal DepthStencilBuffer(GraphicsDevice device, Texture2D depthTexture,
bool isReadOnly) : base(device)
29 DescriptionInternal = depthTexture.Description;
31 Texture.AddReferenceInternal();
32 this.isReadOnly = isReadOnly;
33 InitializeViews(out HasStencil);
36 public static bool IsReadOnlySupported(GraphicsDevice device)
38 return device.Features.Profile >= GraphicsProfile.Level_11_0;
41 protected override void DestroyImpl()
46 _nativeDeviceChild = null;
47 Utilities.Dispose(ref NativeDepthStencilView);
51 protected internal override void OnDestroyed()
59 protected internal override bool OnRecreate()
63 _nativeDeviceChild = Texture.NativeDeviceChild;
64 InitializeViews(out HasStencil);
69 private void InitializeViews(out
bool hasStencil)
71 var nativeDescription = ((
Texture2D)Texture).NativeDescription;
73 if ((nativeDescription.BindFlags & BindFlags.DepthStencil) == 0)
74 throw new InvalidOperationException();
77 if (ComputeShaderResourceFormat((Format)Texture.Description.Format) == Format.Unknown)
78 throw new NotSupportedException(
"Depth stencil format not supported");
81 hasStencil = IsStencilFormat(nativeDescription.Format);
84 var depthStencilViewDescription =
new SharpDX.Direct3D11.DepthStencilViewDescription
86 Format = ComputeDepthViewFormatFromTextureFormat(nativeDescription.Format),
87 Flags = SharpDX.Direct3D11.DepthStencilViewFlags.None,
90 if (nativeDescription.ArraySize > 1)
92 depthStencilViewDescription.Dimension = SharpDX.Direct3D11.DepthStencilViewDimension.Texture2DArray;
93 depthStencilViewDescription.Texture2DArray.ArraySize = nativeDescription.ArraySize;
94 depthStencilViewDescription.Texture2DArray.FirstArraySlice = 0;
95 depthStencilViewDescription.Texture2DArray.MipSlice = 0;
99 depthStencilViewDescription.Dimension = SharpDX.Direct3D11.DepthStencilViewDimension.Texture2D;
100 depthStencilViewDescription.Texture2D.MipSlice = 0;
103 if (nativeDescription.SampleDescription.Count > 1)
104 depthStencilViewDescription.Dimension = DepthStencilViewDimension.Texture2DMultisampled;
108 if (!IsReadOnlySupported(GraphicsDevice))
109 throw new NotSupportedException(
"Cannot instantiate ReadOnly DepthStencilBuffer. Not supported on this device.");
112 depthStencilViewDescription.Flags = DepthStencilViewFlags.ReadOnlyDepth;
114 depthStencilViewDescription.Flags |= DepthStencilViewFlags.ReadOnlyStencil;
117 NativeDepthStencilView =
new SharpDX.Direct3D11.DepthStencilView(GraphicsDevice.NativeDevice, Texture.NativeResource, depthStencilViewDescription);
122 NativeDepthStencilView =
new SharpDX.Direct3D11.DepthStencilView(GraphicsDevice.NativeDevice, Texture.NativeResource, depthStencilViewDescription);
126 internal static bool IsStencilFormat(Format
format)
130 case Format.R24G8_Typeless:
131 case Format.D24_UNorm_S8_UInt:
132 case Format.R32G8X24_Typeless:
133 case Format.D32_Float_S8X24_UInt:
140 internal static Format ComputeShaderResourceFormat(Format format)
147 case Format.D16_UNorm:
148 viewFormat = SharpDX.DXGI.Format.R16_Float;
150 case Format.D32_Float:
151 viewFormat = SharpDX.DXGI.Format.R32_Float;
153 case Format.D24_UNorm_S8_UInt:
154 viewFormat = SharpDX.DXGI.Format.R24_UNorm_X8_Typeless;
156 case Format.D32_Float_S8X24_UInt:
157 viewFormat = SharpDX.DXGI.Format.R32_Float_X8X24_Typeless;
160 viewFormat = Format.Unknown;
167 internal static Format ComputeDepthViewFormatFromTextureFormat(Format format)
173 case Format.R16_Typeless:
174 case Format.D16_UNorm:
175 viewFormat = Format.D16_UNorm;
177 case Format.R32_Typeless:
178 case Format.D32_Float:
179 viewFormat = Format.D32_Float;
181 case Format.R24G8_Typeless:
182 case Format.D24_UNorm_S8_UInt:
183 viewFormat = Format.D24_UNorm_S8_UInt;
185 case Format.R32G8X24_Typeless:
186 case Format.D32_Float_S8X24_UInt:
187 viewFormat = Format.D32_Float_S8X24_UInt;
190 throw new NotSupportedException(
string.Format(
"Unsupported depth format [{0}]", format));
Flags
Enumeration of the new Assimp's flags.
SiliconStudio.Core.Utilities Utilities
Same as Deferred mode, except sprites are sorted by texture prior to drawing. This can improve perfor...
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
The texture dimension is 2D.