nice clean maths, nice perf boost :D
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1163 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -31,7 +31,7 @@ namespace OpenRa.Game
|
||||
Dictionary<Sheet, IndexBuffer> drawBatches = new Dictionary<Sheet, IndexBuffer>();
|
||||
|
||||
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<Sheet, IndexBuffer> 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)
|
||||
|
||||
10
diffuse.fx
10
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 = <DiffuseTexture>;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user