Ejemplo n.º 1
0
        /// <summary>
        /// Creates a texture from an image file data (png, dds, ...).
        /// </summary>
        /// <param name="graphicsDevice">The graphics device in which to create the texture</param>
        /// <param name="data">The image file data</param>
        /// <returns>The texture</returns>
        public static Texture FromFileData(GraphicsDevice graphicsDevice, byte[] data)
        {
            Texture result;

            var loadAsSRgb = graphicsDevice.ColorSpace == ColorSpace.Linear;

            using (var imageStream = new MemoryStream(data))
            {
                using (var image = Image.Load(imageStream, loadAsSRgb))
                {
                    result = Texture.New(graphicsDevice, image);
                }
            }

            result.Reload = graphicsResource =>
            {
                using (var imageStream = new MemoryStream(data))
                {
                    using (var image = Image.Load(imageStream, loadAsSRgb))
                    {
                        ((Texture)graphicsResource).Recreate(image.ToDataBox());
                    }
                }
            };

            return(result);
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a texture from an image file data (png, dds, ...).
        /// </summary>
        /// <param name="graphicsDevice">The graphics device in which to create the texture</param>
        /// <param name="data">The image file data</param>
        /// <returns>The texture</returns>
        public static Texture FromFileData(GraphicsDevice graphicsDevice, byte[] data)
        {
            Texture result;

            using (var imageStream = new MemoryStream(data))
            {
                using (var image = Image.Load(imageStream))
                    result = Texture.New(graphicsDevice, image);
            }

            result.Reload = graphicsResource =>
            {
                using (var imageStream = new MemoryStream(data))
                {
                    using (var image = Image.Load(imageStream))
                        ((Texture)graphicsResource).Recreate(image.ToDataBox());
                }
            };

            return(result);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a texture for output.
 /// </summary>
 /// <param name="description">The description.</param>
 /// <param name="viewFormat">The pixel format seen by the shader</param>
 /// <returns>Texture.</returns>
 protected virtual Texture CreateTexture(TextureDescription description, PixelFormat viewFormat)
 {
     return(Texture.New(GraphicsDevice, description));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a texture for output.
 /// </summary>
 /// <param name="description">The description.</param>
 /// <returns>Texture.</returns>
 protected virtual Texture CreateTexture(TextureDescription description)
 {
     return(Texture.New(GraphicsDevice, description));
 }