internal FeaturesPerFormat(Format format, MSAALevel maximumMSAALevel, ComputeShaderFormatSupport computeShaderFormatSupport, FormatSupport formatSupport) { Format = format; this.MSAALevelMax = maximumMSAALevel; ComputeShaderFormatSupport = computeShaderFormatSupport; FormatSupport = formatSupport; }
public RenderOutputDescription(PixelFormat renderTargetFormat, PixelFormat depthStencilFormat = PixelFormat.None, MSAALevel multiSampleLevel = MSAALevel.None) : this() { RenderTargetCount = renderTargetFormat != PixelFormat.None ? 1 : 0; RenderTargetFormat0 = renderTargetFormat; DepthStencilFormat = depthStencilFormat; MultiSampleLevel = multiSampleLevel; }
//internal FeaturesPerFormat(PixelFormat format, MSAALevel maximumMSAALevel, ComputeShaderFormatSupport computeShaderFormatSupport, FormatSupport formatSupport) internal FeaturesPerFormat(PixelFormat format, MSAALevel maximumMSAALevel, FormatSupport formatSupport) { Format = format; this.MSAALevelMax = maximumMSAALevel; //ComputeShaderFormatSupport = computeShaderFormatSupport; FormatSupport = formatSupport; }
private ShaderResourceViewProxy CreateRenderTarget(int width, int height, MSAALevel msaa) { #if MSAA MSAA = msaa; #endif TargetWidth = width; TargetHeight = height; DisposeBuffers(); ColorBufferSampleDesc = GetMSAASampleDescription(); OnCreateRenderTargetAndDepthBuffers(width, height, UseDepthStencilBuffer, out colorBuffer, out depthStencilBuffer); backBuffer = OnCreateBackBuffer(width, height); backBuffer.CreateRenderTargetView(); fullResPPBuffer = Collect(new PingPongColorBuffers(Format, width, height, this.deviceResources)); fullResDepthStencilPool = Collect(new TexturePool(this.deviceResources, new Texture2DDescription() { Width = width, Height = height, ArraySize = 1, BindFlags = BindFlags.DepthStencil, CpuAccessFlags = CpuAccessFlags.None, Usage = ResourceUsage.Default, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0) })); Initialized = true; OnNewBufferCreated?.Invoke(this, new Texture2DArgs(backBuffer)); return(backBuffer); }
public void ValidateParams(bool allowRandomAccess, MSAALevel msaaLevel) { if (allowRandomAccess && msaaLevel != MSAALevel.Disabled) { throw new NotSupportedException("Texture can't be random access with MSAA enabled"); } }
/// <summary> /// Initializes. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="msaa">The msaa.</param> /// <returns></returns> public ShaderResourceViewProxy Initialize(int width, int height, MSAALevel msaa) { #if MSAA return(CreateRenderTarget(width, height, msaa)); #else return(CreateRenderTarget(width, height, MSAALevel.Disable)); #endif }
/// <summary> /// Initializes. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="msaa">The msaa.</param> /// <returns></returns> public Texture2D Initialize(int width, int height, MSAALevel msaa) { #if MSAA return(CreateRenderTarget(width, height, msaa)); #else return(CreateRenderTarget(width, height, MSAALevel.Disable)); #endif }
private void InitProperties() { MSAA = new MSAALevel(); FXAA = new FXAALevel(); HeightMultiplicator = 1.0f; DirectionalLightColor = Colors.White; ChangeViewportQuality(2); }
/// <summary> /// Initializes a new instance of the <see cref="PresentationParameters" /> class with default values. /// </summary> public PresentationParameters() { BackBufferWidth = 800; BackBufferHeight = 480; BackBufferFormat = PixelFormat.R8G8B8A8_UNorm; PresentationInterval = PresentInterval.Immediate; DepthStencilFormat = PixelFormat.D24_UNorm_S8_UInt; MultiSampleCount = MSAALevel.None; IsFullScreen = false; RefreshRate = new Rational(60, 1); // by default }
public unsafe override bool GetMaxMSAALevel(TextureFormat format, out MSAALevel msaaLevel) { var result = MSAALevel.Disabled; if (Orbital_Video_D3D12_Device_GetMaxMSAALevel(handle, format, &result) != 0) { msaaLevel = result; return(true); } msaaLevel = MSAALevel.Disabled; return(false); }
/// <summary> /// Initializes a new instance of the <see cref="PresentationParameters" /> class with default values. /// </summary> public PresentationParameters() { BackBufferWidth = 800; BackBufferHeight = 480; BackBufferFormat = PixelFormat.R8G8B8A8.UNorm; PresentationInterval = PresentInterval.Immediate; DepthStencilFormat = DepthFormat.Depth24Stencil8; MultiSampleCount = MSAALevel.None; IsFullScreen = false; RefreshRate = new Rational(60, 1); // by default RenderTargetUsage = Usage.BackBuffer | Usage.RenderTargetOutput; Flags = SwapChainFlags.AllowModeSwitch; }
/// <summary> /// Sets default values for this instance. /// </summary> public void SetDefault() { CullMode = CullMode.Back; FillMode = FillMode.Solid; DepthClipEnable = true; FrontFaceCounterClockwise = false; ScissorTestEnable = false; MultiSampleLevel = MSAALevel.None; MultiSampleAntiAliasLine = false; DepthBias = 0; DepthBiasClamp = 0f; SlopeScaleDepthBias = 0f; }
private Texture2D CreateRenderTarget(int width, int height, MSAALevel msaa) { #if MSAA MSAA = msaa; #endif TargetWidth = width; TargetHeight = height; DisposeBuffers(); var texture = OnCreateRenderTargetAndDepthBuffers(width, height, UseDepthStencilBuffer); Initialized = true; OnNewBufferCreated?.Invoke(this, new Texture2DArgs(texture)); return(texture); }
private ShaderResourceViewProxy CreateRenderTarget(int width, int height, MSAALevel msaa) { #if MSAA MSAA = msaa; #endif TargetWidth = width; TargetHeight = height; DisposeBuffers(); ColorBufferSampleDesc = GetMSAASampleDescription(); OnCreateRenderTargetAndDepthBuffers(width, height, UseDepthStencilBuffer, out colorBuffer, out depthStencilBuffer); backBuffer = OnCreateBackBuffer(width, height); backBuffer.CreateRenderTargetView(); Initialized = true; OnNewBufferCreated?.Invoke(this, new Texture2DArgs(backBuffer)); return(backBuffer); }
public WarpSceneRenderer(Scene scene, int width, int height) { _scene = scene; _width = width; _height = height; _aspectRatio = width / (float)height; _device = GraphicsDevice.New(DriverType.Warp, DeviceCreationFlags.None, FeatureLevel.Level_10_1); var serviceProvider = new ServiceProvider(); serviceProvider.AddService <IGraphicsDeviceService>(new GraphicsDeviceService(_device)); _contentManager = new ContentManager(serviceProvider); _contentManager.Resolvers.Add(new ContentResolver()); var viewport = new Viewport(0, 0, _width, _height); _device.SetViewports(viewport); const MSAALevel msaaLevel = MSAALevel.None; _depthStencilTexture = DepthStencilBuffer.New(_device, _width, _height, msaaLevel, DepthFormat.Depth24Stencil8); _renderTexture = RenderTarget2D.New(_device, _width, _height, msaaLevel, PixelFormat.R8G8B8A8.UNorm); Options = new RenderOptions(); _effect = new BasicEffect(_device); _effect.EnableDefaultLighting(); _inputLayout = VertexInputLayout.New(0, typeof(VertexPositionNormalTexture)); _device.SetVertexInputLayout(_inputLayout); _meshes = new List <WarpMesh>(); foreach (Mesh mesh in _scene.Meshes) { if (!mesh.Positions.Any()) { continue; } var warpMesh = new WarpMesh(_device, mesh); _meshes.Add(warpMesh); warpMesh.Initialize(_contentManager); } }
/// <summary> /// Will find the MSAA level compatible with all devices /// </summary> public unsafe override bool GetMaxMSAALevel(TextureFormat format, out MSAALevel msaaLevel) { msaaLevel = MSAALevel.X16; foreach (var device in devices) { MSAALevel deviceMSAA; if (!device.GetMaxMSAALevel(format, out deviceMSAA)) { return(false); } if (deviceMSAA < msaaLevel) { msaaLevel = deviceMSAA; } } return(true); }
public unsafe void CaptureState(CommandList commandList) { DepthStencilFormat = commandList.DepthStencilBuffer != null ? commandList.DepthStencilBuffer.ViewFormat : PixelFormat.None; MultiSampleLevel = commandList.DepthStencilBuffer != null ? commandList.DepthStencilBuffer.MultiSampleLevel : MSAALevel.None; RenderTargetCount = commandList.RenderTargetCount; fixed(PixelFormat *renderTargetFormat0 = &RenderTargetFormat0) { var renderTargetFormat = renderTargetFormat0; for (int i = 0; i < RenderTargetCount; ++i) { *renderTargetFormat++ = commandList.RenderTargets[i].ViewFormat; MultiSampleLevel = commandList.RenderTargets[i].MultiSampleLevel; // multisample should all be equal } } }
/// <summary> /// Creates a new <see cref="GPUTextureDescription" />. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">Describes the format to use.</param> /// <param name="textureFlags">true if the texture needs to support unordered read write.</param> /// <param name="mipCount">Number of mipmaps for the texture. Default is 1. Use 0 to allocate full mip chain.</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <param name="msaaLevel">The MSAA Level.</param> /// <returns>A new instance of <see cref="GPUTextureDescription" /> class.</returns> public static GPUTextureDescription New2D(int width, int height, PixelFormat format, GPUTextureFlags textureFlags, int mipCount, int arraySize, MSAALevel msaaLevel = MSAALevel.None) { GPUTextureDescription desc; desc.Dimensions = TextureDimensions.Texture; desc.Width = width; desc.Height = height; desc.Depth = 1; desc.ArraySize = arraySize; desc.MipLevels = CalculateMipMapCount(mipCount, Mathf.Max(width, height)); desc.Format = format; desc.MultiSampleLevel = msaaLevel; desc.Flags = textureFlags; desc.DefaultClearColor = Color.Black; desc.Usage = GPUResourceUsage.Default; return(desc); }
/// <summary> /// Creates a new texture description <see cref="RenderTarget2D" /> using multisampling. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">Describes the format to use.</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <param name="multiSampleCount">The multisample count.</param> /// <returns>A new instance of <see cref="RenderTarget2D" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static Texture2DDescription CreateDescription(GraphicsDevice device, int width, int height, MSAALevel multiSampleCount, PixelFormat format, int arraySize = 1) { return CreateDescription(device.MainDevice, width, height, format, TextureFlags.RenderTarget, 1, arraySize, multiSampleCount); }
/// <summary> /// Creates a new <see cref="GPUTextureDescription" />. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="mipCount">Number of mipmaps for the texture. Default is 1. Use 0 to allocate full mip chain.</param> /// <param name="format">Describes the format to use.</param> /// <param name="textureFlags">true if the texture needs to support unordered read write.</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <param name="msaaLevel">The MSAA Level.</param> /// <returns>A new instance of <see cref="GPUTextureDescription" /> class.</returns> public static GPUTextureDescription New2D(int width, int height, int mipCount, PixelFormat format, GPUTextureFlags textureFlags = GPUTextureFlags.ShaderResource | GPUTextureFlags.RenderTarget, int arraySize = 1, MSAALevel msaaLevel = MSAALevel.None) { return(New2D(width, height, format, textureFlags, mipCount, arraySize, msaaLevel)); }
/// <summary> /// Allocates a temporary render target. /// </summary> /// <param name="format">The texture format.</param> /// <param name="width">The width in pixels.</param> /// <param name="height">The height in pixels.</param> /// <param name="flags">The texture usage flags.</param> /// <param name="msaa">The texture multisampling level.</param> /// <returns>Created texture.</returns> public static RenderTarget GetTemporary(PixelFormat format, int width, int height, TextureFlags flags = TextureFlags.ShaderResource | TextureFlags.RenderTarget, MSAALevel msaa = MSAALevel.None) { // Try reuse for (int i = 0; i < _tmpRenderTargets.Count; i++) { if (_tmpRenderTargets[i].TryReuse(format, width, height, flags, msaa)) { return(_tmpRenderTargets[i].OnUse()); } } // Allocate new var target = new Temporary(format, width, height, flags, msaa); _tmpRenderTargets.Add(target); return(target.OnUse()); }
internal unsafe bool Init(int width, int height, TextureFormat format, byte[] data, bool isRenderTexture, bool allowRandomAccess, MSAALevel msaaLevel, MultiGPUNodeResourceVisibility nodeVisibility) { ValidateParams(allowRandomAccess, msaaLevel); this.msaaLevel = msaaLevel; this.width = width; this.height = height; uint widthValue = (uint)width; uint heightValue = (uint)height; uint depthValue = 1; if (data == null) return(Texture.Orbital_Video_D3D12_Texture_Init(handle, format, TextureType_NativeInterop._2D, 1, &widthValue, &heightValue, &depthValue, null, isRenderTexture ? 1 : 0, allowRandomAccess ? 1 : 0, msaaLevel, nodeVisibility) != 0); fixed(byte *dataPtr = data) return(Texture.Orbital_Video_D3D12_Texture_Init(handle, format, TextureType_NativeInterop._2D, 1, &widthValue, &heightValue, &depthValue, &dataPtr, isRenderTexture ? 1 : 0, allowRandomAccess ? 1 : 0, msaaLevel, nodeVisibility) != 0); }
protected static Texture2DDescription NewDepthStencilBufferDescription(GraphicsDevice device, int width, int height, DepthFormat format, MSAALevel multiSampleCount, int arraySize, bool shaderResource) { var desc = Texture2DBase.NewDescription(width, height, DXGI.Format.Unknown, TextureFlags.None, 1, arraySize, ResourceUsage.Default); desc.BindFlags |= BindFlags.DepthStencil; if (shaderResource) { desc.BindFlags |= BindFlags.ShaderResource; } // Sets the MSAALevel int maximumMSAA = (int)device.Features[(DXGI.Format)format].MSAALevelMax; desc.SampleDescription.Count = Math.Max(1, Math.Min((int)multiSampleCount, maximumMSAA)); var typelessDepthFormat = (SharpDX.DXGI.Format)format; // If shader resource view are not required, don't use a TypeLess format if (shaderResource) { // Determine TypeLess Format and ShaderResourceView Format switch (format) { case DepthFormat.Depth16: typelessDepthFormat = SharpDX.DXGI.Format.R16_Typeless; break; case DepthFormat.Depth32: typelessDepthFormat = SharpDX.DXGI.Format.R32_Typeless; break; case DepthFormat.Depth24Stencil8: typelessDepthFormat = SharpDX.DXGI.Format.R24G8_Typeless; break; case DepthFormat.Depth32Stencil8X24: typelessDepthFormat = SharpDX.DXGI.Format.R32G8X24_Typeless; break; default: throw new InvalidOperationException(string.Format("Unsupported DepthFormat [{0}] for depth buffer", format)); } } desc.Format = typelessDepthFormat; return(desc); }
public bool TryReuse(PixelFormat format, int width, int height, TextureFlags flags, MSAALevel msaa) { return(IsFree && Texture.Format == format && Texture.Width == width && Texture.Height == height && Texture.Flags == flags && Texture.MultiSampleLevel == msaa); }
/// <summary> /// Creates a new texture description <see cref="RenderTarget2D" /> using multisampling. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">Describes the format to use.</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <param name="multiSampleCount">The multisample count.</param> /// <returns>A new instance of <see cref="RenderTarget2D" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static Texture2DDescription CreateDescription(GraphicsDevice device, int width, int height, MSAALevel multiSampleCount, PixelFormat format, int arraySize = 1) { if (multiSampleCount == MSAALevel.None) { throw new ArgumentException("Cannot declare a MSAA RenderTarget with MSAALevel.None. Use other non-MSAA constructors", "multiSampleCount"); } return CreateDescription(device.MainDevice, width, height, format, TextureFlags.RenderTarget, 1, arraySize, multiSampleCount); }
/// <summary> /// Initializes render target texture. /// </summary> /// <param name="format">The surface pixels format.</param> /// <param name="size">The surface size in pixels (width, height).</param> /// <param name="flags">The surface usage flags.</param> /// <param name="mipMaps">Number of mipmaps for the texture. Default is 1. Use 0 to allocate full mip chain.</param> /// <param name="multiSampleLevel">The surface multisampling level.</param> public void Init(PixelFormat format, Vector2 size, TextureFlags flags = TextureFlags.ShaderResource | TextureFlags.RenderTarget, int mipMaps = 1, MSAALevel multiSampleLevel = MSAALevel.None) { Init(format, (int)size.X, (int)size.Y, flags, mipMaps, multiSampleLevel); }
internal static Texture2DDescription CreateDescription(GraphicsDevice device, int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, MSAALevel multiSampleCount) { // Make sure that the texture to create is a render target textureFlags |= TextureFlags.RenderTarget; var desc = Texture2DBase.NewDescription(width, height, format, textureFlags, mipCount, arraySize, ResourceUsage.Default); // Sets the MSAALevel int maximumMSAA = (int)device.Features[format].MSAALevelMax; desc.SampleDescription.Count = Math.Max(1, Math.Min((int)multiSampleCount, maximumMSAA)); return(desc); }
internal static Texture2DDescription CreateDescription(GraphicsDevice device, int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, MSAALevel multiSampleCount) { // Make sure that the texture to create is a render target textureFlags |= TextureFlags.RenderTarget; var desc = Texture2DBase.NewDescription(width, height, format, textureFlags, mipCount, arraySize, ResourceUsage.Default); // Sets the MSAALevel int maximumMSAA = (int)device.Features[format].MSAALevelMax; desc.SampleDescription.Count = Math.Max(1, Math.Min((int)multiSampleCount, maximumMSAA)); return desc; }
/// <summary> /// Creates a new texture description <see cref="RenderTarget2D" /> using multisampling. /// </summary> /// <param name="device">The <see cref="GraphicsDevice"/>.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">Describes the format to use.</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <param name="multiSampleCount">The multisample count.</param> /// <returns>A new instance of <see cref="RenderTarget2D" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static Texture2DDescription CreateDescription(GraphicsDevice device, int width, int height, MSAALevel multiSampleCount, PixelFormat format, int arraySize = 1) { if (multiSampleCount == MSAALevel.None) { throw new ArgumentException("Cannot declare a MSAA RenderTarget with MSAALevel.None. Use other non-MSAA constructors", "multiSampleCount"); } return(CreateDescription(device.MainDevice, width, height, format, TextureFlags.RenderTarget, 1, arraySize, multiSampleCount)); }
/// <summary> /// Initializes a new instance of the <see cref="PresentationParameters" /> class with default values. /// </summary> public PresentationParameters() { BackBufferWidth = 800; BackBufferHeight = 480; BackBufferFormat = PixelFormat.R8G8B8A8.UNorm; PresentationInterval = PresentInterval.Immediate; DepthStencilFormat = DepthFormat.Depth24Stencil8; MultiSampleCount = MSAALevel.None; IsFullScreen = false; RefreshRate = new Rational(60, 1); // by default RenderTargetUsage = Usage.BackBuffer | Usage.RenderTargetOutput; Flags = SwapChainFlags.None; }
private static extern int Orbital_Video_D3D12_DepthStencil_Init(IntPtr handle, DepthStencilFormat format, uint width, uint height, MSAALevel msaaLevel);
public static unsafe extern int Orbital_Video_D3D12_Texture_Init(IntPtr handle, TextureFormat format, TextureType_NativeInterop type, uint mipLevels, uint *width, uint *height, uint *depth, byte **data, int isRenderTexture, int allowRandomAccess, MSAALevel msaaLevel, MultiGPUNodeResourceVisibility nodeVisibility);
public Temporary(PixelFormat format, int width, int height, TextureFlags flags, MSAALevel msaa) { Texture = New(); Texture.Init(format, width, height, flags, 1, msaa); }
/// <summary> /// Creates a new <see cref="DepthStencilBuffer" /> using multisampling. /// </summary> /// <param name="device">The <see cref="GraphicsDevice" />.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="multiSampleCount">The multisample count.</param> /// <param name="format">Describes the format to use.</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <param name="shaderResource">if set to <c>true</c> this depth stencil buffer can be set as an input to a shader (default: false).</param> /// <returns>A new instance of <see cref="DepthStencilBuffer" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static DepthStencilBuffer New(GraphicsDevice device, int width, int height, MSAALevel multiSampleCount, DepthFormat format, bool shaderResource = false, int arraySize = 1) { return(new DepthStencilBuffer(device, NewDepthStencilBufferDescription(device.MainDevice, width, height, format, multiSampleCount, arraySize, shaderResource), format)); }
public unsafe bool Init(int width, int height, DepthStencilFormat format, MSAALevel msaaLevel) { this.width = width; this.height = height; return(Orbital_Video_D3D12_DepthStencil_Init(handle, format, (uint)width, (uint)height, msaaLevel) != 0); }
/// <summary> /// Creates a new <see cref="DepthStencilBuffer" /> using multisampling. /// </summary> /// <param name="device">The <see cref="GraphicsDevice" />.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="multiSampleCount">The multisample count.</param> /// <param name="format">Describes the format to use.</param> /// <param name="arraySize">Size of the texture 2D array, default to 1.</param> /// <param name="shaderResource">if set to <c>true</c> this depth stencil buffer can be set as an input to a shader (default: false).</param> /// <returns>A new instance of <see cref="DepthStencilBuffer" /> class.</returns> /// <msdn-id>ff476521</msdn-id> /// <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged> /// <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short> public static DepthStencilBuffer New(GraphicsDevice device, int width, int height, MSAALevel multiSampleCount, DepthFormat format, bool shaderResource = false, int arraySize = 1) { return new DepthStencilBuffer(device, NewDepthStencilBufferDescription(device.MainDevice, width, height, format, multiSampleCount, arraySize, shaderResource), format); }
/// <summary>Creates a new depth stencil buffer description.</summary> /// <param name="device">The device.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="format">The format.</param> /// <param name="multiSampleCount">The multi sample count.</param> /// <param name="arraySize">Size of the array.</param> /// <param name="shaderResource">if set to <see langword="true" /> [shader resource].</param> /// <returns>Texture2DDescription.</returns> /// <exception cref="System.InvalidOperationException"></exception> protected static Texture2DDescription NewDepthStencilBufferDescription(GraphicsDevice device, int width, int height, DepthFormat format, MSAALevel multiSampleCount, int arraySize, bool shaderResource) { var desc = Texture2DBase.NewDescription(width, height, DXGI.Format.Unknown, TextureFlags.None, 1, arraySize, ResourceUsage.Default); desc.BindFlags |= BindFlags.DepthStencil; if (shaderResource) { desc.BindFlags |= BindFlags.ShaderResource; } // Sets the MSAALevel int maximumMSAA = (int)device.Features[(DXGI.Format)format].MSAALevelMax; desc.SampleDescription.Count = Math.Max(1, Math.Min((int)multiSampleCount, maximumMSAA)); var typelessDepthFormat = (SharpDX.DXGI.Format)format; // If shader resource view are not required, don't use a TypeLess format if (shaderResource) { // Determine TypeLess Format and ShaderResourceView Format switch (format) { case DepthFormat.Depth16: typelessDepthFormat = SharpDX.DXGI.Format.R16_Typeless; break; case DepthFormat.Depth32: typelessDepthFormat = SharpDX.DXGI.Format.R32_Typeless; break; case DepthFormat.Depth24Stencil8: typelessDepthFormat = SharpDX.DXGI.Format.R24G8_Typeless; break; case DepthFormat.Depth32Stencil8X24: typelessDepthFormat = SharpDX.DXGI.Format.R32G8X24_Typeless; break; default: throw new InvalidOperationException(string.Format("Unsupported DepthFormat [{0}] for depth buffer", format)); } } desc.Format = typelessDepthFormat; return desc; }