Record the SheetType in each Sheet.

This commit is contained in:
Paul Chote
2015-09-28 18:23:25 +01:00
parent 426e187a4c
commit e819ff832b
13 changed files with 23 additions and 18 deletions

View File

@@ -106,7 +106,7 @@ namespace OpenRA.Graphics
sheet = cachedSheets[mi.Src];
else
{
sheet = new Sheet(mi.Src);
sheet = new Sheet(SheetType.BGRA, mi.Src);
cachedSheets.Add(mi.Src, sheet);
}

View File

@@ -24,6 +24,8 @@ namespace OpenRA.Graphics
byte[] data;
public readonly Size Size;
public readonly SheetType Type;
public byte[] GetData()
{
CreateBuffer();
@@ -32,18 +34,20 @@ namespace OpenRA.Graphics
public bool Buffered { get { return data != null || texture == null; } }
public Sheet(Size size)
public Sheet(SheetType type, Size size)
{
Type = type;
Size = size;
}
public Sheet(ITexture texture)
public Sheet(SheetType type, ITexture texture)
{
Type = type;
this.texture = texture;
Size = texture.Size;
}
public Sheet(string filename)
public Sheet(SheetType type, string filename)
{
using (var stream = GlobalFileSystem.Open(filename))
using (var bitmap = (Bitmap)Image.FromStream(stream))
@@ -54,6 +58,7 @@ namespace OpenRA.Graphics
Util.FastCopyIntoSprite(new Sprite(this, bitmap.Bounds(), TextureChannel.Red), bitmap);
}
Type = type;
ReleaseBuffer();
}

View File

@@ -40,16 +40,16 @@ namespace OpenRA.Graphics
int rowHeight = 0;
Point p;
public static Sheet AllocateSheet(int sheetSize)
public static Sheet AllocateSheet(SheetType type, int sheetSize)
{
return new Sheet(new Size(sheetSize, sheetSize));
return new Sheet(type, new Size(sheetSize, sheetSize));
}
public SheetBuilder(SheetType t)
: this(t, Game.Settings.Graphics.SheetSize) { }
public SheetBuilder(SheetType t, int sheetSize)
: this(t, () => AllocateSheet(sheetSize)) { }
: this(t, () => AllocateSheet(t, sheetSize)) { }
public SheetBuilder(SheetType t, Func<Sheet> allocateSheet)
{

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Graphics
throw new SheetOverflowException("Terrain sheet overflow. Try increasing the tileset SheetSize parameter.");
allocated = true;
return new Sheet(new Size(tileset.SheetSize, tileset.SheetSize));
return new Sheet(SheetType.Indexed, new Size(tileset.SheetSize, tileset.SheetSize));
};
sheetBuilder = new SheetBuilder(SheetType.Indexed, allocate);

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Graphics
if (allocated)
throw new SheetOverflowException("");
allocated = true;
return SheetBuilder.AllocateSheet(Game.Settings.Graphics.SheetSize);
return SheetBuilder.AllocateSheet(SheetType.DualIndexed, Game.Settings.Graphics.SheetSize);
};
return new SheetBuilder(SheetType.DualIndexed, allocate);

View File

@@ -331,7 +331,7 @@ namespace OpenRA.Graphics
var size = new Size(renderer.SheetSize, renderer.SheetSize);
var framebuffer = renderer.Device.CreateFrameBuffer(size);
var sheet = new Sheet(framebuffer.Texture);
var sheet = new Sheet(SheetType.DualIndexed, framebuffer.Texture);
mappedBuffers.Add(sheet, framebuffer);
return sheet;