Beispiel #1
0
        public void Update(GraphicsDevice Device)
        {
            if (!CompositeValid)
            {
                CompositeValid = true;
                Layers.Sort((a, b) => a.Layer.Precedence - b.Layer.Precedence);

                // Render the composite texture
                var maxSize = new Point(0, 0);
                foreach (var layer in Layers)
                {
                    maxSize.X = Math.Max(layer.Layer.CachedTexture.Width, maxSize.X);
                    maxSize.Y = Math.Max(layer.Layer.CachedTexture.Height, maxSize.Y);
                }

                if (maxSize.X == 0 || maxSize.Y == 0)
                {
                    return;
                }

                if (MemoryComposite == null || MemoryComposite.Width != maxSize.X || MemoryComposite.Height != maxSize.Y)
                {
                    MemoryComposite = new MemoryTexture(maxSize.X, maxSize.Y);
                }

                TextureTool.ClearMemoryTexture(MemoryComposite);

                foreach (var layer in Layers)
                {
                    TextureTool.Blit(layer.Layer.CachedTexture, layer.Palette.CachedPalette, MemoryComposite);
                }

                Composite = TextureTool.Texture2DFromMemoryTexture(Device, MemoryComposite);
            }
        }