IBOless rendering with quads; considerably reduces renderer complexity

This commit is contained in:
Chris Forbes
2011-05-05 17:50:23 +12:00
parent 8e1bc25006
commit 4d6b2c7954
13 changed files with 43 additions and 262 deletions

View File

@@ -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 ); }

View File

@@ -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(); }
}
}

View File

@@ -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" />