ConvertToSRV() публичный статический Метод

public static ConvertToSRV ( DepthFormat format ) : SharpDX.DXGI.Format
format DepthFormat
Результат SharpDX.DXGI.Format
Пример #1
0
        /// <summary>
        /// Creates depth stencil texture, view and shader resource with format D24S8
        /// </summary>
        /// <param name="rs"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="format"></param>
        public DepthStencil2D(GraphicsDevice device, DepthFormat format, int width, int height, int samples = 1) : base(device)
        {
            Log.Debug("DepthStencil2D: f:{0} w:{1} h:{2} s:{3}", format, width, height, samples);
            CheckSamplesCount(samples);

            Width       = width;
            Height      = height;
            Depth       = 1;
            Format      = format;
            SampleCount = samples;

            var bindFlags = BindFlags.DepthStencil;


            if (device.GraphicsProfile == GraphicsProfile.HiDef)
            {
                bindFlags |= BindFlags.ShaderResource;
            }
            else if (device.GraphicsProfile == GraphicsProfile.Reach)
            {
                if (samples == 1)
                {
                    bindFlags |= BindFlags.ShaderResource;
                }
            }


            var texDesc = new Texture2DDescription();

            texDesc.Width             = width;
            texDesc.Height            = height;
            texDesc.ArraySize         = 1;
            texDesc.BindFlags         = bindFlags;
            texDesc.CpuAccessFlags    = CpuAccessFlags.None;
            texDesc.Format            = Converter.ConvertToTex(format);
            texDesc.MipLevels         = 1;
            texDesc.OptionFlags       = ResourceOptionFlags.None;
            texDesc.SampleDescription = new DXGI.SampleDescription(samples, 0);
            texDesc.Usage             = ResourceUsage.Default;

            var dsvDesc = new DepthStencilViewDescription();

            dsvDesc.Dimension = samples > 1 ? DepthStencilViewDimension.Texture2DMultisampled : DepthStencilViewDimension.Texture2D;
            dsvDesc.Format    = Converter.ConvertToDSV(format);
            dsvDesc.Flags     = DepthStencilViewFlags.None;

            var srvDesc = new ShaderResourceViewDescription();

            srvDesc.Dimension = samples > 1 ? ShaderResourceViewDimension.Texture2DMultisampled : ShaderResourceViewDimension.Texture2D;
            srvDesc.Format    = Converter.ConvertToSRV(format);
            srvDesc.Texture2D.MostDetailedMip = 0;
            srvDesc.Texture2D.MipLevels       = 1;

            tex2D = new D3D.Texture2D(device.Device, texDesc);

            var dsv = new DepthStencilView(device.Device, tex2D, dsvDesc);

            if (bindFlags.HasFlag(BindFlags.ShaderResource))
            {
                SRV = new ShaderResourceView(device.Device, tex2D, srvDesc);
            }

            surface = new DepthStencilSurface(dsv, format, width, height, samples);
        }
Пример #2
0
        /// <summary>
        /// Creates render target
        /// </summary>
        /// <param name="rs"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="format"></param>
        public DepthStencilCube(GraphicsDevice device, DepthFormat format, int size, int samples, string debugName = "") : base(device)
        {
            bool msaa = samples > 1;

            CheckSamplesCount(samples);

            SampleCount = samples;

            Format      = format;
            SampleCount = samples;
            Width       = size;
            Height      = size;
            Depth       = 1;

            var texDesc = new Texture2DDescription();

            texDesc.Width             = Width;
            texDesc.Height            = Height;
            texDesc.ArraySize         = 6;
            texDesc.BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource;
            texDesc.CpuAccessFlags    = CpuAccessFlags.None;
            texDesc.Format            = Converter.ConvertToTex(format);
            texDesc.MipLevels         = 1;
            texDesc.OptionFlags       = ResourceOptionFlags.TextureCube;
            texDesc.SampleDescription = new DXGI.SampleDescription(samples, 0);
            texDesc.Usage             = ResourceUsage.Default;


            texCube = new D3D.Texture2D(device.Device, texDesc);


            var srvDesc = new ShaderResourceViewDescription();

            srvDesc.Dimension = samples > 1 ? ShaderResourceViewDimension.Texture2DMultisampled : ShaderResourceViewDimension.Texture2D;
            srvDesc.Format    = Converter.ConvertToSRV(format);
            srvDesc.Texture2D.MostDetailedMip = 0;
            srvDesc.Texture2D.MipLevels       = 1;

            SRV = new ShaderResourceView(device.Device, texCube);



            //
            //	Create surfaces :
            //
            surfaces = new DepthStencilSurface[6];

            for (int face = 0; face < 6; face++)
            {
                var rtvDesc = new DepthStencilViewDescription();
                rtvDesc.Texture2DArray.MipSlice        = 0;
                rtvDesc.Texture2DArray.FirstArraySlice = face;
                rtvDesc.Texture2DArray.ArraySize       = 1;
                rtvDesc.Dimension = msaa ? DepthStencilViewDimension.Texture2DMultisampledArray : DepthStencilViewDimension.Texture2DArray;
                rtvDesc.Format    = Converter.ConvertToDSV(format);

                var dsv = new DepthStencilView(device.Device, texCube, rtvDesc);

                int subResId = Resource.CalculateSubResourceIndex(0, face, 1);

                surfaces[face] = new DepthStencilSurface(dsv, format, Width, Height, SampleCount);
            }
        }