Example #1
0
        /// <summary>
        /// Creates a texture that can be used as a ShaderResource from an existing depth texture.
        /// </summary>
        /// <returns></returns>
        public Texture2D ToDepthTextureCompatible()
        {
            if ((Description.Flags & TextureFlags.DepthStencil) == 0)
            {
                throw new NotSupportedException("This texture is not a valid depth stencil texture");
            }

            var description = Description;

            description.Format = (PixelFormat)DepthStencilBuffer.ComputeShaderResourceFormat((Format)Description.Format);
            if (description.Format == PixelFormat.None)
            {
                throw new NotSupportedException("This depth stencil format is not supported");
            }

            description.Flags = TextureFlags.ShaderResource;
            return(New(GraphicsDevice, description));
        }