From 69125989ab9943631ee46bfb8cbc76a02ca686aa Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Fri, 10 Oct 2014 09:38:14 +0100 Subject: [PATCH] Changed Vertex constructors to pass more parameters as plain floats. This avoids callers having to construct a float2 struct, only to have the Vertex constructor unwrap it into individual components again. --- OpenRA.Game/Graphics/LineRenderer.cs | 8 ++++---- OpenRA.Game/Graphics/QuadRenderer.cs | 14 +++++++++----- OpenRA.Game/Graphics/Sprite.cs | 22 +--------------------- OpenRA.Game/Graphics/Util.cs | 11 ++++++----- OpenRA.Game/Graphics/Vertex.cs | 12 ++++++------ OpenRA.Game/Graphics/VoxelLoader.cs | 11 ++++++----- 6 files changed, 32 insertions(+), 46 deletions(-) diff --git a/OpenRA.Game/Graphics/LineRenderer.cs b/OpenRA.Game/Graphics/LineRenderer.cs index 2b16179a97..4c7f240942 100644 --- a/OpenRA.Game/Graphics/LineRenderer.cs +++ b/OpenRA.Game/Graphics/LineRenderer.cs @@ -77,12 +77,12 @@ namespace OpenRA.Graphics Flush(); vertices[nv++] = new Vertex(start + offset, - new float2(startColor.R / 255.0f, startColor.G / 255.0f), - new float2(startColor.B / 255.0f, startColor.A / 255.0f)); + startColor.R / 255.0f, startColor.G / 255.0f, + startColor.B / 255.0f, startColor.A / 255.0f); vertices[nv++] = new Vertex(end + offset, - new float2(endColor.R / 255.0f, endColor.G / 255.0f), - new float2(endColor.B / 255.0f, endColor.A / 255.0f)); + endColor.R / 255.0f, endColor.G / 255.0f, + endColor.B / 255.0f, endColor.A / 255.0f); } public void FillRect(RectangleF r, Color color) diff --git a/OpenRA.Game/Graphics/QuadRenderer.cs b/OpenRA.Game/Graphics/QuadRenderer.cs index f46ae03628..21a48d3dc0 100644 --- a/OpenRA.Game/Graphics/QuadRenderer.cs +++ b/OpenRA.Game/Graphics/QuadRenderer.cs @@ -43,17 +43,21 @@ namespace OpenRA.Graphics } } - public void FillRect(RectangleF r, Color color) + public void FillRect(RectangleF rect, Color color) { Renderer.CurrentBatchRenderer = this; if (nv + 4 > Renderer.TempBufferSize) Flush(); - vertices[nv] = new Vertex(new float2(r.Left, r.Top), new float2(color.R / 255.0f, color.G / 255.0f), new float2(color.B / 255.0f, color.A / 255.0f)); - vertices[nv + 1] = new Vertex(new float2(r.Right, r.Top), new float2(color.R / 255.0f, color.G / 255.0f), new float2(color.B / 255.0f, color.A / 255.0f)); - vertices[nv + 2] = new Vertex(new float2(r.Right, r.Bottom), new float2(color.R / 255.0f, color.G / 255.0f), new float2(color.B / 255.0f, color.A / 255.0f)); - vertices[nv + 3] = new Vertex(new float2(r.Left, r.Bottom), new float2(color.R / 255.0f, color.G / 255.0f), new float2(color.B / 255.0f, color.A / 255.0f)); + var r = color.R / 255.0f; + var g = color.G / 255.0f; + var b = color.B / 255.0f; + var a = color.A / 255.0f; + vertices[nv] = new Vertex(new float2(rect.Left, rect.Top), r, g, b, a); + vertices[nv + 1] = new Vertex(new float2(rect.Right, rect.Top), r, g, b, a); + vertices[nv + 2] = new Vertex(new float2(rect.Right, rect.Bottom), r, g, b, a); + vertices[nv + 3] = new Vertex(new float2(rect.Left, rect.Bottom), r, g, b, a); nv += 4; } diff --git a/OpenRA.Game/Graphics/Sprite.cs b/OpenRA.Game/Graphics/Sprite.cs index bc8359e416..9a2ccb32d4 100644 --- a/OpenRA.Game/Graphics/Sprite.cs +++ b/OpenRA.Game/Graphics/Sprite.cs @@ -21,7 +21,7 @@ namespace OpenRA.Graphics public readonly float2 size; public readonly float2 offset; public readonly float2 fractionalOffset; - readonly float top, left, bottom, right; + public readonly float top, left, bottom, right; public Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel) : this(sheet, bounds, float2.Zero, channel, BlendMode.Alpha) {} @@ -45,26 +45,6 @@ namespace OpenRA.Graphics right = (float)(bounds.Right) / sheet.Size.Width; bottom = (float)(bounds.Bottom) / sheet.Size.Height; } - - public float2 TopLeftTextureCoords - { - 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); } - } } public enum TextureChannel diff --git a/OpenRA.Game/Graphics/Util.cs b/OpenRA.Game/Graphics/Util.cs index 613f852d01..1ebb4b3c3e 100644 --- a/OpenRA.Game/Graphics/Util.cs +++ b/OpenRA.Game/Graphics/Util.cs @@ -29,12 +29,13 @@ namespace OpenRA.Graphics 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 attribP = palette / (float)HardwarePalette.MaxPalettes; + var attribC = channelSelect[(int)r.channel]; - 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); + vertices[nv] = new Vertex(a, r.left, r.top, attribP, attribC); + vertices[nv + 1] = new Vertex(b, r.right, r.top, attribP, attribC); + vertices[nv + 2] = new Vertex(c, r.right, r.bottom, attribP, attribC); + vertices[nv + 3] = new Vertex(d, r.left, r.bottom, attribP, attribC); } static readonly int[] channelMasks = { 2, 1, 0, 3 }; // yes, our channel order is nuts. diff --git a/OpenRA.Game/Graphics/Vertex.cs b/OpenRA.Game/Graphics/Vertex.cs index 4c1452dda0..0d4e655610 100644 --- a/OpenRA.Game/Graphics/Vertex.cs +++ b/OpenRA.Game/Graphics/Vertex.cs @@ -18,18 +18,18 @@ namespace OpenRA.Graphics public float x, y, z, u, v; public float p, c; - public Vertex(float2 xy, float2 uv, float2 pc) + public Vertex(float2 xy, float u, float v, float p, float c) { this.x = xy.X; this.y = xy.Y; this.z = 0; - this.u = uv.X; this.v = uv.Y; - this.p = pc.X; this.c = pc.Y; + this.u = u; this.v = v; + this.p = p; this.c = c; } - public Vertex(float[] xyz, float2 uv, float2 pc) + public Vertex(float[] xyz, float u, float v, float p, float c) { this.x = xyz[0]; this.y = xyz[1]; this.z = xyz[2]; - this.u = uv.X; this.v = uv.Y; - this.p = pc.X; this.c = pc.Y; + this.u = u; this.v = v; + this.p = p; this.c = c; } } } diff --git a/OpenRA.Game/Graphics/VoxelLoader.cs b/OpenRA.Game/Graphics/VoxelLoader.cs index 143258af4a..2fc2d2fdf8 100644 --- a/OpenRA.Game/Graphics/VoxelLoader.cs +++ b/OpenRA.Game/Graphics/VoxelLoader.cs @@ -87,13 +87,14 @@ namespace OpenRA.Graphics Util.FastCopyIntoChannel(s, 1, normals); s.sheet.CommitData(); - var channels = new float2(channelSelect[(int)s.channel], channelSelect[(int)s.channel + 1]); + var channelP =channelSelect[(int)s.channel]; + var channelC = channelSelect[(int)s.channel + 1]; return new Vertex[4] { - 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) + new Vertex(coord(0, 0), s.left, s.top, channelP, channelC), + new Vertex(coord(su, 0),s.right, s.top, channelP, channelC), + new Vertex(coord(su, sv), s.right, s.bottom, channelP, channelC), + new Vertex(coord(0, sv), s.left, s.bottom, channelP, channelC) }; }