Files
OpenRA/OpenRa.Game/HardwarePalette.cs
chrisf d37bab15d0 wow, it works!
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1190 993157c7-ee19-0410-b2c4-bb4e9862e678
2007-07-13 09:15:06 +00:00

56 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using BluntDirectX.Direct3D;
using System.Drawing;
using System.IO;
using OpenRa.FileFormats;
namespace OpenRa.Game
{
class HardwarePalette
{
const int maxEntries = 16; // dont need anything like this many,
// but the hardware likes square textures better
Bitmap bitmap = new Bitmap(256, maxEntries);
GraphicsDevice device;
int allocated = 0;
Texture paletteTexture;
public HardwarePalette(GraphicsDevice device)
{
this.device = device;
}
void Resolve()
{
const string filename = "../../../palette-cache.png";
bitmap.Save(filename);
using (Stream s = File.OpenRead(filename))
paletteTexture = Texture.Create(s, device);
}
public Texture PaletteTexture
{
get
{
if (paletteTexture == null)
Resolve();
return paletteTexture;
}
}
public int AddPalette(Palette p)
{
for (int i = 0; i < 256; i++)
bitmap.SetPixel(i, allocated, p.GetColor(i));
return allocated++;
}
}
}