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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -55,10 +55,6 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Ijw.DirectX, Version=0.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Ijw.DirectX\bin\Ijw.DirectX.dll</HintPath>
</Reference>
<Reference Include="IjwFramework, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="IjwFramework, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\Ijw.DirectX\Ijw.Framework\IjwFramework\bin\Debug\IjwFramework.dll</HintPath> <HintPath>..\Ijw.DirectX\Ijw.Framework\IjwFramework\bin\Debug\IjwFramework.dll</HintPath>
@@ -283,6 +279,10 @@
<Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project> <Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project>
<Name>OpenRa.FileFormats</Name> <Name>OpenRa.FileFormats</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\OpenRa.Gl\OpenRa.Gl.csproj">
<Project>{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}</Project>
<Name>OpenRa.Gl</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0"> <BootstrapperPackage Include="Microsoft.Net.Framework.2.0">

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
namespace OpenRa.Gl
{
public class GraphicsDevice
{
public GraphicsDevice(Control host, int width, int height, bool fullscreen, bool vsync) { }
public void EnableScissor(int left, int top, int width, int height) { }
public void DisableScissor() { }
public void Begin() { }
public void End() { }
public void Clear(Color c) { }
public void Present() { }
public void DrawIndexedPrimitives(PrimitiveType pt, Range<int> vertices, Range<int> indices) { }
public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives) { }
}
public struct Range<T>
{
public Range(T start, T end) { }
}
public class VertexBuffer<T> where T : struct
{
public VertexBuffer(GraphicsDevice dev, int size, VertexFormat fmt) { }
public void SetData(T[] data) { }
public void Bind() { }
}
public class IndexBuffer
{
public IndexBuffer(GraphicsDevice dev, int size) { }
public void SetData(ushort[] data) { }
public void Bind() { }
}
public class Shader
{
public Shader(GraphicsDevice dev, Stream s) { }
public ShaderQuality Quality { get; set; }
public void Render(Action a) { }
public void SetValue(string param, Texture texture) { }
public void SetValue<T>(string param, T t) where T : struct { }
public void Commit() { }
}
public class Texture
{
public Texture(GraphicsDevice dev, Bitmap bitmap) { }
public void SetData(Bitmap bitmap) { }
}
[Flags]
public enum VertexFormat { Position, Texture2 }
public enum ShaderQuality { Low, Medium, High }
public enum PrimitiveType { PointList, LineList, TriangleList }
}

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenRa.Gl</RootNamespace>
<AssemblyName>OpenRa.Gl</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Tao.Cg, Version=2.0.0.0, Culture=neutral, PublicKeyToken=52fa5aba625fe731, processorArchitecture=MSIL" />
<Reference Include="Tao.Glfw, Version=2.6.0.0, Culture=neutral, PublicKeyToken=2bb092b6587e4402, processorArchitecture=MSIL" />
<Reference Include="Tao.OpenGl, Version=2.1.0.12, Culture=neutral, PublicKeyToken=1ca010269a4501ef, processorArchitecture=MSIL" />
</ItemGroup>
<ItemGroup>
<Compile Include="GraphicsDevice.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OpenRa.Gl")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("OpenRa.Gl")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5531344c-b25d-4641-bc3c-fe035cc777bd")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.Mods.Aftermath", "Op
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.Mods.Cnc", "OpenRa.Mods.Cnc\OpenRa.Mods.Cnc.csproj", "{2881135D-4D62-493E-8F83-5EEE92CCC6BE}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.Mods.Cnc", "OpenRa.Mods.Cnc\OpenRa.Mods.Cnc.csproj", "{2881135D-4D62-493E-8F83-5EEE92CCC6BE}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.Gl", "OpenRa.Gl\OpenRa.Gl.csproj", "{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -49,6 +51,10 @@ Global
{2881135D-4D62-493E-8F83-5EEE92CCC6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU {2881135D-4D62-493E-8F83-5EEE92CCC6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2881135D-4D62-493E-8F83-5EEE92CCC6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU {2881135D-4D62-493E-8F83-5EEE92CCC6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2881135D-4D62-493E-8F83-5EEE92CCC6BE}.Release|Any CPU.Build.0 = Release|Any CPU {2881135D-4D62-493E-8F83-5EEE92CCC6BE}.Release|Any CPU.Build.0 = Release|Any CPU
{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE