added null renderer, game runs. good place to start.

This commit is contained in:
Chris Forbes
2010-02-15 16:22:13 +13:00
parent 283c92fa91
commit a8e07d4dfb
12 changed files with 210 additions and 42 deletions

View File

@@ -1,12 +1,12 @@
using System.Drawing;
using Ijw.DirectX;
using OpenRa.Gl;
namespace OpenRa.Graphics
{
class LineRenderer
{
Renderer renderer;
FvfVertexBuffer<Vertex> vertexBuffer;
VertexBuffer<Vertex> vertexBuffer;
IndexBuffer indexBuffer; /* kindof a waste of space, but the GPU likes indexing, oh well */
const int linesPerBatch = 1024;
@@ -19,7 +19,7 @@ namespace OpenRa.Graphics
public LineRenderer( Renderer renderer )
{
this.renderer = renderer;
vertexBuffer = new FvfVertexBuffer<Vertex>( renderer.Device, vertices.Length, Vertex.Format );
vertexBuffer = new VertexBuffer<Vertex>( renderer.Device, vertices.Length, Vertex.Format );
indexBuffer = new IndexBuffer( renderer.Device, indices.Length );
}

View File

@@ -1,6 +1,6 @@
using System.Xml;
using System.Drawing;
using Ijw.DirectX;
using OpenRa.Gl;
using System.IO;
namespace OpenRa.Graphics
{

View File

@@ -1,6 +1,6 @@
using System.Drawing;
using System.Windows.Forms;
using Ijw.DirectX;
using OpenRa.Gl;
using OpenRa.FileFormats;
using OpenRa.Support;
@@ -19,14 +19,13 @@ namespace OpenRa.Graphics
public Texture PaletteTexture;
readonly SpriteHelper sh;
readonly FontHelper fhDebug, fhTitle;
//readonly SpriteHelper sh;
//readonly FontHelper fhDebug, fhTitle;
public Renderer(Control host, Size resolution, bool windowed)
{
host.ClientSize = resolution;
device = GraphicsDevice.Create(host,
resolution.Width, resolution.Height, windowed, false);
device = new GraphicsDevice(host, resolution.Width, resolution.Height, windowed, false);
SpriteShader = new Shader(device, FileSystem.Open("world-shp.fx"));
SpriteShader.Quality = ShaderQuality.Low;
@@ -37,9 +36,9 @@ namespace OpenRa.Graphics
WorldSpriteShader = new Shader(device, FileSystem.Open("chrome-shp.fx"));
WorldSpriteShader.Quality = ShaderQuality.High;
sh = new SpriteHelper(device);
fhDebug = new FontHelper(device, "Tahoma", 10, false);
fhTitle = new FontHelper(device, "Tahoma", 10, true);
//sh = new SpriteHelper(device);
//fhDebug = new FontHelper(device, "Tahoma", 10, false);
//fhTitle = new FontHelper(device, "Tahoma", 10, true);
}
public GraphicsDevice Device { get { return device; } }
@@ -47,7 +46,7 @@ namespace OpenRa.Graphics
public void BeginFrame(float2 r1, float2 r2, float2 scroll)
{
device.Begin();
device.Clear(0, Surfaces.Color);
device.Clear(Color.Black);
SpriteShader.SetValue("Palette", PaletteTexture);
SpriteShader.SetValue("Scroll", scroll);
@@ -62,60 +61,58 @@ namespace OpenRa.Graphics
device.Present();
}
public void DrawBatch<T>(FvfVertexBuffer<T> vertices, IndexBuffer indices,
public void DrawBatch<T>(VertexBuffer<T> vertices, IndexBuffer indices,
Range<int> vertexRange, Range<int> indexRange, Texture texture, PrimitiveType type, Shader shader)
where T : struct
{
shader.SetValue("DiffuseTexture", texture);
shader.Commit();
vertices.Bind(0);
vertices.Bind();
indices.Bind();
device.DrawIndexedPrimitives(type,
vertexRange, indexRange);
device.DrawIndexedPrimitives(type, vertexRange, indexRange);
PerfHistory.Increment("batches", 1);
}
public void DrawBatch<T>(FvfVertexBuffer<T> vertices, IndexBuffer indices,
public void DrawBatch<T>(VertexBuffer<T> vertices, IndexBuffer indices,
int vertexPool, int numPrimitives, Texture texture, PrimitiveType type)
where T : struct
{
SpriteShader.SetValue("DiffuseTexture", texture);
SpriteShader.Commit();
vertices.Bind(0);
vertices.Bind();
indices.Bind();
device.DrawIndexedPrimitives(type,
vertexPool, numPrimitives);
device.DrawIndexedPrimitives(type, vertexPool, numPrimitives);
PerfHistory.Increment("batches", 1);
}
public void DrawText(string text, int2 pos, Color c)
{
sh.Begin();
fhDebug.Draw(sh, text, pos.X, pos.Y, c.ToArgb());
sh.End();
//sh.Begin();
//fhDebug.Draw(sh, text, pos.X, pos.Y, c.ToArgb());
//sh.End();
}
public void DrawText2(string text, int2 pos, Color c)
{
sh.Begin();
fhTitle.Draw(sh, text, pos.X, pos.Y, c.ToArgb());
sh.End();
//sh.Begin();
//fhTitle.Draw(sh, text, pos.X, pos.Y, c.ToArgb());
//sh.End();
}
public int2 MeasureText(string text)
{
return new int2(fhDebug.MeasureText(sh, text));
return new int2(20,20);//fhDebug.MeasureText(sh, text));
}
public int2 MeasureText2(string text)
{
return new int2(fhTitle.MeasureText(sh, text));
return new int2(20,20);//fhTitle.MeasureText(sh, text));
}
}
}

View File

@@ -1,5 +1,5 @@
using System.Drawing;
using Ijw.DirectX;
using OpenRa.Gl;
using OpenRa.FileFormats;
namespace OpenRa.Graphics
@@ -25,7 +25,7 @@ namespace OpenRa.Graphics
void Resolve()
{
texture = Texture.CreateFromBitmap(bitmap, renderer.Device);
texture = new Texture(renderer.Device, bitmap);
}
public Texture Texture

View File

@@ -1,10 +1,10 @@
using Ijw.DirectX;
using OpenRa.Gl;
namespace OpenRa.Graphics
{
class SpriteRenderer
{
FvfVertexBuffer<Vertex> vertexBuffer;
VertexBuffer<Vertex> vertexBuffer;
IndexBuffer indexBuffer;
Renderer renderer;
Shader shader;
@@ -23,7 +23,7 @@ namespace OpenRa.Graphics
this.renderer = renderer;
this.shader = shader;
vertexBuffer = new FvfVertexBuffer<Vertex>(renderer.Device, vertices.Length, Vertex.Format);
vertexBuffer = new VertexBuffer<Vertex>(renderer.Device, vertices.Length, Vertex.Format);
indexBuffer = new IndexBuffer(renderer.Device, indices.Length);
quality = allowAlpha ? ShaderQuality.High : ShaderQuality.Low;

View File

@@ -1,5 +1,5 @@
using System.Drawing;
using Ijw.DirectX;
using OpenRa.Gl;
using IjwFramework.Collections;
using OpenRa.FileFormats;
@@ -7,7 +7,7 @@ namespace OpenRa.Graphics
{
class TerrainRenderer
{
FvfVertexBuffer<Vertex> vertexBuffer;
VertexBuffer<Vertex> vertexBuffer;
IndexBuffer indexBuffer;
Sheet terrainSheet;
@@ -43,7 +43,7 @@ namespace OpenRa.Graphics
terrainSheet = tileMapping[map.MapTiles[map.XOffset, map.YOffset]].sheet;
vertexBuffer = new FvfVertexBuffer<Vertex>( renderer.Device, vertices.Length, Vertex.Format );
vertexBuffer = new VertexBuffer<Vertex>( renderer.Device, vertices.Length, Vertex.Format );
vertexBuffer.SetData( vertices );
indexBuffer = new IndexBuffer( renderer.Device, indices.Length );

View File

@@ -1,5 +1,5 @@
using System.Runtime.InteropServices;
using Ijw.DirectX;
using OpenRa.Gl;
namespace OpenRa.Graphics
{