git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1156 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
chrisf
2007-07-10 06:08:38 +00:00
parent d10f9eab9a
commit d42b2f45e5
2 changed files with 45 additions and 4 deletions

View File

@@ -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<int> vertices, Range<int> indices)
{
device->DrawIndexedPrimitive( (D3DPRIMITIVETYPE)primType,
0, vertices.Start, vertices.End - vertices.Start,
indices.Start, (indices.End - indices.Start) / 3 );
}
};
}}

View File

@@ -87,7 +87,7 @@ namespace OpenRa.Game
void LoadVertexBuffer()
{
Dictionary<Sheet, List<ushort>> indexMap = new Dictionary<Sheet, List<ushort>>();
List<Vertex> vertices = new List<Vertex>();// Vertex[] vertices = new Vertex[4 * 128 * 128];
List<Vertex> vertices = new List<Vertex>();
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<int> indexRange = new Range<int>(indicesPerRow * firstRow, indicesPerRow * lastRow);
Range<int> vertexRange = new Range<int>(verticesPerRow * firstRow, verticesPerRow * lastRow);
device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
vertexRange, indexRange);
}
effect.EndPass();