From 2215f749597f15c23bb802d3bd6f19a1e7e30460 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 13 Jun 2013 05:07:47 +1200 Subject: [PATCH] Support rendering sprites into non-rectangular quads. --- OpenRA.Game/Graphics/SpriteRenderer.cs | 15 +++++++++++++++ OpenRA.Game/Graphics/Util.cs | 20 ++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/OpenRA.Game/Graphics/SpriteRenderer.cs b/OpenRA.Game/Graphics/SpriteRenderer.cs index 465db7ce75..14049bb4af 100644 --- a/OpenRA.Game/Graphics/SpriteRenderer.cs +++ b/OpenRA.Game/Graphics/SpriteRenderer.cs @@ -81,6 +81,21 @@ namespace OpenRA.Graphics 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 buffer, int start, int length, PrimitiveType type, Sheet sheet) { shader.SetTexture("DiffuseTexture", sheet.Texture); diff --git a/OpenRA.Game/Graphics/Util.cs b/OpenRA.Game/Graphics/Util.cs index 98673f2486..c859121b9d 100644 --- a/OpenRA.Game/Graphics/Util.cs +++ b/OpenRA.Game/Graphics/Util.cs @@ -18,17 +18,21 @@ namespace OpenRA.Graphics 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) + { + 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]); - vertices[nv] = new Vertex(o, - r.FastMapTextureCoords(0), attrib); - vertices[nv + 1] = new Vertex(new float2(o.X + size.X, o.Y), - r.FastMapTextureCoords(1), 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); + 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); } static readonly int[] channelMasks = { 2, 1, 0, 3 }; // yes, our channel order is nuts.