Automatically flush line renderer when changing width.

This commit is contained in:
Paul Chote
2013-10-14 23:24:01 +13:00
parent 24b33891a7
commit d2d73a32a2
2 changed files with 18 additions and 16 deletions

View File

@@ -49,20 +49,10 @@ namespace OpenRA.Graphics
var src = wr.ScreenPosition(pos); var src = wr.ScreenPosition(pos);
var dest = wr.ScreenPosition(pos + length); var dest = wr.ScreenPosition(pos + length);
var lineWidth = wlr.LineWidth; var oldWidth = wlr.LineWidth;
if (lineWidth != width)
{
wlr.Flush();
wlr.LineWidth = width; wlr.LineWidth = width;
}
wlr.DrawLine(src, dest, color, color); wlr.DrawLine(src, dest, color, color);
wlr.LineWidth = oldWidth;
if (lineWidth != width)
{
wlr.Flush();
wlr.LineWidth = lineWidth;
}
} }
public void RenderDebugGeometry(WorldRenderer wr) {} public void RenderDebugGeometry(WorldRenderer wr) {}

View File

@@ -15,9 +15,8 @@ namespace OpenRA.Graphics
{ {
public class LineRenderer : Renderer.IBatchRenderer public class LineRenderer : Renderer.IBatchRenderer
{ {
public float LineWidth = 1f;
static float2 offset = new float2(0.5f, 0.5f); static float2 offset = new float2(0.5f, 0.5f);
float lineWidth = 1f;
Renderer renderer; Renderer renderer;
IShader shader; IShader shader;
@@ -30,6 +29,19 @@ namespace OpenRA.Graphics
this.shader = shader; this.shader = shader;
} }
public float LineWidth
{
get { return lineWidth; }
set
{
if (LineWidth != value)
Flush();
lineWidth = value;
}
}
public void Flush() public void Flush()
{ {
if (nv > 0) if (nv > 0)