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

This commit is contained in:
chrisf
2007-10-03 22:12:31 +00:00
parent b5627d0bb2
commit 9354daed64
3 changed files with 43 additions and 55 deletions

View File

@@ -6,21 +6,20 @@ using System.Drawing;
using BluntDirectX.Direct3D;
using System.IO;
using OpenRa.FileFormats;
using IjwFramework.Delegates;
namespace OpenRa.Game
{
class Renderer
{
readonly GraphicsDevice device;
readonly Effect shader;
readonly IntPtr r1Handle, r2Handle, baseTextureHandle, scrollHandle, paletteHandle;
readonly Shader shader;
const string shaderName = "diffuse.fx";
public void SetPalette(HardwarePalette hp)
{
shader.SetTexture(paletteHandle, hp.Texture);
shader.SetValue("Palette", hp.Texture);
}
public Renderer(Control host, Size resolution, bool windowed)
@@ -29,14 +28,8 @@ namespace OpenRa.Game
device = GraphicsDevice.Create(host,
resolution.Width, resolution.Height, windowed, false);
shader = new Effect(device, FileSystem.Open(shaderName));
shader = new Shader(device, FileSystem.Open(shaderName));
shader.Quality = ShaderQuality.Low;
baseTextureHandle = shader.GetHandle("DiffuseTexture");
scrollHandle = shader.GetHandle("Scroll");
r1Handle = shader.GetHandle("r1");
r2Handle = shader.GetHandle("r2");
paletteHandle = shader.GetHandle("Palette");
}
public GraphicsDevice Device { get { return device; } }
@@ -45,9 +38,9 @@ namespace OpenRa.Game
{
device.Begin();
shader.SetValue(scrollHandle, scroll);
shader.SetValue(r1Handle, r1);
shader.SetValue(r2Handle, r2);
shader.SetValue("Scroll", scroll);
shader.SetValue("r1", r1);
shader.SetValue("r2", r2);
}
public void EndFrame()
@@ -56,26 +49,17 @@ namespace OpenRa.Game
device.Present();
}
public void DrawWithShader(ShaderQuality quality, MethodInvoker task)
public void DrawWithShader(ShaderQuality quality, Action task)
{
shader.Quality = quality;
int passes = shader.Begin();
for (int pass = 0; pass < passes; pass++)
{
shader.BeginPass(pass);
task();
shader.EndPass();
}
shader.End();
shader.Render(task);
}
public void DrawBatch<T>(FvfVertexBuffer<T> vertices, IndexBuffer indices,
Range<int> vertexRange, Range<int> indexRange, Texture texture)
where T : struct
{
shader.SetTexture(baseTextureHandle, texture);
shader.SetValue("DiffuseTexture", texture);
shader.Commit();
vertices.Bind(0);