git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@2049 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
68
OpenRa.Game/Graphics/Renderer.cs
Normal file
68
OpenRa.Game/Graphics/Renderer.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user