From ccf66cde2f7e29853c716ad442df3ef54e270c75 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 11 Nov 2010 23:53:29 +1300 Subject: [PATCH] Expose Graphics.Renderer setting; Refactor Renderer.Null. --- Makefile | 12 ++++++-- OpenRA.Game/GameRules/Settings.cs | 1 + OpenRA.Game/Graphics/Renderer.cs | 2 +- OpenRA.Renderer.Cg/GraphicsDevice.cs | 1 + OpenRA.Renderer.Gl/GraphicsDevice.cs | 1 + OpenRA.Renderer.Null/NullGraphicsDevice.cs | 29 +++++++++++++++++++ OpenRA.Renderer.Null/NullIndexBuffer.cs | 20 ------------- OpenRA.Renderer.Null/NullShader.cs | 23 --------------- OpenRA.Renderer.Null/NullTexture.cs | 22 -------------- OpenRA.Renderer.Null/NullVertexBuffer.cs | 20 ------------- .../OpenRA.Renderer.Null.csproj | 4 --- 11 files changed, 43 insertions(+), 92 deletions(-) delete mode 100644 OpenRA.Renderer.Null/NullIndexBuffer.cs delete mode 100644 OpenRA.Renderer.Null/NullShader.cs delete mode 100644 OpenRA.Renderer.Null/NullTexture.cs delete mode 100644 OpenRA.Renderer.Null/NullVertexBuffer.cs diff --git a/Makefile b/Makefile index 688fbf1f40..e75441c201 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CSC = gmcs CSFLAGS = -nologo -warn:4 -debug:+ -debug:full -optimize- -codepage:utf8 -unsafe DEFINE = DEBUG;TRACE -PROGRAMS = fileformats rcg rgl game ra cnc seqed editor ralint filex tsbuild utility +PROGRAMS = fileformats rcg rgl rnull game ra cnc seqed editor ralint filex tsbuild utility prefix = /usr/local datarootdir = $(prefix)/share datadir = $(datarootdir) @@ -25,6 +25,7 @@ rcg_DEPS = $(fileformats_TARGET) $(game_TARGET) rcg_LIBS = $(COMMON_LIBS) System.Windows.Forms.dll \ thirdparty/Tao/Tao.Cg.dll thirdparty/Tao/Tao.OpenGl.dll thirdparty/Tao/Tao.Sdl.dll \ $(rcg_DEPS) $(game_TARGET) + rgl_SRCS = $(shell find OpenRA.Renderer.Gl/ -iname '*.cs') rgl_TARGET = OpenRA.Renderer.Gl.dll rgl_KIND = library @@ -33,6 +34,13 @@ rgl_LIBS = $(COMMON_LIBS) System.Windows.Forms.dll \ thirdparty/Tao/Tao.Cg.dll thirdparty/Tao/Tao.OpenGl.dll thirdparty/Tao/Tao.Sdl.dll \ $(rgl_DEPS) $(game_TARGET) +rnull_SRCS = $(shell find OpenRA.Renderer.Null/ -iname '*.cs') +rnull_TARGET = OpenRA.Renderer.Null.dll +rnull_KIND = library +rnull_DEPS = $(fileformats_TARGET) $(game_TARGET) +rnull_LIBS = $(COMMON_LIBS) System.Windows.Forms.dll \ + $(rnull_DEPS) $(game_TARGET) + game_SRCS = $(shell find OpenRA.Game/ -iname '*.cs') game_TARGET = OpenRA.Game.exe game_KIND = winexe @@ -98,7 +106,7 @@ utility_LIBS = $(COMMON_LIBS) $(utility_DEPS) .SUFFIXES: .PHONY: clean all game tool default mods mod_ra mod_cnc install uninstall editor_res editor tsbuild ralint seqed filex utility -game: $(fileformats_TARGET) $(rcg_TARGET) $(rgl_TARGET) $(game_TARGET) $(ra_TARGET) $(cnc_TARGET) $(utility_TARGET) +game: $(fileformats_TARGET) $(rcg_TARGET) $(rgl_TARGET) $(rnull_TARGET) $(game_TARGET) $(ra_TARGET) $(cnc_TARGET) $(utility_TARGET) clean: @-rm *.exe *.dll *.mdb mods/**/*.dll mods/**/*.mdb *.resources diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index 76f55a3df2..9712dd8417 100755 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -39,6 +39,7 @@ namespace OpenRA.GameRules public class GraphicSettings { + public string Renderer = "Cg"; public WindowMode Mode = WindowMode.PseudoFullscreen; public int2 FullscreenSize = new int2(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); public int2 WindowedSize = new int2(1024, 768); diff --git a/OpenRA.Game/Graphics/Renderer.cs b/OpenRA.Game/Graphics/Renderer.cs index ccb6491799..5004e59f87 100644 --- a/OpenRA.Game/Graphics/Renderer.cs +++ b/OpenRA.Game/Graphics/Renderer.cs @@ -133,7 +133,7 @@ namespace OpenRA.Graphics internal static void Initialize( OpenRA.FileFormats.Graphics.WindowMode windowMode ) { var resolution = GetResolution( windowMode ); - device = CreateDevice( Assembly.LoadFile( Path.GetFullPath( "OpenRA.Renderer.Gl.dll" ) ), resolution.Width, resolution.Height, windowMode, false ); + device = CreateDevice( Assembly.LoadFile( Path.GetFullPath( "OpenRA.Renderer.{0}.dll".F(Game.Settings.Graphics.Renderer) ) ), resolution.Width, resolution.Height, windowMode, false ); } static Size GetResolution(WindowMode windowmode) diff --git a/OpenRA.Renderer.Cg/GraphicsDevice.cs b/OpenRA.Renderer.Cg/GraphicsDevice.cs index da9bc8cf64..6ef5b5e530 100755 --- a/OpenRA.Renderer.Cg/GraphicsDevice.cs +++ b/OpenRA.Renderer.Cg/GraphicsDevice.cs @@ -50,6 +50,7 @@ namespace OpenRA.Renderer.Cg public GraphicsDevice( int width, int height, WindowMode window, bool vsync ) { + Console.WriteLine("Using Cg renderer"); Sdl.SDL_Init( Sdl.SDL_INIT_NOPARACHUTE | Sdl.SDL_INIT_VIDEO ); Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_DOUBLEBUFFER, 1 ); Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_RED_SIZE, 8 ); diff --git a/OpenRA.Renderer.Gl/GraphicsDevice.cs b/OpenRA.Renderer.Gl/GraphicsDevice.cs index 78849cbdd5..42dcdaf07e 100755 --- a/OpenRA.Renderer.Gl/GraphicsDevice.cs +++ b/OpenRA.Renderer.Gl/GraphicsDevice.cs @@ -47,6 +47,7 @@ namespace OpenRA.Renderer.Glsl public GraphicsDevice( int width, int height, WindowMode window, bool vsync ) { + Console.WriteLine("Using Gl renderer"); Sdl.SDL_Init( Sdl.SDL_INIT_NOPARACHUTE | Sdl.SDL_INIT_VIDEO ); Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_DOUBLEBUFFER, 1 ); Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_RED_SIZE, 8 ); diff --git a/OpenRA.Renderer.Null/NullGraphicsDevice.cs b/OpenRA.Renderer.Null/NullGraphicsDevice.cs index 31e13de739..824bedf6e6 100644 --- a/OpenRA.Renderer.Null/NullGraphicsDevice.cs +++ b/OpenRA.Renderer.Null/NullGraphicsDevice.cs @@ -12,6 +12,7 @@ using System.Drawing; using System.IO; using OpenRA.FileFormats.Graphics; using OpenRA.Graphics; +using System; [assembly: Renderer(typeof(OpenRA.Renderer.Null.NullGraphicsDevice))] @@ -23,6 +24,7 @@ namespace OpenRA.Renderer.Null public NullGraphicsDevice(int width, int height, WindowMode window, bool vsync) { + Console.WriteLine("Using Null renderer"); WindowSize = new Size(width, height); } @@ -46,4 +48,31 @@ namespace OpenRA.Renderer.Null public ITexture CreateTexture(Bitmap bitmap) { return new NullTexture(); } public IShader CreateShader(string name) { return new NullShader(); } } + + public class NullIndexBuffer : IIndexBuffer + { + public void Bind() {} + public void SetData(ushort[] indices, int length) {} + } + + public class NullShader : IShader + { + public void SetValue(string name, float x, float y) { } + public void SetValue(string param, ITexture texture) { } + public void Commit() { } + public void Render(Action a) { } + } + + public class NullTexture : ITexture + { + public void SetData(Bitmap bitmap) { } + public void SetData(uint[,] colors) { } + public void SetData(byte[] colors, int width, int height) { } + } + + class NullVertexBuffer : IVertexBuffer + { + public void Bind() { } + public void SetData(T[] vertices, int length) { } + } } diff --git a/OpenRA.Renderer.Null/NullIndexBuffer.cs b/OpenRA.Renderer.Null/NullIndexBuffer.cs deleted file mode 100644 index 723f64b297..0000000000 --- a/OpenRA.Renderer.Null/NullIndexBuffer.cs +++ /dev/null @@ -1,20 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see LICENSE. - */ -#endregion - -using OpenRA.FileFormats.Graphics; - -namespace OpenRA.Renderer.Null -{ - public class NullIndexBuffer : IIndexBuffer - { - public void Bind() {} - public void SetData(ushort[] indices, int length) {} - } -} diff --git a/OpenRA.Renderer.Null/NullShader.cs b/OpenRA.Renderer.Null/NullShader.cs deleted file mode 100644 index 468b63caba..0000000000 --- a/OpenRA.Renderer.Null/NullShader.cs +++ /dev/null @@ -1,23 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see LICENSE. - */ -#endregion - -using System; -using OpenRA.FileFormats.Graphics; - -namespace OpenRA.Renderer.Null -{ - public class NullShader : IShader - { - public void SetValue(string name, float x, float y) { } - public void SetValue(string param, ITexture texture) { } - public void Commit() { } - public void Render(Action a) { } - } -} diff --git a/OpenRA.Renderer.Null/NullTexture.cs b/OpenRA.Renderer.Null/NullTexture.cs deleted file mode 100644 index e22907a1d6..0000000000 --- a/OpenRA.Renderer.Null/NullTexture.cs +++ /dev/null @@ -1,22 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see LICENSE. - */ -#endregion - -using System.Drawing; -using OpenRA.FileFormats.Graphics; - -namespace OpenRA.Renderer.Null -{ - public class NullTexture : ITexture - { - public void SetData(Bitmap bitmap) { } - public void SetData(uint[,] colors) { } - public void SetData(byte[] colors, int width, int height) { } - } -} diff --git a/OpenRA.Renderer.Null/NullVertexBuffer.cs b/OpenRA.Renderer.Null/NullVertexBuffer.cs deleted file mode 100644 index f6f0bd555c..0000000000 --- a/OpenRA.Renderer.Null/NullVertexBuffer.cs +++ /dev/null @@ -1,20 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see LICENSE. - */ -#endregion - -using OpenRA.FileFormats.Graphics; - -namespace OpenRA.Renderer.Null -{ - class NullVertexBuffer : IVertexBuffer - { - public void Bind() { } - public void SetData(T[] vertices, int length) { } - } -} diff --git a/OpenRA.Renderer.Null/OpenRA.Renderer.Null.csproj b/OpenRA.Renderer.Null/OpenRA.Renderer.Null.csproj index c06193fb66..7861732310 100644 --- a/OpenRA.Renderer.Null/OpenRA.Renderer.Null.csproj +++ b/OpenRA.Renderer.Null/OpenRA.Renderer.Null.csproj @@ -48,10 +48,6 @@ - - - -