git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@2049 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
chrisf
2008-07-20 20:06:19 +00:00
parent 6f8919d301
commit 4ea033f63d
42 changed files with 247 additions and 198 deletions

View File

@@ -0,0 +1,68 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using Ijw.DirectX;
using OpenRa.FileFormats;
namespace OpenRa.Game.Graphics
{
class Renderer
{
readonly GraphicsDevice device;
readonly Shader shader;
const string shaderName = "diffuse.fx";
public void SetPalette(HardwarePalette hp)
{
shader.SetValue("Palette", hp.Texture);
}
public Renderer(Control host, Size resolution, bool windowed)
{
host.ClientSize = resolution;
device = GraphicsDevice.Create(host,
resolution.Width, resolution.Height, windowed, false);
shader = new Shader(device, FileSystem.Open(shaderName));
shader.Quality = ShaderQuality.Low;
}
public GraphicsDevice Device { get { return device; } }
public void BeginFrame( float2 r1, float2 r2, float2 scroll )
{
device.Begin();
shader.SetValue("Scroll", scroll);
shader.SetValue("r1", r1);
shader.SetValue("r2", r2);
}
public void EndFrame()
{
device.End();
device.Present();
}
public void DrawWithShader(ShaderQuality quality, Action task)
{
shader.Quality = quality;
shader.Render(() => task());
}
public void DrawBatch<T>(FvfVertexBuffer<T> vertices, IndexBuffer indices,
Range<int> vertexRange, Range<int> indexRange, Texture texture)
where T : struct
{
shader.SetValue("DiffuseTexture", texture);
shader.Commit();
vertices.Bind(0);
indices.Bind();
device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
vertexRange, indexRange);
}
}
}