Exemplo n.º 1
0
 private void CreateNonMSAADepthStencilBuffer(int width, int height)
 {
     if (HasMSAA)
     {
         var depthFormat = Format.D32_Float_S8X24_UInt;
         var depthdesc   = new Texture2DDescription
         {
             BindFlags         = BindFlags.DepthStencil | BindFlags.ShaderResource,
             Format            = DepthStencilFormatHelper.ComputeTextureFormat(depthFormat, out _),
             Width             = width,
             Height            = height,
             MipLevels         = 1,
             SampleDescription = new SampleDescription(1, 0),
             Usage             = ResourceUsage.Default,
             OptionFlags       = ResourceOptionFlags.None,
             CpuAccessFlags    = CpuAccessFlags.None,
             ArraySize         = 1,
         };
         depthStencilBufferNoMSAA = new ShaderResourceViewProxy(Device, depthdesc);
         depthStencilBufferNoMSAA.CreateDepthStencilView(new DepthStencilViewDescription()
         {
             Format    = DepthStencilFormatHelper.ComputeDSVFormat(depthFormat),
             Dimension = DepthStencilViewDimension.Texture2D
         });
         depthStencilBufferNoMSAA.CreateTextureView(new ShaderResourceViewDescription()
         {
             Format    = DepthStencilFormatHelper.ComputeSRVFormat(depthFormat),
             Dimension = global::SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D,
             Texture2D = new ShaderResourceViewDescription.Texture2DResource()
             {
                 MipLevels = 1
             }
         });
     }
     else
     {
         depthStencilBufferNoMSAA = depthStencilBuffer;
     }
 }
Exemplo n.º 2
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="width"></param>
            /// <param name="height"></param>
            /// <param name="createDepthStencilBuffer"></param>
            /// <param name="colorBuffer"></param>
            /// <param name="depthStencilBuffer"></param>
            /// <returns></returns>
            protected virtual void OnCreateRenderTargetAndDepthBuffers(int width, int height, bool createDepthStencilBuffer,
                                                                       out ShaderResourceViewProxy colorBuffer, out ShaderResourceViewProxy depthStencilBuffer)
            {
                var sampleDesc  = ColorBufferSampleDesc;
                var optionFlags = ResourceOptionFlags.None;

                var colordesc = new Texture2DDescription
                {
                    BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                    Format            = Format,
                    Width             = width,
                    Height            = height,
                    MipLevels         = 1,
                    SampleDescription = sampleDesc,
                    Usage             = ResourceUsage.Default,
                    OptionFlags       = optionFlags,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    ArraySize         = 1
                };

                colorBuffer = new ShaderResourceViewProxy(Device, colordesc);
                colorBuffer.CreateRenderTargetView();
                colorBuffer.CreateTextureView();
                if (createDepthStencilBuffer)
                {
                    var depthdesc = new Texture2DDescription
                    {
                        BindFlags         = BindFlags.DepthStencil,
                        Format            = DepthStencilFormatHelper.ComputeTextureFormat(Format.D32_Float_S8X24_UInt, out var canUseAsShaderResource),
                        Width             = width,
                        Height            = height,
                        MipLevels         = 1,
                        SampleDescription = sampleDesc,
                        Usage             = ResourceUsage.Default,
                        OptionFlags       = ResourceOptionFlags.None,
                        CpuAccessFlags    = CpuAccessFlags.None,
                        ArraySize         = 1,
                    };
                    canUseAsShaderResource &= !HasMSAA;
                    if (canUseAsShaderResource)
                    {
                        depthdesc.BindFlags |= BindFlags.ShaderResource;
                    }
                    depthStencilBuffer = new ShaderResourceViewProxy(Device, depthdesc);
                    depthStencilBuffer.CreateDepthStencilView(
                        new DepthStencilViewDescription()
                    {
                        Format    = DepthStencilFormatHelper.ComputeDSVFormat(depthdesc.Format),
                        Dimension = HasMSAA ? DepthStencilViewDimension.Texture2DMultisampled : DepthStencilViewDimension.Texture2D
                    });
                    if (canUseAsShaderResource)
                    {
                        depthStencilBuffer.CreateTextureView(new ShaderResourceViewDescription()
                        {
                            Format    = DepthStencilFormatHelper.ComputeSRVFormat(depthdesc.Format),
                            Dimension = global::SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D,
                            Texture2D = new ShaderResourceViewDescription.Texture2DResource()
                            {
                                MipLevels = depthdesc.MipLevels
                            }
                        });
                    }
                }
                else
                {
                    depthStencilBuffer = null;
                }
            }