protected override void CreateInternal(byte[] data) { base.CreateInternal(data); if (Content == null) { return; } // Load the base texture. BaseTexture = Engine.AssetLoader.Get <PaletteBaseTexture>(Content.BaseAsset); Debug.Assert(BaseTexture != null); Debug.Assert(BaseTexture.PaletteMap != null); // Load all variations. var pixels = new byte[BaseTexture.PaletteMap.Length * 4]; foreach (Palette p in Content.Palettes) { for (var j = 0; j < pixels.Length; j += 4) { byte index = BaseTexture.PaletteMap[j / 4]; if (index >= p.Colors.Length) { index = 0; } Color c = p.Colors[index]; pixels[j] = c.B; pixels[j + 1] = c.G; pixels[j + 2] = c.R; pixels[j + 3] = c.A; } GLThread.ExecuteGLThread(() => { var texture = new Texture(BaseTexture.Texture.Size); texture.Upload(BaseTexture.Texture.Size, pixels); texture.FlipY = BaseTexture.Texture.FlipY; PaletteSwaps.Add(p, texture); }); } // Free up the palette map memory. BaseTexture.PaletteMap = null; }
protected override void CreateInternal(ReadOnlyMemory <byte> data) { base.CreateInternal(data); if (Content == null) { return; } // Load the base texture. BaseTexture = Engine.AssetLoader.Get <PaletteBaseTexture>(Content.BaseAsset); Debug.Assert(BaseTexture != null); Debug.Assert(BaseTexture.PaletteMap != null); // Load all variations. var pixels = new byte[BaseTexture.PaletteMap.Length * 4]; Span <Color> pixelsAsColor = MemoryMarshal.Cast <byte, Color>(pixels); foreach (Palette p in Content.Palettes) { for (var j = 0; j < pixelsAsColor.Length; j++) { byte index = BaseTexture.PaletteMap[j]; if (index >= p.Colors.Length) { index = 0; } Color c = p.Colors[index]; pixelsAsColor[j] = c; } GLThread.ExecuteGLThread(() => { var texture = new Texture(BaseTexture.Texture.Size, PixelFormat.Rgba); texture.Upload(BaseTexture.Texture.Size, pixels); texture.FlipY = BaseTexture.Texture.FlipY; PaletteSwaps.Add(p, texture); }); } // Free up the palette map memory. BaseTexture.PaletteMap = null; }