Avoid redundantly setting viewport parameters in BeginFrame.
- Cache the old resolution, scroll and zoom in BeginFrame, and don't bother updating the viewport parameters again until they change. - Pass around scroll as an int2 to reduce the number of back-and-forth casts.
This commit is contained in:
@@ -103,9 +103,9 @@ namespace OpenRA.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
public void SetViewportParams(Size screen, float zoom, float2 scroll)
|
||||
public void SetViewportParams(Size screen, float zoom, int2 scroll)
|
||||
{
|
||||
shader.SetVec("Scroll", (int)scroll.X, (int)scroll.Y);
|
||||
shader.SetVec("Scroll", scroll.X, scroll.Y);
|
||||
shader.SetVec("r1", zoom*2f/screen.Width, -zoom*2f/screen.Height);
|
||||
shader.SetVec("r2", -1, 1);
|
||||
}
|
||||
|
||||
@@ -58,9 +58,9 @@ namespace OpenRA.Graphics
|
||||
nv += 4;
|
||||
}
|
||||
|
||||
public void SetViewportParams(Size screen, float zoom, float2 scroll)
|
||||
public void SetViewportParams(Size screen, float zoom, int2 scroll)
|
||||
{
|
||||
shader.SetVec("Scroll", (int)scroll.X, (int)scroll.Y);
|
||||
shader.SetVec("Scroll", scroll.X, scroll.Y);
|
||||
shader.SetVec("r1", zoom*2f/screen.Width, -zoom*2f/screen.Height);
|
||||
shader.SetVec("r2", -1, 1);
|
||||
}
|
||||
|
||||
@@ -65,17 +65,34 @@ namespace OpenRA.Graphics
|
||||
|
||||
internal IGraphicsDevice Device { get { return device; } }
|
||||
|
||||
public void BeginFrame(float2 scroll, float zoom)
|
||||
Size? lastResolution;
|
||||
int2? lastScroll;
|
||||
float? lastZoom;
|
||||
|
||||
public void BeginFrame(int2 scroll, float zoom)
|
||||
{
|
||||
device.Clear();
|
||||
WorldSpriteRenderer.SetViewportParams(Resolution, zoom, scroll);
|
||||
WorldRgbaSpriteRenderer.SetViewportParams(Resolution, zoom, scroll);
|
||||
SpriteRenderer.SetViewportParams(Resolution, 1f, float2.Zero);
|
||||
RgbaSpriteRenderer.SetViewportParams(Resolution, 1f, float2.Zero);
|
||||
WorldLineRenderer.SetViewportParams(Resolution, zoom, scroll);
|
||||
WorldQuadRenderer.SetViewportParams(Resolution, zoom, scroll);
|
||||
LineRenderer.SetViewportParams(Resolution, 1f, float2.Zero);
|
||||
WorldVoxelRenderer.SetViewportParams(Resolution, zoom, scroll);
|
||||
|
||||
var resolutionChanged = lastResolution != Resolution;
|
||||
if (resolutionChanged)
|
||||
{
|
||||
lastResolution = Resolution;
|
||||
RgbaSpriteRenderer.SetViewportParams(Resolution, 1f, int2.Zero);
|
||||
SpriteRenderer.SetViewportParams(Resolution, 1f, int2.Zero);
|
||||
LineRenderer.SetViewportParams(Resolution, 1f, int2.Zero);
|
||||
}
|
||||
|
||||
// If zoom evaluates as different due to floating point weirdness that's OK, setting the parameters again is harmless.
|
||||
if (resolutionChanged || lastScroll != scroll || lastZoom != zoom)
|
||||
{
|
||||
lastScroll = scroll;
|
||||
lastZoom = zoom;
|
||||
WorldRgbaSpriteRenderer.SetViewportParams(Resolution, zoom, scroll);
|
||||
WorldSpriteRenderer.SetViewportParams(Resolution, zoom, scroll);
|
||||
WorldVoxelRenderer.SetViewportParams(Resolution, zoom, scroll);
|
||||
WorldLineRenderer.SetViewportParams(Resolution, zoom, scroll);
|
||||
WorldQuadRenderer.SetViewportParams(Resolution, zoom, scroll);
|
||||
}
|
||||
}
|
||||
|
||||
ITexture currentPaletteTexture;
|
||||
|
||||
@@ -120,9 +120,9 @@ namespace OpenRA.Graphics
|
||||
shader.SetTexture("Palette", palette);
|
||||
}
|
||||
|
||||
public void SetViewportParams(Size screen, float zoom, float2 scroll)
|
||||
public void SetViewportParams(Size screen, float zoom, int2 scroll)
|
||||
{
|
||||
shader.SetVec("Scroll", (int)scroll.X, (int)scroll.Y);
|
||||
shader.SetVec("Scroll", scroll.X, scroll.Y);
|
||||
shader.SetVec("r1", zoom*2f/screen.Width, -zoom*2f/screen.Height);
|
||||
shader.SetVec("r2", -1, 1);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Graphics
|
||||
shader.SetTexture("Palette", palette);
|
||||
}
|
||||
|
||||
public void SetViewportParams(Size screen, float zoom, float2 scroll)
|
||||
public void SetViewportParams(Size screen, float zoom, int2 scroll)
|
||||
{
|
||||
var a = 2f / Renderer.SheetSize;
|
||||
var view = new float[]
|
||||
|
||||
Reference in New Issue
Block a user