fix rendering of very large maps
This commit is contained in:
@@ -57,7 +57,7 @@ namespace OpenRA.FileFormats.Graphics
|
||||
public interface IIndexBuffer
|
||||
{
|
||||
void Bind();
|
||||
void SetData( ushort[] indices, int length );
|
||||
void SetData( uint[] indices, int length );
|
||||
}
|
||||
|
||||
public interface IShader
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace OpenRA.Graphics
|
||||
Renderer renderer;
|
||||
|
||||
Vertex[] vertices = new Vertex[ Renderer.TempBufferSize ];
|
||||
ushort[] indices = new ushort[ Renderer.TempBufferSize ];
|
||||
uint[] indices = new uint[ Renderer.TempBufferSize ];
|
||||
int nv = 0, ni = 0;
|
||||
|
||||
public LineRenderer( Renderer renderer )
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace OpenRA.Graphics
|
||||
IShader shader;
|
||||
|
||||
Vertex[] vertices = new Vertex[Renderer.TempBufferSize];
|
||||
ushort[] indices = new ushort[Renderer.TempBufferSize];
|
||||
uint[] indices = new uint[Renderer.TempBufferSize];
|
||||
Sheet currentSheet = null;
|
||||
int nv = 0, ni = 0;
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Graphics
|
||||
x => Game.modData.SheetBuilder.Add(world.TileSet.GetBytes(x), tileSize));
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
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]);
|
||||
|
||||
@@ -55,12 +55,12 @@ namespace OpenRA.Graphics
|
||||
vertices[nv + 2] = new Vertex(new float2(o.X, o.Y + size.Y),
|
||||
r.FastMapTextureCoords(2), attrib);
|
||||
vertices[nv + 3] = new Vertex(new float2(o.X + size.X, o.Y + size.Y),
|
||||
r.FastMapTextureCoords(3), attrib);
|
||||
|
||||
indices[ni] = (ushort)(nv);
|
||||
indices[ni + 1] = indices[ni + 3] = (ushort)(nv + 1);
|
||||
indices[ni + 2] = indices[ni + 5] = (ushort)(nv + 2);
|
||||
indices[ni + 4] = (ushort)(nv + 3);
|
||||
r.FastMapTextureCoords(3), attrib);
|
||||
|
||||
indices[ni] = (uint)(nv);
|
||||
indices[ni + 1] = indices[ni + 3] = (uint)(nv + 1);
|
||||
indices[ni + 2] = indices[ni + 5] = (uint)(nv + 2);
|
||||
indices[ni + 4] = (uint)(nv + 3);
|
||||
}
|
||||
|
||||
static readonly int[] channelMasks = { 2, 1, 0, 3 }; // yes, our channel order is nuts.
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
|
||||
using System;
|
||||
using OpenRA.FileFormats.Graphics;
|
||||
using Tao.OpenGl;
|
||||
using Tao.OpenGl;
|
||||
|
||||
using ElemType = System.UInt32;
|
||||
|
||||
namespace OpenRA.Renderer.Cg
|
||||
{
|
||||
@@ -24,18 +26,18 @@ namespace OpenRA.Renderer.Cg
|
||||
GraphicsDevice.CheckGlError();
|
||||
Bind();
|
||||
Gl.glBufferData(Gl.GL_ELEMENT_ARRAY_BUFFER,
|
||||
new IntPtr(2 * size),
|
||||
new ushort[ size ],
|
||||
new IntPtr(sizeof(ElemType) * size),
|
||||
new ElemType[ size ],
|
||||
Gl.GL_DYNAMIC_DRAW);
|
||||
GraphicsDevice.CheckGlError();
|
||||
}
|
||||
|
||||
public void SetData(ushort[] data, int length)
|
||||
public void SetData(ElemType[] data, int length)
|
||||
{
|
||||
Bind();
|
||||
Gl.glBufferSubData(Gl.GL_ELEMENT_ARRAY_BUFFER,
|
||||
IntPtr.Zero,
|
||||
new IntPtr(2 * length),
|
||||
new IntPtr(sizeof(ElemType) * length),
|
||||
data);
|
||||
GraphicsDevice.CheckGlError();
|
||||
}
|
||||
|
||||
@@ -273,14 +273,14 @@ namespace OpenRA.Renderer.Glsl
|
||||
public void DrawIndexedPrimitives( PrimitiveType pt, Range<int> vertices, Range<int> indices )
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
public void DrawIndexedPrimitives( PrimitiveType pt, int numVerts, int numPrimitives )
|
||||
{
|
||||
Gl.glDrawElements( ModeFromPrimitiveType( pt ), numPrimitives * IndicesPerPrimitive( pt ),
|
||||
Gl.GL_UNSIGNED_SHORT, IntPtr.Zero );
|
||||
Gl.glDrawElements( ModeFromPrimitiveType( pt ), numPrimitives * IndicesPerPrimitive( pt ),
|
||||
Gl.GL_UNSIGNED_INT, IntPtr.Zero);
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ using System;
|
||||
using OpenRA.FileFormats.Graphics;
|
||||
using Tao.OpenGl;
|
||||
|
||||
using ElemType = System.UInt32;
|
||||
|
||||
namespace OpenRA.Renderer.Glsl
|
||||
{
|
||||
public class IndexBuffer : IIndexBuffer, IDisposable
|
||||
@@ -24,18 +26,18 @@ namespace OpenRA.Renderer.Glsl
|
||||
GraphicsDevice.CheckGlError();
|
||||
Bind();
|
||||
Gl.glBufferData(Gl.GL_ELEMENT_ARRAY_BUFFER,
|
||||
new IntPtr(2 * size),
|
||||
new ushort[ size ],
|
||||
new IntPtr(sizeof(ElemType) * size),
|
||||
new ElemType[ size ],
|
||||
Gl.GL_DYNAMIC_DRAW);
|
||||
GraphicsDevice.CheckGlError();
|
||||
}
|
||||
|
||||
public void SetData(ushort[] data, int length)
|
||||
}
|
||||
|
||||
public void SetData(ElemType[] data, int length)
|
||||
{
|
||||
Bind();
|
||||
Gl.glBufferSubData(Gl.GL_ELEMENT_ARRAY_BUFFER,
|
||||
IntPtr.Zero,
|
||||
new IntPtr(2 * length),
|
||||
IntPtr.Zero,
|
||||
new IntPtr(sizeof(ElemType) * length),
|
||||
data);
|
||||
GraphicsDevice.CheckGlError();
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA.Renderer.Null
|
||||
public class NullIndexBuffer : IIndexBuffer
|
||||
{
|
||||
public void Bind() {}
|
||||
public void SetData(ushort[] indices, int length) {}
|
||||
public void SetData(uint[] indices, int length) {}
|
||||
}
|
||||
|
||||
public class NullShader : IShader
|
||||
|
||||
Reference in New Issue
Block a user