diff --git a/OpenRa.Game/Graphics/LineRenderer.cs b/OpenRa.Game/Graphics/LineRenderer.cs index f284489d9f..c1b6841b63 100644 --- a/OpenRa.Game/Graphics/LineRenderer.cs +++ b/OpenRa.Game/Graphics/LineRenderer.cs @@ -1,12 +1,12 @@ using System.Drawing; -using Ijw.DirectX; +using OpenRa.Gl; namespace OpenRa.Graphics { class LineRenderer { Renderer renderer; - FvfVertexBuffer vertexBuffer; + VertexBuffer 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( renderer.Device, vertices.Length, Vertex.Format ); + vertexBuffer = new VertexBuffer( renderer.Device, vertices.Length, Vertex.Format ); indexBuffer = new IndexBuffer( renderer.Device, indices.Length ); } diff --git a/OpenRa.Game/Graphics/MappedImage.cs b/OpenRa.Game/Graphics/MappedImage.cs index 06da34390e..8296e0d0ff 100644 --- a/OpenRa.Game/Graphics/MappedImage.cs +++ b/OpenRa.Game/Graphics/MappedImage.cs @@ -1,6 +1,6 @@ using System.Xml; using System.Drawing; -using Ijw.DirectX; +using OpenRa.Gl; using System.IO; namespace OpenRa.Graphics { diff --git a/OpenRa.Game/Graphics/Renderer.cs b/OpenRa.Game/Graphics/Renderer.cs index 1547b95a25..f391af9dc9 100644 --- a/OpenRa.Game/Graphics/Renderer.cs +++ b/OpenRa.Game/Graphics/Renderer.cs @@ -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(FvfVertexBuffer vertices, IndexBuffer indices, + public void DrawBatch(VertexBuffer vertices, IndexBuffer indices, Range vertexRange, Range 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(FvfVertexBuffer vertices, IndexBuffer indices, + public void DrawBatch(VertexBuffer 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)); } } } diff --git a/OpenRa.Game/Graphics/Sheet.cs b/OpenRa.Game/Graphics/Sheet.cs index 9473d2215e..64348c0e99 100644 --- a/OpenRa.Game/Graphics/Sheet.cs +++ b/OpenRa.Game/Graphics/Sheet.cs @@ -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 diff --git a/OpenRa.Game/Graphics/SpriteRenderer.cs b/OpenRa.Game/Graphics/SpriteRenderer.cs index ec523ce86a..47a03f6b49 100644 --- a/OpenRa.Game/Graphics/SpriteRenderer.cs +++ b/OpenRa.Game/Graphics/SpriteRenderer.cs @@ -1,10 +1,10 @@ -using Ijw.DirectX; +using OpenRa.Gl; namespace OpenRa.Graphics { class SpriteRenderer { - FvfVertexBuffer vertexBuffer; + VertexBuffer vertexBuffer; IndexBuffer indexBuffer; Renderer renderer; Shader shader; @@ -23,7 +23,7 @@ namespace OpenRa.Graphics this.renderer = renderer; this.shader = shader; - vertexBuffer = new FvfVertexBuffer(renderer.Device, vertices.Length, Vertex.Format); + vertexBuffer = new VertexBuffer(renderer.Device, vertices.Length, Vertex.Format); indexBuffer = new IndexBuffer(renderer.Device, indices.Length); quality = allowAlpha ? ShaderQuality.High : ShaderQuality.Low; diff --git a/OpenRa.Game/Graphics/TerrainRenderer.cs b/OpenRa.Game/Graphics/TerrainRenderer.cs index 5894c26792..cc90444efc 100644 --- a/OpenRa.Game/Graphics/TerrainRenderer.cs +++ b/OpenRa.Game/Graphics/TerrainRenderer.cs @@ -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 vertexBuffer; + VertexBuffer vertexBuffer; IndexBuffer indexBuffer; Sheet terrainSheet; @@ -43,7 +43,7 @@ namespace OpenRa.Graphics terrainSheet = tileMapping[map.MapTiles[map.XOffset, map.YOffset]].sheet; - vertexBuffer = new FvfVertexBuffer( renderer.Device, vertices.Length, Vertex.Format ); + vertexBuffer = new VertexBuffer( renderer.Device, vertices.Length, Vertex.Format ); vertexBuffer.SetData( vertices ); indexBuffer = new IndexBuffer( renderer.Device, indices.Length ); diff --git a/OpenRa.Game/Graphics/Vertex.cs b/OpenRa.Game/Graphics/Vertex.cs index 9082b0f595..72ca506750 100644 --- a/OpenRa.Game/Graphics/Vertex.cs +++ b/OpenRa.Game/Graphics/Vertex.cs @@ -1,5 +1,5 @@ using System.Runtime.InteropServices; -using Ijw.DirectX; +using OpenRa.Gl; namespace OpenRa.Graphics { diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index df748b80b5..dcd8c0dd58 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -55,10 +55,6 @@ prompt - - False - ..\Ijw.DirectX\bin\Ijw.DirectX.dll - False ..\Ijw.DirectX\Ijw.Framework\IjwFramework\bin\Debug\IjwFramework.dll @@ -283,6 +279,10 @@ {BDAEAB25-991E-46A7-AF1E-4F0E03358DAA} OpenRa.FileFormats + + {67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC} + OpenRa.Gl + diff --git a/OpenRa.Gl/GraphicsDevice.cs b/OpenRa.Gl/GraphicsDevice.cs new file mode 100644 index 0000000000..beb9aadc06 --- /dev/null +++ b/OpenRa.Gl/GraphicsDevice.cs @@ -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 vertices, Range indices) { } + public void DrawIndexedPrimitives(PrimitiveType pt, int numVerts, int numPrimitives) { } + } + + public struct Range + { + public Range(T start, T end) { } + } + + public class VertexBuffer 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(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 } +} diff --git a/OpenRa.Gl/OpenRa.Gl.csproj b/OpenRa.Gl/OpenRa.Gl.csproj new file mode 100644 index 0000000000..2e6920740f --- /dev/null +++ b/OpenRa.Gl/OpenRa.Gl.csproj @@ -0,0 +1,64 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC} + Library + Properties + OpenRa.Gl + OpenRa.Gl + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + + + 3.5 + + + 3.5 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenRa.Gl/Properties/AssemblyInfo.cs b/OpenRa.Gl/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..0f815cf798 --- /dev/null +++ b/OpenRa.Gl/Properties/AssemblyInfo.cs @@ -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")] diff --git a/OpenRa.sln b/OpenRa.sln index eab68ff896..fa15da7fb8 100644 --- a/OpenRa.sln +++ b/OpenRa.sln @@ -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