Implement dynamic hardware palette sizing.
The HardwarePalette will now grow its palette buffer and texture in power-of-2 increments. This avoids it having to allocate memory for a full 256x256 texture up front. In practice the default mods use 22 or 23 palettes so a 32x256 texture is used. This means both the buffer and texture save neatly on memory. Additionally, HardwarePalette.ApplyModifiers sees a nice speedup as it has to transfer a much smaller amount of memory from the buffer to the texture. To facilitate this change, the MaxPalettes constant is no more. Instead the PaletteReference deals with the calculation of the index and this is passed into the appropriate methods.
This commit is contained in:
@@ -19,13 +19,17 @@ namespace OpenRA.Graphics
|
||||
public class PaletteReference
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly int Index;
|
||||
public IPalette Palette { get; internal set; }
|
||||
public PaletteReference(string name, int index, IPalette palette)
|
||||
readonly float index;
|
||||
readonly HardwarePalette hardwarePalette;
|
||||
public float TextureIndex { get { return index / hardwarePalette.Height; } }
|
||||
public float TextureMidIndex { get { return (index + 0.5f) / hardwarePalette.Height; } }
|
||||
public PaletteReference(string name, int index, IPalette palette, HardwarePalette hardwarePalette)
|
||||
{
|
||||
Name = name;
|
||||
Index = index;
|
||||
Palette = palette;
|
||||
this.index = index;
|
||||
this.hardwarePalette = hardwarePalette;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +63,7 @@ namespace OpenRA.Graphics
|
||||
PaletteReference CreatePaletteReference(string name)
|
||||
{
|
||||
var pal = palette.GetPalette(name);
|
||||
return new PaletteReference(name, palette.GetPaletteIndex(name), pal);
|
||||
return new PaletteReference(name, palette.GetPaletteIndex(name), pal, palette);
|
||||
}
|
||||
|
||||
public PaletteReference Palette(string name) { return palettes.GetOrAdd(name, CreatePaletteReference); }
|
||||
|
||||
Reference in New Issue
Block a user