fix rendering of very large maps

This commit is contained in:
Chris Forbes
2011-03-08 19:24:15 +13:00
parent 682cfcd466
commit 16cb275a5f
9 changed files with 31 additions and 27 deletions

View File

@@ -57,7 +57,7 @@ namespace OpenRA.FileFormats.Graphics
public interface IIndexBuffer public interface IIndexBuffer
{ {
void Bind(); void Bind();
void SetData( ushort[] indices, int length ); void SetData( uint[] indices, int length );
} }
public interface IShader public interface IShader

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Graphics
Renderer renderer; Renderer renderer;
Vertex[] vertices = new Vertex[ Renderer.TempBufferSize ]; Vertex[] vertices = new Vertex[ Renderer.TempBufferSize ];
ushort[] indices = new ushort[ Renderer.TempBufferSize ]; uint[] indices = new uint[ Renderer.TempBufferSize ];
int nv = 0, ni = 0; int nv = 0, ni = 0;
public LineRenderer( Renderer renderer ) public LineRenderer( Renderer renderer )

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Graphics
IShader shader; IShader shader;
Vertex[] vertices = new Vertex[Renderer.TempBufferSize]; Vertex[] vertices = new Vertex[Renderer.TempBufferSize];
ushort[] indices = new ushort[Renderer.TempBufferSize]; uint[] indices = new uint[Renderer.TempBufferSize];
Sheet currentSheet = null; Sheet currentSheet = null;
int nv = 0, ni = 0; int nv = 0, ni = 0;

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Graphics
x => Game.modData.SheetBuilder.Add(world.TileSet.GetBytes(x), tileSize)); x => Game.modData.SheetBuilder.Add(world.TileSet.GetBytes(x), tileSize));
Vertex[] vertices = new Vertex[4 * map.Bounds.Height * map.Bounds.Width]; Vertex[] vertices = new Vertex[4 * map.Bounds.Height * map.Bounds.Width];
ushort[] indices = new ushort[6 * map.Bounds.Height * map.Bounds.Width]; uint[] indices = new uint[6 * map.Bounds.Height * map.Bounds.Width];
terrainSheet = tileMapping[map.MapTiles.Value[map.Bounds.Left, map.Bounds.Top]].sheet; terrainSheet = tileMapping[map.MapTiles.Value[map.Bounds.Left, map.Bounds.Top]].sheet;

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Graphics
static float[] channelSelect = { 0.75f, 0.25f, -0.25f, -0.75f }; static float[] channelSelect = { 0.75f, 0.25f, -0.25f, -0.75f };
public static void FastCreateQuad(Vertex[] vertices, ushort[] indices, float2 o, Sprite r, int palette, int nv, int ni, float2 size) public static void FastCreateQuad(Vertex[] vertices, uint[] indices, float2 o, Sprite r, int palette, int nv, int ni, float2 size)
{ {
var attrib = new float2(palette / (float)HardwarePalette.MaxPalettes, channelSelect[(int)r.channel]); var attrib = new float2(palette / (float)HardwarePalette.MaxPalettes, channelSelect[(int)r.channel]);
@@ -55,12 +55,12 @@ namespace OpenRA.Graphics
vertices[nv + 2] = new Vertex(new float2(o.X, o.Y + size.Y), vertices[nv + 2] = new Vertex(new float2(o.X, o.Y + size.Y),
r.FastMapTextureCoords(2), attrib); r.FastMapTextureCoords(2), attrib);
vertices[nv + 3] = new Vertex(new float2(o.X + size.X, o.Y + size.Y), vertices[nv + 3] = new Vertex(new float2(o.X + size.X, o.Y + size.Y),
r.FastMapTextureCoords(3), attrib); r.FastMapTextureCoords(3), attrib);
indices[ni] = (ushort)(nv); indices[ni] = (uint)(nv);
indices[ni + 1] = indices[ni + 3] = (ushort)(nv + 1); indices[ni + 1] = indices[ni + 3] = (uint)(nv + 1);
indices[ni + 2] = indices[ni + 5] = (ushort)(nv + 2); indices[ni + 2] = indices[ni + 5] = (uint)(nv + 2);
indices[ni + 4] = (ushort)(nv + 3); indices[ni + 4] = (uint)(nv + 3);
} }
static readonly int[] channelMasks = { 2, 1, 0, 3 }; // yes, our channel order is nuts. static readonly int[] channelMasks = { 2, 1, 0, 3 }; // yes, our channel order is nuts.

View File

@@ -10,7 +10,9 @@
using System; using System;
using OpenRA.FileFormats.Graphics; using OpenRA.FileFormats.Graphics;
using Tao.OpenGl; using Tao.OpenGl;
using ElemType = System.UInt32;
namespace OpenRA.Renderer.Cg namespace OpenRA.Renderer.Cg
{ {
@@ -24,18 +26,18 @@ namespace OpenRA.Renderer.Cg
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
Bind(); Bind();
Gl.glBufferData(Gl.GL_ELEMENT_ARRAY_BUFFER, Gl.glBufferData(Gl.GL_ELEMENT_ARRAY_BUFFER,
new IntPtr(2 * size), new IntPtr(sizeof(ElemType) * size),
new ushort[ size ], new ElemType[ size ],
Gl.GL_DYNAMIC_DRAW); Gl.GL_DYNAMIC_DRAW);
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
} }
public void SetData(ushort[] data, int length) public void SetData(ElemType[] data, int length)
{ {
Bind(); Bind();
Gl.glBufferSubData(Gl.GL_ELEMENT_ARRAY_BUFFER, Gl.glBufferSubData(Gl.GL_ELEMENT_ARRAY_BUFFER,
IntPtr.Zero, IntPtr.Zero,
new IntPtr(2 * length), new IntPtr(sizeof(ElemType) * length),
data); data);
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
} }

View File

@@ -273,14 +273,14 @@ namespace OpenRA.Renderer.Glsl
public void DrawIndexedPrimitives( PrimitiveType pt, Range<int> vertices, Range<int> indices ) public void DrawIndexedPrimitives( PrimitiveType pt, Range<int> vertices, Range<int> indices )
{ {
Gl.glDrawElements( ModeFromPrimitiveType( pt ), indices.End - indices.Start, Gl.glDrawElements( ModeFromPrimitiveType( pt ), indices.End - indices.Start,
Gl.GL_UNSIGNED_SHORT, new IntPtr( indices.Start * 2 ) ); Gl.GL_UNSIGNED_INT, new IntPtr( indices.Start * 4 ) );
CheckGlError(); CheckGlError();
} }
public void DrawIndexedPrimitives( PrimitiveType pt, int numVerts, int numPrimitives ) public void DrawIndexedPrimitives( PrimitiveType pt, int numVerts, int numPrimitives )
{ {
Gl.glDrawElements( ModeFromPrimitiveType( pt ), numPrimitives * IndicesPerPrimitive( pt ), Gl.glDrawElements( ModeFromPrimitiveType( pt ), numPrimitives * IndicesPerPrimitive( pt ),
Gl.GL_UNSIGNED_SHORT, IntPtr.Zero ); Gl.GL_UNSIGNED_INT, IntPtr.Zero);
CheckGlError(); CheckGlError();
} }

View File

@@ -12,6 +12,8 @@ using System;
using OpenRA.FileFormats.Graphics; using OpenRA.FileFormats.Graphics;
using Tao.OpenGl; using Tao.OpenGl;
using ElemType = System.UInt32;
namespace OpenRA.Renderer.Glsl namespace OpenRA.Renderer.Glsl
{ {
public class IndexBuffer : IIndexBuffer, IDisposable public class IndexBuffer : IIndexBuffer, IDisposable
@@ -24,18 +26,18 @@ namespace OpenRA.Renderer.Glsl
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
Bind(); Bind();
Gl.glBufferData(Gl.GL_ELEMENT_ARRAY_BUFFER, Gl.glBufferData(Gl.GL_ELEMENT_ARRAY_BUFFER,
new IntPtr(2 * size), new IntPtr(sizeof(ElemType) * size),
new ushort[ size ], new ElemType[ size ],
Gl.GL_DYNAMIC_DRAW); Gl.GL_DYNAMIC_DRAW);
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
} }
public void SetData(ushort[] data, int length) public void SetData(ElemType[] data, int length)
{ {
Bind(); Bind();
Gl.glBufferSubData(Gl.GL_ELEMENT_ARRAY_BUFFER, Gl.glBufferSubData(Gl.GL_ELEMENT_ARRAY_BUFFER,
IntPtr.Zero, IntPtr.Zero,
new IntPtr(2 * length), new IntPtr(sizeof(ElemType) * length),
data); data);
GraphicsDevice.CheckGlError(); GraphicsDevice.CheckGlError();
} }

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Renderer.Null
public class NullIndexBuffer : IIndexBuffer public class NullIndexBuffer : IIndexBuffer
{ {
public void Bind() {} public void Bind() {}
public void SetData(ushort[] indices, int length) {} public void SetData(uint[] indices, int length) {}
} }
public class NullShader : IShader public class NullShader : IShader