From c59850008e35cb48d91cfd696316a38d0cb8ca35 Mon Sep 17 00:00:00 2001 From: chrisf Date: Tue, 10 Jul 2007 08:13:35 +0000 Subject: [PATCH] nice clean maths, nice perf boost :D git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1163 993157c7-ee19-0410-b2c4-bb4e9862e678 --- OpenRa.Game/MainWindow.cs | 20 +++++++++++++------- diffuse.fx | 10 +++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index c00fb44a99..d22402017f 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -31,7 +31,7 @@ namespace OpenRa.Game Dictionary drawBatches = new Dictionary(); Effect effect; - IntPtr texture, scroll; + IntPtr texture, scroll, r1h, r2h; void LoadTextures() { @@ -148,6 +148,9 @@ namespace OpenRa.Game effect = new Effect(device, File.OpenRead("../../../" + shaderName)); texture = effect.GetHandle("DiffuseTexture"); scroll = effect.GetHandle("Scroll"); + + r1h = effect.GetHandle("r1"); + r2h = effect.GetHandle("r2"); } internal void Run() @@ -178,11 +181,9 @@ namespace OpenRa.Game if (e.Button != 0) { - int dx = x1 - e.X; - int dy = y1 - e.Y; scrollPos = oldPos; - scrollPos.X += (float)dx / (ClientSize.Width / 2); - scrollPos.Y += (float)dy / (ClientSize.Height / 2); + scrollPos.X += x1 - e.X; + scrollPos.Y += y1 - e.Y; } } @@ -198,6 +199,9 @@ namespace OpenRa.Game void Frame() { + PointF r1 = new PointF(2.0f / ClientSize.Width, -2.0f / ClientSize.Height); + PointF r2 = new PointF(-1, 1); + device.Begin(); device.Clear( 0, Surfaces.Color ); @@ -208,6 +212,8 @@ namespace OpenRa.Game effect.BeginPass(0); effect.SetValue(scroll, scrollPos); + effect.SetValue(r1h, r1); + effect.SetValue(r2h, r2); foreach (KeyValuePair batch in drawBatches) { @@ -219,9 +225,9 @@ namespace OpenRa.Game int indicesPerRow = map.Width * 6; int verticesPerRow = map.Width * 4; - int visibleRows = (int)Math.Ceiling(800.0f / 24.0f) + 3; + int visibleRows = (int)(ClientSize.Height / 24.0f + 2); - int firstRow = (int)((scrollPos.Y - 1) * 16.0f); + int firstRow = (int)(scrollPos.Y / 24.0f); int lastRow = firstRow + visibleRows; if (firstRow < 0) diff --git a/diffuse.fx b/diffuse.fx index 5ac83422a0..7409eb09bf 100644 --- a/diffuse.fx +++ b/diffuse.fx @@ -4,7 +4,8 @@ shared texture DiffuseTexture; shared float2 Scroll; -const float2 ScreenSize = { 640, 400 }; + +shared float2 r1, r2; // matrix elements sampler s_DiffuseTexture = sampler_state { Texture = ; @@ -33,10 +34,9 @@ struct FragmentIn { VertexOut Simple_vp(VertexIn v) { VertexOut o; - o.Position = float4( - v.Position.x / ScreenSize.x - 0.5f - Scroll.x, - Scroll.y - v.Position.y / ScreenSize.y, - 0, 1 ); + + float2 p = (v.Position.xy - Scroll.xy) * r1 + r2; + o.Position = float4(p.x,p.y,0,1); o.Tex0 = v.Tex0; return o; }