Don't store pre-calculated texture coords in Sprite.
By storing only the four corners, we can save the object overhead of an array and 4 float elements per sprite. This results in savings of around 5 MiB to store these coordinates.
This commit is contained in:
@@ -21,7 +21,7 @@ namespace OpenRA.Graphics
|
||||
public readonly float2 size;
|
||||
public readonly float2 offset;
|
||||
public readonly float2 fractionalOffset;
|
||||
readonly float2[] textureCoords;
|
||||
readonly float top, left, bottom, right;
|
||||
|
||||
public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel)
|
||||
: this(sheet, bounds, float2.Zero, channel, BlendMode.Alpha) {}
|
||||
@@ -40,22 +40,30 @@ namespace OpenRA.Graphics
|
||||
|
||||
this.fractionalOffset = offset / this.size;
|
||||
|
||||
var left = (float)(bounds.Left) / sheet.Size.Width;
|
||||
var top = (float)(bounds.Top) / sheet.Size.Height;
|
||||
var right = (float)(bounds.Right) / sheet.Size.Width;
|
||||
var bottom = (float)(bounds.Bottom) / sheet.Size.Height;
|
||||
textureCoords = new float2[]
|
||||
{
|
||||
new float2(left, top),
|
||||
new float2(right, top),
|
||||
new float2(left, bottom),
|
||||
new float2(right, bottom),
|
||||
};
|
||||
left = (float)(bounds.Left) / sheet.Size.Width;
|
||||
top = (float)(bounds.Top) / sheet.Size.Height;
|
||||
right = (float)(bounds.Right) / sheet.Size.Width;
|
||||
bottom = (float)(bounds.Bottom) / sheet.Size.Height;
|
||||
}
|
||||
|
||||
public float2 FastMapTextureCoords(int k)
|
||||
public float2 TopLeftTextureCoords
|
||||
{
|
||||
return textureCoords[k];
|
||||
get { return new float2(left, top); }
|
||||
}
|
||||
|
||||
public float2 TopRightTextureCoords
|
||||
{
|
||||
get { return new float2(right, top); }
|
||||
}
|
||||
|
||||
public float2 BottomLeftTextureCoords
|
||||
{
|
||||
get { return new float2(left, bottom); }
|
||||
}
|
||||
|
||||
public float2 BottomRightTextureCoords
|
||||
{
|
||||
get { return new float2(right, bottom); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
var attrib = new float2(palette / (float)HardwarePalette.MaxPalettes, channelSelect[(int)r.channel]);
|
||||
|
||||
vertices[nv] = new Vertex(a, r.FastMapTextureCoords(0), attrib);
|
||||
vertices[nv + 1] = new Vertex(b, r.FastMapTextureCoords(1), attrib);
|
||||
vertices[nv + 2] = new Vertex(c, r.FastMapTextureCoords(3), attrib);
|
||||
vertices[nv + 3] = new Vertex(d, r.FastMapTextureCoords(2), attrib);
|
||||
vertices[nv] = new Vertex(a, r.TopLeftTextureCoords, attrib);
|
||||
vertices[nv + 1] = new Vertex(b, r.TopRightTextureCoords, attrib);
|
||||
vertices[nv + 2] = new Vertex(c, r.BottomRightTextureCoords, attrib);
|
||||
vertices[nv + 3] = new Vertex(d, r.BottomLeftTextureCoords, attrib);
|
||||
}
|
||||
|
||||
static readonly int[] channelMasks = { 2, 1, 0, 3 }; // yes, our channel order is nuts.
|
||||
|
||||
@@ -90,10 +90,10 @@ namespace OpenRA.Graphics
|
||||
var channels = new float2(channelSelect[(int)s.channel], channelSelect[(int)s.channel + 1]);
|
||||
return new Vertex[4]
|
||||
{
|
||||
new Vertex(coord(0, 0), s.FastMapTextureCoords(0), channels),
|
||||
new Vertex(coord(su, 0), s.FastMapTextureCoords(1), channels),
|
||||
new Vertex(coord(su, sv), s.FastMapTextureCoords(3), channels),
|
||||
new Vertex(coord(0, sv), s.FastMapTextureCoords(2), channels)
|
||||
new Vertex(coord(0, 0), s.TopLeftTextureCoords, channels),
|
||||
new Vertex(coord(su, 0), s.TopRightTextureCoords, channels),
|
||||
new Vertex(coord(su, sv), s.BottomRightTextureCoords, channels),
|
||||
new Vertex(coord(0, sv), s.BottomLeftTextureCoords, channels)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user