From d42b2f45e5f4e5c02f417592bc68a5a27dcb4da9 Mon Sep 17 00:00:00 2001 From: chrisf Date: Tue, 10 Jul 2007 06:08:38 +0000 Subject: [PATCH] git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1156 993157c7-ee19-0410-b2c4-bb4e9862e678 --- BluntDx/GraphicsDevice.h | 21 +++++++++++++++++++++ OpenRa.Game/MainWindow.cs | 28 ++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/BluntDx/GraphicsDevice.h b/BluntDx/GraphicsDevice.h index 63041a026a..7f31456588 100644 --- a/BluntDx/GraphicsDevice.h +++ b/BluntDx/GraphicsDevice.h @@ -2,6 +2,20 @@ namespace BluntDirectX { namespace Direct3D { + generic< typename T > + public value class Range + { + T start, end; + public: + Range( T start, T end ) + : start( start ), end( end ) + { + } + + property T Start { T get() { return start; } } + property T End { T get() { return end; } } + }; + public ref class GraphicsDevice { private: @@ -164,5 +178,12 @@ namespace BluntDirectX { namespace Direct3D { device->DrawIndexedPrimitive( (D3DPRIMITIVETYPE)primtype, 0, 0, vertexPoolSize, 0, numPrimitives ); } + + void DrawIndexedPrimitives(PrimitiveType primType, Range vertices, Range indices) + { + device->DrawIndexedPrimitive( (D3DPRIMITIVETYPE)primType, + 0, vertices.Start, vertices.End - vertices.Start, + indices.Start, (indices.End - indices.Start) / 3 ); + } }; }} diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index fd183b035e..3e7a9a9183 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -87,7 +87,7 @@ namespace OpenRa.Game void LoadVertexBuffer() { Dictionary> indexMap = new Dictionary>(); - List vertices = new List();// Vertex[] vertices = new Vertex[4 * 128 * 128]; + List vertices = new List(); for (int j = 0; j < map.Height; j++) for (int i = 0; i < map.Width; i++) @@ -127,7 +127,7 @@ namespace OpenRa.Game public MainWindow() { - ClientSize = new Size(640, 480); + ClientSize = new Size(1280, 800); Visible = true; @@ -216,8 +216,28 @@ namespace OpenRa.Game batch.Value.Bind(); - device.DrawIndexedPrimitives(PrimitiveType.TriangleList, - vertexBuffer.Size, batch.Value.Size / 3); + int indicesPerRow = map.Width * 6; + int verticesPerRow = map.Width * 4; + + int visibleRows = (int)Math.Ceiling(800.0f / 24.0f) + 2; + + int firstRow = (int)((scrollPos.Y - 1) * 16.0f); + int lastRow = firstRow + visibleRows; + + if (firstRow < 0) + firstRow = 0; + + if (lastRow < 0) + lastRow = 0; + + if (lastRow > map.Height) + lastRow = map.Height; + + Range indexRange = new Range(indicesPerRow * firstRow, indicesPerRow * lastRow); + Range vertexRange = new Range(verticesPerRow * firstRow, verticesPerRow * lastRow); + + device.DrawIndexedPrimitives(PrimitiveType.TriangleList, + vertexRange, indexRange); } effect.EndPass();