fixed Renderer init (separated device creation from shader load)

This commit is contained in:
Bob
2010-08-21 18:59:05 +12:00
parent 7e67a5bb2d
commit 18914447aa
2 changed files with 45 additions and 36 deletions

View File

@@ -15,6 +15,7 @@ using System.Reflection;
using OpenRA.FileFormats;
using OpenRA.FileFormats.Graphics;
using OpenRA.Support;
using System.Windows.Forms;
namespace OpenRA.Graphics
{
@@ -22,8 +23,6 @@ namespace OpenRA.Graphics
{
internal static int SheetSize;
readonly IGraphicsDevice device;
public IShader SpriteShader { get; private set; } /* note: shared shader params */
public IShader LineShader { get; private set; }
public IShader RgbaSpriteShader { get; private set; }
@@ -38,12 +37,8 @@ namespace OpenRA.Graphics
public readonly SpriteFont RegularFont, BoldFont, TitleFont;
public Size Resolution { get { return device.WindowSize; } }
public Renderer(Size resolution, OpenRA.FileFormats.Graphics.WindowMode windowMode)
public Renderer()
{
device = CreateDevice( Assembly.LoadFile( Path.GetFullPath( "OpenRA.Gl.dll" ) ), resolution.Width, resolution.Height, windowMode, false );
SpriteShader = device.CreateShader(FileSystem.Open("shaders/world-shp.fx"));
LineShader = device.CreateShader(FileSystem.Open("shaders/line.fx"));
RgbaSpriteShader = device.CreateShader(FileSystem.Open("shaders/chrome-rgba.fx"));
@@ -59,16 +54,6 @@ namespace OpenRA.Graphics
TitleFont = new SpriteFont("titles.ttf", 48);
}
IGraphicsDevice CreateDevice( Assembly rendererDll, int width, int height, WindowMode window, bool vsync )
{
foreach( RendererAttribute r in rendererDll.GetCustomAttributes( typeof( RendererAttribute ), false ) )
{
return (IGraphicsDevice)r.Type.GetConstructor( new Type[] { typeof( int ), typeof( int ), typeof( WindowMode ), typeof( bool ) } )
.Invoke( new object[] { width, height, window, vsync } );
}
throw new NotImplementedException();
}
public IGraphicsDevice Device { get { return device; } }
public void BeginFrame(float2 r1, float2 r2, float2 scroll)
@@ -127,5 +112,44 @@ namespace OpenRA.Graphics
RgbaSpriteRenderer.Flush();
LineRenderer.Flush();
}
static IGraphicsDevice device;
public static Size Resolution { get { return device.WindowSize; } }
internal static void Initialize( Settings settings, OpenRA.FileFormats.Graphics.WindowMode windowMode )
{
var resolution = GetResolution( settings, windowMode );
device = CreateDevice( Assembly.LoadFile( Path.GetFullPath( "OpenRA.Gl.dll" ) ), resolution.Width, resolution.Height, windowMode, false );
}
static Size GetResolution(Settings settings, WindowMode windowmode)
{
var desktopResolution = Screen.PrimaryScreen.Bounds.Size;
var customSize = (windowmode == WindowMode.Windowed) ? Game.Settings.WindowedSize : Game.Settings.FullscreenSize;
if (customSize.X > 0 && customSize.Y > 0)
{
desktopResolution.Width = customSize.X;
desktopResolution.Height = customSize.Y;
}
return new Size(
desktopResolution.Width,
desktopResolution.Height);
}
static IGraphicsDevice CreateDevice( Assembly rendererDll, int width, int height, WindowMode window, bool vsync )
{
foreach( RendererAttribute r in rendererDll.GetCustomAttributes( typeof( RendererAttribute ), false ) )
{
return (IGraphicsDevice)r.Type.GetConstructor( new Type[] { typeof( int ), typeof( int ), typeof( WindowMode ), typeof( bool ) } )
.Invoke( new object[] { width, height, window, vsync } );
}
throw new NotImplementedException();
}
}
}