IBOless rendering with quads; considerably reduces renderer complexity
This commit is contained in:
@@ -30,7 +30,6 @@ namespace OpenRA.FileFormats.Graphics
|
||||
public interface IGraphicsDevice
|
||||
{
|
||||
IVertexBuffer<Vertex> CreateVertexBuffer( int length );
|
||||
IIndexBuffer CreateIndexBuffer( int length );
|
||||
ITexture CreateTexture( Bitmap bitmap );
|
||||
ITexture CreateTexture();
|
||||
IShader CreateShader( string name );
|
||||
@@ -41,8 +40,7 @@ namespace OpenRA.FileFormats.Graphics
|
||||
void Clear( Color color );
|
||||
void Present( IInputHandler inputHandler );
|
||||
|
||||
void DrawIndexedPrimitives( PrimitiveType type, Range<int> vertexRange, Range<int> indexRange );
|
||||
void DrawIndexedPrimitives( PrimitiveType type, int vertexPool, int numPrimitives );
|
||||
void DrawPrimitives( PrimitiveType type, int firstVertex, int numVertices );
|
||||
|
||||
void EnableScissor( int left, int top, int width, int height );
|
||||
void DisableScissor();
|
||||
@@ -54,12 +52,6 @@ namespace OpenRA.FileFormats.Graphics
|
||||
void SetData( T[] vertices, int length );
|
||||
}
|
||||
|
||||
public interface IIndexBuffer
|
||||
{
|
||||
void Bind();
|
||||
void SetData( uint[] indices, int length );
|
||||
}
|
||||
|
||||
public interface IShader
|
||||
{
|
||||
void SetValue( string name, float x, float y );
|
||||
@@ -79,6 +71,7 @@ namespace OpenRA.FileFormats.Graphics
|
||||
PointList,
|
||||
LineList,
|
||||
TriangleList,
|
||||
QuadList,
|
||||
}
|
||||
|
||||
public struct Range<T>
|
||||
|
||||
@@ -18,8 +18,7 @@ namespace OpenRA.Graphics
|
||||
Renderer renderer;
|
||||
|
||||
Vertex[] vertices = new Vertex[ Renderer.TempBufferSize ];
|
||||
uint[] indices = new uint[ Renderer.TempBufferSize ];
|
||||
int nv = 0, ni = 0;
|
||||
int nv = 0;
|
||||
|
||||
public LineRenderer( Renderer renderer )
|
||||
{
|
||||
@@ -28,19 +27,16 @@ namespace OpenRA.Graphics
|
||||
|
||||
public void Flush()
|
||||
{
|
||||
if( ni > 0 )
|
||||
if( nv > 0 )
|
||||
{
|
||||
renderer.LineShader.Render( () =>
|
||||
{
|
||||
var vb = renderer.GetTempVertexBuffer();
|
||||
var ib = renderer.GetTempIndexBuffer();
|
||||
vb.SetData( vertices, nv );
|
||||
ib.SetData( indices, ni );
|
||||
renderer.DrawBatch( vb, ib,
|
||||
nv, ni / 2, PrimitiveType.LineList );
|
||||
renderer.DrawBatch( vb, 0, nv, PrimitiveType.LineList );
|
||||
} );
|
||||
|
||||
nv = 0; ni = 0;
|
||||
nv = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,19 +44,13 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
Renderer.CurrentBatchRenderer = this;
|
||||
|
||||
if( ni + 2 > Renderer.TempBufferSize )
|
||||
Flush();
|
||||
if( nv + 2 > Renderer.TempBufferSize )
|
||||
Flush();
|
||||
|
||||
indices[ ni++ ] = (ushort)nv;
|
||||
|
||||
vertices[ nv++ ] = new Vertex( start,
|
||||
new float2( startColor.R / 255.0f, startColor.G / 255.0f ),
|
||||
new float2( startColor.B / 255.0f, startColor.A / 255.0f ) );
|
||||
|
||||
indices[ ni++ ] = (ushort)nv;
|
||||
|
||||
vertices[ nv++ ] = new Vertex( end,
|
||||
new float2( endColor.R / 255.0f, endColor.G / 255.0f ),
|
||||
new float2( endColor.B / 255.0f, endColor.A / 255.0f ) );
|
||||
@@ -69,9 +59,7 @@ namespace OpenRA.Graphics
|
||||
public void FillRect( RectangleF r, Color color )
|
||||
{
|
||||
for (float y = r.Top; y < r.Bottom; y++)
|
||||
{
|
||||
DrawLine(new float2(r.Left, y), new float2(r.Right, y), color, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ namespace OpenRA.Graphics
|
||||
const int TempBufferCount = 8;
|
||||
|
||||
Queue<IVertexBuffer<Vertex>> tempBuffersV = new Queue<IVertexBuffer<Vertex>>();
|
||||
Queue<IIndexBuffer> tempBuffersI = new Queue<IIndexBuffer>();
|
||||
|
||||
public Renderer()
|
||||
{
|
||||
@@ -62,10 +61,7 @@ namespace OpenRA.Graphics
|
||||
TinyBoldFont = new SpriteFont("FreeSansBold.ttf", 10);
|
||||
|
||||
for( int i = 0 ; i < TempBufferCount ; i++ )
|
||||
{
|
||||
tempBuffersV.Enqueue( device.CreateVertexBuffer( TempBufferSize ) );
|
||||
tempBuffersI.Enqueue( device.CreateIndexBuffer( TempBufferSize ) );
|
||||
}
|
||||
}
|
||||
|
||||
internal IGraphicsDevice Device { get { return device; } }
|
||||
@@ -83,7 +79,7 @@ namespace OpenRA.Graphics
|
||||
SetShaderParams( WorldSpriteShader, r1, r2, scroll );
|
||||
}
|
||||
|
||||
private void SetShaderParams( IShader s, float2 r1, float2 r2, float2 scroll )
|
||||
void SetShaderParams( IShader s, float2 r1, float2 r2, float2 scroll )
|
||||
{
|
||||
s.SetValue( "Palette", PaletteTexture );
|
||||
s.SetValue( "Scroll", (int) scroll.X, (int) scroll.Y );
|
||||
@@ -97,27 +93,12 @@ namespace OpenRA.Graphics
|
||||
device.Present( inputHandler );
|
||||
}
|
||||
|
||||
public void DrawBatch<T>(IVertexBuffer<T> vertices, IIndexBuffer indices,
|
||||
Range<int> vertexRange, Range<int> indexRange, PrimitiveType type, IShader shader)
|
||||
public void DrawBatch<T>(IVertexBuffer<T> vertices,
|
||||
int firstVertex, int numVertices, PrimitiveType type)
|
||||
where T : struct
|
||||
{
|
||||
vertices.Bind();
|
||||
indices.Bind();
|
||||
|
||||
device.DrawIndexedPrimitives(type, vertexRange, indexRange);
|
||||
|
||||
PerfHistory.Increment("batches", 1);
|
||||
}
|
||||
|
||||
public void DrawBatch<T>(IVertexBuffer<T> vertices, IIndexBuffer indices,
|
||||
int vertexPool, int numPrimitives, PrimitiveType type)
|
||||
where T : struct
|
||||
{
|
||||
vertices.Bind();
|
||||
indices.Bind();
|
||||
|
||||
device.DrawIndexedPrimitives(type, vertexPool, numPrimitives);
|
||||
|
||||
device.DrawPrimitives(type, firstVertex, numVertices);
|
||||
PerfHistory.Increment("batches", 1);
|
||||
}
|
||||
|
||||
@@ -168,13 +149,6 @@ namespace OpenRA.Graphics
|
||||
return ret;
|
||||
}
|
||||
|
||||
internal IIndexBuffer GetTempIndexBuffer()
|
||||
{
|
||||
var ret = tempBuffersI.Dequeue();
|
||||
tempBuffersI.Enqueue( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
public interface IBatchRenderer
|
||||
{
|
||||
void Flush();
|
||||
|
||||
@@ -18,9 +18,8 @@ namespace OpenRA.Graphics
|
||||
IShader shader;
|
||||
|
||||
Vertex[] vertices = new Vertex[Renderer.TempBufferSize];
|
||||
uint[] indices = new uint[Renderer.TempBufferSize];
|
||||
Sheet currentSheet = null;
|
||||
int nv = 0, ni = 0;
|
||||
int nv = 0;
|
||||
|
||||
public SpriteRenderer(Renderer renderer, IShader shader)
|
||||
{
|
||||
@@ -33,23 +32,17 @@ namespace OpenRA.Graphics
|
||||
|
||||
public void Flush()
|
||||
{
|
||||
if (ni > 0)
|
||||
if (nv > 0)
|
||||
{
|
||||
shader.SetValue( "DiffuseTexture", currentSheet.Texture );
|
||||
shader.Render(() =>
|
||||
{
|
||||
var vb = renderer.GetTempVertexBuffer();
|
||||
var ib = renderer.GetTempIndexBuffer();
|
||||
vb.SetData(vertices, nv);
|
||||
ib.SetData(indices, ni);
|
||||
renderer.DrawBatch(vb, ib,
|
||||
new Range<int>(0, nv),
|
||||
new Range<int>(0, ni),
|
||||
PrimitiveType.TriangleList,
|
||||
shader);
|
||||
renderer.DrawBatch(vb, 0, nv, PrimitiveType.QuadList);
|
||||
});
|
||||
|
||||
nv = 0; ni = 0;
|
||||
nv = 0;
|
||||
currentSheet = null;
|
||||
}
|
||||
}
|
||||
@@ -73,12 +66,10 @@ namespace OpenRA.Graphics
|
||||
|
||||
if( nv + 4 > Renderer.TempBufferSize )
|
||||
Flush();
|
||||
if( ni + 6 > Renderer.TempBufferSize )
|
||||
Flush();
|
||||
|
||||
currentSheet = s.sheet;
|
||||
Util.FastCreateQuad(vertices, indices, location.ToInt2(), s, paletteIndex, nv, ni, size);
|
||||
nv += 4; ni += 6;
|
||||
Util.FastCreateQuad(vertices, location.ToInt2(), s, paletteIndex, nv, size);
|
||||
nv += 4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace OpenRA.Graphics
|
||||
class TerrainRenderer
|
||||
{
|
||||
IVertexBuffer<Vertex> vertexBuffer;
|
||||
IIndexBuffer indexBuffer;
|
||||
Sheet terrainSheet;
|
||||
|
||||
World world;
|
||||
@@ -30,27 +29,23 @@ namespace OpenRA.Graphics
|
||||
this.world = world;
|
||||
this.map = world.Map;
|
||||
|
||||
Size tileSize = new Size( Game.CellSize, Game.CellSize );
|
||||
var tileSize = new Size( Game.CellSize, Game.CellSize );
|
||||
var tileMapping = new Cache<TileReference<ushort,byte>, Sprite>(
|
||||
x => Game.modData.SheetBuilder.Add(world.TileSet.GetBytes(x), tileSize));
|
||||
|
||||
Vertex[] vertices = new Vertex[4 * map.Bounds.Height * map.Bounds.Width];
|
||||
uint[] indices = new uint[6 * map.Bounds.Height * map.Bounds.Width];
|
||||
var vertices = new Vertex[4 * map.Bounds.Height * map.Bounds.Width];
|
||||
|
||||
terrainSheet = tileMapping[map.MapTiles.Value[map.Bounds.Left, map.Bounds.Top]].sheet;
|
||||
|
||||
int nv = 0;
|
||||
int ni = 0;
|
||||
|
||||
for( int j = map.Bounds.Top; j < map.Bounds.Bottom; j++ )
|
||||
for( int i = map.Bounds.Left; i < map.Bounds.Right; i++ )
|
||||
{
|
||||
Sprite tile = tileMapping[map.MapTiles.Value[i, j]];
|
||||
// TODO: The zero below should explicitly refer to the terrain palette, but this code is called
|
||||
// before the palettes are created. Therefore assumes that "terrain" is the first palette to be defined
|
||||
Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, Game.modData.Palette.GetPaletteIndex("terrain"), nv, ni, tile.size);
|
||||
var tile = tileMapping[map.MapTiles.Value[i, j]];
|
||||
// TODO: move GetPaletteIndex out of the inner loop.
|
||||
Util.FastCreateQuad(vertices, Game.CellSize * new float2(i, j), tile, Game.modData.Palette.GetPaletteIndex("terrain"), nv, tile.size);
|
||||
nv += 4;
|
||||
ni += 6;
|
||||
|
||||
if (tileMapping[map.MapTiles.Value[i, j]].sheet != terrainSheet)
|
||||
throw new InvalidOperationException("Terrain sprites span multiple sheets");
|
||||
@@ -58,14 +53,10 @@ namespace OpenRA.Graphics
|
||||
|
||||
vertexBuffer = Game.Renderer.Device.CreateVertexBuffer( vertices.Length );
|
||||
vertexBuffer.SetData( vertices, nv );
|
||||
|
||||
indexBuffer = Game.Renderer.Device.CreateIndexBuffer( indices.Length );
|
||||
indexBuffer.SetData( indices, ni );
|
||||
}
|
||||
|
||||
public void Draw( WorldRenderer wr, Viewport viewport )
|
||||
{
|
||||
int indicesPerRow = map.Bounds.Width * 6;
|
||||
int verticesPerRow = map.Bounds.Width * 4;
|
||||
|
||||
int visibleRows = (int)(viewport.Height * 1f / Game.CellSize + 2);
|
||||
@@ -93,10 +84,9 @@ namespace OpenRA.Graphics
|
||||
|
||||
Game.Renderer.SpriteShader.SetValue( "DiffuseTexture", terrainSheet.Texture );
|
||||
Game.Renderer.SpriteShader.Render(() =>
|
||||
Game.Renderer.DrawBatch(vertexBuffer, indexBuffer,
|
||||
new Range<int>(verticesPerRow * firstRow, verticesPerRow * lastRow),
|
||||
new Range<int>(indicesPerRow * firstRow, indicesPerRow * lastRow),
|
||||
PrimitiveType.TriangleList, Game.Renderer.SpriteShader));
|
||||
Game.Renderer.DrawBatch(vertexBuffer,
|
||||
verticesPerRow * firstRow, verticesPerRow * (lastRow - firstRow),
|
||||
PrimitiveType.QuadList));
|
||||
|
||||
foreach (var r in world.WorldActor.TraitsImplementing<IRenderOverlay>())
|
||||
r.Render( wr );
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
static float[] channelSelect = { 0.75f, 0.25f, -0.25f, -0.75f };
|
||||
|
||||
public static void FastCreateQuad(Vertex[] vertices, uint[] indices, float2 o, Sprite r, int palette, int nv, int ni, float2 size)
|
||||
public static void FastCreateQuad(Vertex[] vertices, float2 o, Sprite r, int palette, int nv, float2 size)
|
||||
{
|
||||
var attrib = new float2(palette / (float)HardwarePalette.MaxPalettes, channelSelect[(int)r.channel]);
|
||||
|
||||
@@ -52,15 +52,10 @@ namespace OpenRA.Graphics
|
||||
r.FastMapTextureCoords(0), attrib);
|
||||
vertices[nv + 1] = new Vertex(new float2(o.X + size.X, o.Y),
|
||||
r.FastMapTextureCoords(1), attrib);
|
||||
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),
|
||||
vertices[nv + 2] = new Vertex(new float2(o.X + size.X, o.Y + size.Y),
|
||||
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);
|
||||
vertices[nv + 3] = new Vertex(new float2(o.X, o.Y + size.Y),
|
||||
r.FastMapTextureCoords(2), attrib);
|
||||
}
|
||||
|
||||
static readonly int[] channelMasks = { 2, 1, 0, 3 }; // yes, our channel order is nuts.
|
||||
|
||||
@@ -278,17 +278,9 @@ namespace OpenRA.Renderer.Cg
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
public void DrawIndexedPrimitives( PrimitiveType pt, Range<int> vertices, Range<int> indices )
|
||||
public void DrawPrimitives( PrimitiveType pt, int firstVertex, int numVertices )
|
||||
{
|
||||
Gl.glDrawElements( ModeFromPrimitiveType( pt ), indices.End - indices.Start,
|
||||
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_INT, IntPtr.Zero);
|
||||
Gl.glDrawArrays( ModeFromPrimitiveType( pt ), firstVertex, numVertices );
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
@@ -299,6 +291,7 @@ namespace OpenRA.Renderer.Cg
|
||||
case PrimitiveType.PointList: return Gl.GL_POINTS;
|
||||
case PrimitiveType.LineList: return Gl.GL_LINES;
|
||||
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
|
||||
case PrimitiveType.QuadList: return Gl.GL_QUADS;
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -310,12 +303,12 @@ namespace OpenRA.Renderer.Cg
|
||||
case PrimitiveType.PointList: return 1;
|
||||
case PrimitiveType.LineList: return 2;
|
||||
case PrimitiveType.TriangleList: return 3;
|
||||
case PrimitiveType.QuadList: return 4;
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IVertexBuffer<Vertex> CreateVertexBuffer( int size ) { return new VertexBuffer<Vertex>( this, size ); }
|
||||
public IIndexBuffer CreateIndexBuffer( int size ) { return new IndexBuffer( this, size ); }
|
||||
public ITexture CreateTexture() { return new Texture( this ); }
|
||||
public ITexture CreateTexture( Bitmap bitmap ) { return new Texture( this, bitmap ); }
|
||||
public IShader CreateShader( string name ) { return new Shader( this, name ); }
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.FileFormats.Graphics;
|
||||
using Tao.OpenGl;
|
||||
|
||||
using ElemType = System.UInt32;
|
||||
|
||||
namespace OpenRA.Renderer.Cg
|
||||
{
|
||||
public class IndexBuffer : IIndexBuffer, IDisposable
|
||||
{
|
||||
int buffer;
|
||||
|
||||
public IndexBuffer(GraphicsDevice dev, int size)
|
||||
{
|
||||
Gl.glGenBuffers(1, out buffer);
|
||||
GraphicsDevice.CheckGlError();
|
||||
Bind();
|
||||
Gl.glBufferData(Gl.GL_ELEMENT_ARRAY_BUFFER,
|
||||
new IntPtr(sizeof(ElemType) * size),
|
||||
new ElemType[ size ],
|
||||
Gl.GL_DYNAMIC_DRAW);
|
||||
GraphicsDevice.CheckGlError();
|
||||
}
|
||||
|
||||
public void SetData(ElemType[] data, int length)
|
||||
{
|
||||
Bind();
|
||||
Gl.glBufferSubData(Gl.GL_ELEMENT_ARRAY_BUFFER,
|
||||
IntPtr.Zero,
|
||||
new IntPtr(sizeof(ElemType) * length),
|
||||
data);
|
||||
GraphicsDevice.CheckGlError();
|
||||
}
|
||||
|
||||
public void Bind()
|
||||
{
|
||||
Gl.glBindBuffer(Gl.GL_ELEMENT_ARRAY_BUFFER, buffer);
|
||||
GraphicsDevice.CheckGlError();
|
||||
}
|
||||
|
||||
bool disposed;
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed) return;
|
||||
GC.SuppressFinalize(this);
|
||||
Gl.glDeleteBuffers(1, ref buffer);
|
||||
GraphicsDevice.CheckGlError();
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
//~IndexBuffer() { Dispose(); }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -56,7 +56,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GraphicsDevice.cs" />
|
||||
<Compile Include="IndexBuffer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Shader.cs" />
|
||||
<Compile Include="Texture.cs" />
|
||||
|
||||
@@ -274,17 +274,9 @@ namespace OpenRA.Renderer.Glsl
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
public void DrawIndexedPrimitives( PrimitiveType pt, Range<int> vertices, Range<int> indices )
|
||||
public void DrawPrimitives( PrimitiveType pt, int firstVertex, int numVertices )
|
||||
{
|
||||
Gl.glDrawElements( ModeFromPrimitiveType( pt ), indices.End - indices.Start,
|
||||
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_INT, IntPtr.Zero);
|
||||
Gl.glDrawArrays( ModeFromPrimitiveType( pt ), firstVertex, numVertices );
|
||||
CheckGlError();
|
||||
}
|
||||
|
||||
@@ -295,6 +287,7 @@ namespace OpenRA.Renderer.Glsl
|
||||
case PrimitiveType.PointList: return Gl.GL_POINTS;
|
||||
case PrimitiveType.LineList: return Gl.GL_LINES;
|
||||
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
|
||||
case PrimitiveType.QuadList: return Gl.GL_QUADS;
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -306,12 +299,12 @@ namespace OpenRA.Renderer.Glsl
|
||||
case PrimitiveType.PointList: return 1;
|
||||
case PrimitiveType.LineList: return 2;
|
||||
case PrimitiveType.TriangleList: return 3;
|
||||
case PrimitiveType.QuadList: return 4;
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IVertexBuffer<Vertex> CreateVertexBuffer( int size ) { return new VertexBuffer<Vertex>( this, size ); }
|
||||
public IIndexBuffer CreateIndexBuffer( int size ) { return new IndexBuffer( this, size ); }
|
||||
public ITexture CreateTexture() { return new Texture( this ); }
|
||||
public ITexture CreateTexture( Bitmap bitmap ) { return new Texture( this, bitmap ); }
|
||||
public IShader CreateShader( string name ) { return new Shader( this, name ); }
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.FileFormats.Graphics;
|
||||
using Tao.OpenGl;
|
||||
|
||||
using ElemType = System.UInt32;
|
||||
|
||||
namespace OpenRA.Renderer.Glsl
|
||||
{
|
||||
public class IndexBuffer : IIndexBuffer, IDisposable
|
||||
{
|
||||
int buffer;
|
||||
|
||||
public IndexBuffer(GraphicsDevice dev, int size)
|
||||
{
|
||||
Gl.glGenBuffers(1, out buffer);
|
||||
GraphicsDevice.CheckGlError();
|
||||
Bind();
|
||||
Gl.glBufferData(Gl.GL_ELEMENT_ARRAY_BUFFER,
|
||||
new IntPtr(sizeof(ElemType) * size),
|
||||
new ElemType[ size ],
|
||||
Gl.GL_DYNAMIC_DRAW);
|
||||
GraphicsDevice.CheckGlError();
|
||||
}
|
||||
|
||||
public void SetData(ElemType[] data, int length)
|
||||
{
|
||||
Bind();
|
||||
Gl.glBufferSubData(Gl.GL_ELEMENT_ARRAY_BUFFER,
|
||||
IntPtr.Zero,
|
||||
new IntPtr(sizeof(ElemType) * length),
|
||||
data);
|
||||
GraphicsDevice.CheckGlError();
|
||||
}
|
||||
|
||||
public void Bind()
|
||||
{
|
||||
Gl.glBindBuffer(Gl.GL_ELEMENT_ARRAY_BUFFER, buffer);
|
||||
GraphicsDevice.CheckGlError();
|
||||
}
|
||||
|
||||
bool disposed;
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed) return;
|
||||
GC.SuppressFinalize(this);
|
||||
Gl.glDeleteBuffers(1, ref buffer);
|
||||
GraphicsDevice.CheckGlError();
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
//~IndexBuffer() { Dispose(); }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -56,7 +56,6 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="GraphicsDevice.cs" />
|
||||
<Compile Include="IndexBuffer.cs" />
|
||||
<Compile Include="Shader.cs" />
|
||||
<Compile Include="Texture.cs" />
|
||||
<Compile Include="VertexBuffer.cs" />
|
||||
|
||||
@@ -39,11 +39,9 @@ namespace OpenRA.Renderer.Null
|
||||
ih.ModifierKeys(Modifiers.None);
|
||||
}
|
||||
|
||||
public void DrawIndexedPrimitives(PrimitiveType pt, Range<int> vertices, Range<int> indices) { }
|
||||
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives) { }
|
||||
public void DrawPrimitives(PrimitiveType pt, int firstVertex, int numVertices) { }
|
||||
|
||||
public IVertexBuffer<Vertex> CreateVertexBuffer(int size) { return new NullVertexBuffer<Vertex>(); }
|
||||
public IIndexBuffer CreateIndexBuffer(int size) { return new NullIndexBuffer(); }
|
||||
public ITexture CreateTexture() { return new NullTexture(); }
|
||||
public ITexture CreateTexture(Bitmap bitmap) { return new NullTexture(); }
|
||||
public IShader CreateShader(string name) { return new NullShader(); }
|
||||
@@ -51,12 +49,6 @@ namespace OpenRA.Renderer.Null
|
||||
public int GpuMemoryUsed { get { return 0; } }
|
||||
}
|
||||
|
||||
public class NullIndexBuffer : IIndexBuffer
|
||||
{
|
||||
public void Bind() {}
|
||||
public void SetData(uint[] indices, int length) {}
|
||||
}
|
||||
|
||||
public class NullShader : IShader
|
||||
{
|
||||
public void SetValue(string name, float x, float y) { }
|
||||
|
||||
Reference in New Issue
Block a user