Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new texture that can be used as a ShaderResource from an existing depth texture.
        /// </summary>
        /// <returns></returns>
        public static Texture CreateDepthTextureCompatible(this Texture texture)
        {
            if (!texture.IsDepthStencil)
            {
                throw new NotSupportedException("This texture is not a valid depth stencil texture");
            }

            var description = texture.Description;

            description.Format = (PixelFormat)Texture.ComputeShaderResourceFormatFromDepthFormat(description.Format); // TODO: review this
            if (description.Format == PixelFormat.None)
            {
                throw new NotSupportedException("This depth stencil format is not supported");
            }

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