/// <summary>
        /// Initializes a new instance of the <see cref="DynamicTextureAtlas"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="width">The width of the texture atlas in pixels.</param>
        /// <param name="height">The height of the texture atlas in pixels.</param>
        /// <param name="spacing">The number of pixels between cells on the texture atlas.</param>
        /// <param name="options">The texture's configuration options.</param>
        private DynamicTextureAtlas(UltravioletContext uv, Int32 width, Int32 height, Int32 spacing, TextureOptions options)
            : base(uv)
        {
            Contract.EnsureRange(width > 0, nameof(width));
            Contract.EnsureRange(height > 0, nameof(height));
            Contract.EnsureRange(spacing >= 0, nameof(spacing));

            var isSrgb   = (options & TextureOptions.SrgbColor) == TextureOptions.SrgbColor;
            var isLinear = (options & TextureOptions.LinearColor) == TextureOptions.LinearColor;

            if (isSrgb && isLinear)
            {
                throw new ArgumentException(UltravioletStrings.TextureCannotHaveMultipleEncodings);
            }

            var caps        = uv.GetGraphics().Capabilities;
            var srgbEncoded = (isLinear ? false : (isSrgb ? true : uv.Properties.SrgbDefaultForTexture2D)) && caps.SrgbEncodingEnabled;
            var surfOptions = (srgbEncoded ? SurfaceOptions.SrgbColor : SurfaceOptions.LinearColor);

            this.IsFlipped = Ultraviolet.GetGraphics().Capabilities.FlippedTextures;

            this.Width   = width;
            this.Height  = height;
            this.Spacing = spacing;
            this.Surface = Surface2D.Create(width, height, surfOptions);
            this.Texture = Texture2D.CreateDynamicTexture(width, height, options, this, (dt2d, state) =>
            {
                ((DynamicTextureAtlas)state).Flush();
            });

            Clear(true);
            Invalidate();
        }
        /// <summary>
        /// Creates the output surface for a texture atlas.
        /// </summary>
        private static Surface2D CreateOutputSurface(TextureAtlasDescription atlasDesc, IEnumerable <TextureAtlasImage> atlasImages,
                                                     ContentManager content, IContentProcessorMetadata metadata, Int32 width, Int32 height, Dictionary <String, Rectangle> images)
        {
            var output = Surface2D.Create(width, height);

            foreach (var image in atlasImages)
            {
                var imageArea = images[image.Name];
                using (var imageSurface = content.Load <Surface2D>(image.Path, metadata.AssetDensity, false, metadata.IsLoadedFromSolution))
                {
                    var areaWithoutPadding = new Rectangle(
                        imageArea.X,
                        imageArea.Y,
                        imageArea.Width - atlasDesc.Metadata.Padding,
                        imageArea.Height - atlasDesc.Metadata.Padding);
                    imageSurface.Blit(output, areaWithoutPadding);
                }
            }

            return(output);
        }
Example #3
0
 /// <summary>
 /// Saves the specified surface as a JPEG image.
 /// </summary>
 /// <param name="surface">The surface to save.</param>
 /// <param name="stream">The stream to which to save the surface data.</param>
 public abstract void SaveAsJpeg(Surface2D surface, Stream stream);
Example #4
0
 /// <summary>
 /// Blits the surface onto the specified destination surface at the given location relative
 /// to the destination's top-left corner, optionally flipping this surface in the process.
 /// </summary>
 /// <param name="dst">The destination surface.</param>
 /// <param name="position">The position at which to blit the surface.</param>
 /// <param name="direction">The direction in which to flip the surface.</param>
 public abstract void Blit(Surface2D dst, Point2 position, SurfaceFlipDirection direction);
Example #5
0
 /// <summary>
 /// Blits the surface onto the specified destination surface at the given location relative
 /// to the destination's top-left corner, optionally flipping this surface in the process.
 /// </summary>
 /// <param name="dst">The destination surface.</param>
 /// <param name="position">The position at which to blit the surface.</param>
 public abstract void Blit(Surface2D dst, Point2 position);
Example #6
0
 /// <summary>
 /// Blits the surface onto the specified destination surface.
 /// </summary>
 /// <param name="srcRect">The area of this surface that will be copied to the destination surface.</param>
 /// <param name="dst">The destination surface.</param>
 /// <param name="dstRect">The area on the destination surface to which this surface will be copied.</param>
 public abstract void Blit(Rectangle srcRect, Surface2D dst, Rectangle dstRect);
Example #7
0
 /// <summary>
 /// Blits the surface onto the specified destination surface.
 /// </summary>
 /// <param name="dst">The destination surface.</param>
 /// <param name="dstRect">The area on the destination surface to which this surface will be copied.</param>
 public abstract void Blit(Surface2D dst, Rectangle dstRect);
Example #8
0
 /// <summary>
 /// Blits the surface onto the specified destination surface.
 /// </summary>
 /// <param name="dst">The destination surface.</param>
 public abstract void Blit(Surface2D dst);
Example #9
0
 /// <summary>
 /// Sets the texture's data.
 /// </summary>
 /// <param name="surface">The <see cref="Surface2D"/> which contains the data to set.</param>
 public abstract void SetData(Surface2D surface);
 /// <summary>
 /// Sets the <see cref="Surface2D"/> which represents the specified layer
 /// of this <see cref="Surface3D"/> instance.
 /// </summary>
 /// <param name="layer">The index of the layer to set.</param>
 /// <param name="surface">The <see cref="Surface2D"/> which represents the
 /// specified layer of this <see cref="Surface3D"/> instance.</param>
 /// <param name="transferOwnership">A value indicating whether ownership of the layer
 /// is transferred to this object. If so, the layer surface will be disposed when this object is disposed.</param>
 public abstract void SetLayer(Int32 layer, Surface2D surface, Boolean transferOwnership = false);