Support rendering sprites into non-rectangular quads.
This commit is contained in:
@@ -81,6 +81,21 @@ namespace OpenRA.Graphics
|
|||||||
DrawSprite(s, location, 0, size);
|
DrawSprite(s, location, 0, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DrawSprite(Sprite s, float2 a, float2 b, float2 c, float2 d)
|
||||||
|
{
|
||||||
|
Renderer.CurrentBatchRenderer = this;
|
||||||
|
|
||||||
|
if (s.sheet != currentSheet)
|
||||||
|
Flush();
|
||||||
|
|
||||||
|
if (nv + 4 > Renderer.TempBufferSize)
|
||||||
|
Flush();
|
||||||
|
|
||||||
|
currentSheet = s.sheet;
|
||||||
|
Util.FastCreateQuad(vertices, a, b, c, d, s, 0, nv);
|
||||||
|
nv += 4;
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawVertexBuffer(IVertexBuffer<Vertex> buffer, int start, int length, PrimitiveType type, Sheet sheet)
|
public void DrawVertexBuffer(IVertexBuffer<Vertex> buffer, int start, int length, PrimitiveType type, Sheet sheet)
|
||||||
{
|
{
|
||||||
shader.SetTexture("DiffuseTexture", sheet.Texture);
|
shader.SetTexture("DiffuseTexture", sheet.Texture);
|
||||||
|
|||||||
@@ -18,17 +18,21 @@ namespace OpenRA.Graphics
|
|||||||
static float[] channelSelect = { 0.75f, 0.25f, -0.25f, -0.75f };
|
static float[] channelSelect = { 0.75f, 0.25f, -0.25f, -0.75f };
|
||||||
|
|
||||||
public static void FastCreateQuad(Vertex[] vertices, float2 o, Sprite r, int palette, int nv, float2 size)
|
public static void FastCreateQuad(Vertex[] vertices, float2 o, Sprite r, int palette, int nv, float2 size)
|
||||||
|
{
|
||||||
|
var b = new float2(o.X + size.X, o.Y);
|
||||||
|
var c = new float2(o.X + size.X, o.Y + size.Y);
|
||||||
|
var d = new float2(o.X, o.Y + size.Y);
|
||||||
|
FastCreateQuad(vertices, o, b, c, d, r, palette, nv);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void FastCreateQuad(Vertex[] vertices, float2 a, float2 b, float2 c, float2 d, Sprite r, int palette, int nv)
|
||||||
{
|
{
|
||||||
var attrib = new float2(palette / (float)HardwarePalette.MaxPalettes, channelSelect[(int)r.channel]);
|
var attrib = new float2(palette / (float)HardwarePalette.MaxPalettes, channelSelect[(int)r.channel]);
|
||||||
|
|
||||||
vertices[nv] = new Vertex(o,
|
vertices[nv] = new Vertex(a, r.FastMapTextureCoords(0), attrib);
|
||||||
r.FastMapTextureCoords(0), attrib);
|
vertices[nv + 1] = new Vertex(b, r.FastMapTextureCoords(1), attrib);
|
||||||
vertices[nv + 1] = new Vertex(new float2(o.X + size.X, o.Y),
|
vertices[nv + 2] = new Vertex(c, r.FastMapTextureCoords(3), attrib);
|
||||||
r.FastMapTextureCoords(1), attrib);
|
vertices[nv + 3] = new Vertex(d, r.FastMapTextureCoords(2), attrib);
|
||||||
vertices[nv + 2] = new Vertex(new float2(o.X + size.X, o.Y + size.Y),
|
|
||||||
r.FastMapTextureCoords(3), attrib);
|
|
||||||
vertices[nv + 3] = new Vertex(new float2(o.X, o.Y + size.Y),
|
|
||||||
r.FastMapTextureCoords(2), attrib);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static readonly int[] channelMasks = { 2, 1, 0, 3 }; // yes, our channel order is nuts.
|
static readonly int[] channelMasks = { 2, 1, 0, 3 }; // yes, our channel order is nuts.
|
||||||
|
|||||||
Reference in New Issue
Block a user