added null renderer, game runs. good place to start.
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Xml;
|
||||
using System.Drawing;
|
||||
using Ijw.DirectX;
|
||||
using OpenRa.Gl;
|
||||
using System.IO;
|
||||
namespace OpenRa.Graphics
|
||||
{
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Ijw.DirectX;
|
||||
using OpenRa.Gl;
|
||||
|
||||
namespace OpenRa.Graphics
|
||||
{
|
||||
|
||||
@@ -55,10 +55,6 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<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">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Ijw.DirectX\Ijw.Framework\IjwFramework\bin\Debug\IjwFramework.dll</HintPath>
|
||||
@@ -283,6 +279,10 @@
|
||||
<Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project>
|
||||
<Name>OpenRa.FileFormats</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OpenRa.Gl\OpenRa.Gl.csproj">
|
||||
<Project>{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}</Project>
|
||||
<Name>OpenRa.Gl</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||
|
||||
65
OpenRa.Gl/GraphicsDevice.cs
Normal file
65
OpenRa.Gl/GraphicsDevice.cs
Normal 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 }
|
||||
}
|
||||
64
OpenRa.Gl/OpenRa.Gl.csproj
Normal file
64
OpenRa.Gl/OpenRa.Gl.csproj
Normal 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>
|
||||
36
OpenRa.Gl/Properties/AssemblyInfo.cs
Normal file
36
OpenRa.Gl/Properties/AssemblyInfo.cs
Normal 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")]
|
||||
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.Mods.Aftermath", "Op
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.Mods.Cnc", "OpenRa.Mods.Cnc\OpenRa.Mods.Cnc.csproj", "{2881135D-4D62-493E-8F83-5EEE92CCC6BE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.Gl", "OpenRa.Gl\OpenRa.Gl.csproj", "{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user