Esempio 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the depth stencil buffer.
        /// </summary>
        protected virtual void CreateDepthStencilBuffer()
        {
            // If no depth stencil buffer, just return
            if (Description.DepthStencilFormat == PixelFormat.None)
            {
                return;
            }

            // Creates the depth stencil buffer.
            var flags = TextureFlags.DepthStencil;

            if (GraphicsDevice.Features.CurrentProfile >= GraphicsProfile.Level_10_0 && Description.MultiSampleLevel == MSAALevel.None)
            {
                flags |= TextureFlags.ShaderResource;
            }

            // Create texture description
            var depthTextureDescription = TextureDescription.New2D(Description.BackBufferWidth, Description.BackBufferHeight, Description.DepthStencilFormat, flags);

            depthTextureDescription.MultiSampleLevel = Description.MultiSampleLevel;

            var depthTexture = Texture.New(GraphicsDevice, depthTextureDescription);

            DepthStencilBuffer = depthTexture.DisposeBy(this);
        }
Esempio n. 3
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 = 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));
        }
 /// <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));
 }