fixed #989: don't do renderer setup in a reflected call.
This commit is contained in:
@@ -21,12 +21,17 @@ namespace OpenRA.FileFormats.Graphics
|
||||
|
||||
public RendererAttribute( Type graphicsDeviceType )
|
||||
{
|
||||
if( !typeof( IGraphicsDevice ).IsAssignableFrom( graphicsDeviceType ) )
|
||||
if( !typeof( IDeviceFactory ).IsAssignableFrom( graphicsDeviceType ) )
|
||||
throw new InvalidOperationException( "Incorrect type in RendererAttribute" );
|
||||
Type = graphicsDeviceType;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IDeviceFactory
|
||||
{
|
||||
IGraphicsDevice Create( Size size, WindowMode windowMode, bool vsync );
|
||||
}
|
||||
|
||||
public interface IGraphicsDevice
|
||||
{
|
||||
IVertexBuffer<Vertex> CreateVertexBuffer( int length );
|
||||
|
||||
@@ -142,11 +142,11 @@ namespace OpenRA.Graphics
|
||||
|
||||
static IGraphicsDevice CreateDevice( Assembly rendererDll, int width, int height, WindowMode window, bool vsync )
|
||||
{
|
||||
var argTypes = new Type[] { typeof( int ), typeof( int ), typeof( WindowMode ), typeof( bool ) };
|
||||
var argValues = new object[] { width, height, window, vsync };
|
||||
|
||||
foreach( RendererAttribute r in rendererDll.GetCustomAttributes( typeof( RendererAttribute ), false ) )
|
||||
return (IGraphicsDevice)r.Type.GetConstructor( argTypes ).Invoke( argValues );
|
||||
{
|
||||
var factory = (IDeviceFactory) r.Type.GetConstructor( Type.EmptyTypes ).Invoke( null );
|
||||
return factory.Create( new Size( width, height ), window, vsync );
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Renderer DLL is missing RendererAttribute to tell us what type to use!");
|
||||
}
|
||||
|
||||
@@ -16,10 +16,18 @@ using Tao.Cg;
|
||||
using Tao.OpenGl;
|
||||
using Tao.Sdl;
|
||||
|
||||
[assembly: Renderer(typeof(OpenRA.Renderer.Cg.GraphicsDevice))]
|
||||
[assembly: Renderer(typeof(OpenRA.Renderer.Cg.DeviceFactory))]
|
||||
|
||||
namespace OpenRA.Renderer.Cg
|
||||
{
|
||||
public class DeviceFactory : IDeviceFactory
|
||||
{
|
||||
public IGraphicsDevice Create(Size size, WindowMode windowMode, bool vsync)
|
||||
{
|
||||
return new GraphicsDevice( size, windowMode, vsync );
|
||||
}
|
||||
}
|
||||
|
||||
public class GraphicsDevice : IGraphicsDevice
|
||||
{
|
||||
Size windowSize;
|
||||
@@ -75,7 +83,7 @@ namespace OpenRA.Renderer.Cg
|
||||
throw new InvalidOperationException("CG Error. See graphics.log for details");
|
||||
};
|
||||
|
||||
public GraphicsDevice( int width, int height, WindowMode window, bool vsync )
|
||||
public GraphicsDevice( Size size, WindowMode window, bool vsync )
|
||||
{
|
||||
Console.WriteLine("Using Cg renderer");
|
||||
Sdl.SDL_Init( Sdl.SDL_INIT_NOPARACHUTE | Sdl.SDL_INIT_VIDEO );
|
||||
@@ -102,7 +110,7 @@ namespace OpenRA.Renderer.Cg
|
||||
break;
|
||||
}
|
||||
|
||||
surf = Sdl.SDL_SetVideoMode( width, height, 0, Sdl.SDL_OPENGL | windowFlags );
|
||||
surf = Sdl.SDL_SetVideoMode( size.Width, size.Height, 0, Sdl.SDL_OPENGL | windowFlags );
|
||||
|
||||
Sdl.SDL_WM_SetCaption( "OpenRA", "OpenRA" );
|
||||
Sdl.SDL_ShowCursor( 0 );
|
||||
@@ -111,7 +119,7 @@ namespace OpenRA.Renderer.Cg
|
||||
|
||||
CheckGlError();
|
||||
|
||||
windowSize = new Size( width, height );
|
||||
windowSize = size;
|
||||
|
||||
cgContext = Tao.Cg.Cg.cgCreateContext();
|
||||
|
||||
|
||||
@@ -11,16 +11,23 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats.Graphics;
|
||||
using Tao.Cg;
|
||||
using Tao.OpenGl;
|
||||
using Tao.Sdl;
|
||||
using System.Linq;
|
||||
|
||||
[assembly: Renderer(typeof(OpenRA.Renderer.Glsl.GraphicsDevice))]
|
||||
[assembly: Renderer(typeof(OpenRA.Renderer.Glsl.DeviceFactory))]
|
||||
|
||||
namespace OpenRA.Renderer.Glsl
|
||||
{
|
||||
public class DeviceFactory : IDeviceFactory
|
||||
{
|
||||
public IGraphicsDevice Create(Size size, WindowMode windowMode, bool vsync)
|
||||
{
|
||||
return new GraphicsDevice( size, windowMode, vsync );
|
||||
}
|
||||
}
|
||||
|
||||
public class GraphicsDevice : IGraphicsDevice
|
||||
{
|
||||
Size windowSize;
|
||||
@@ -65,7 +72,7 @@ namespace OpenRA.Renderer.Glsl
|
||||
Log.Write("graphics", Gl.glGetString(Gl.GL_EXTENSIONS));
|
||||
}
|
||||
|
||||
public GraphicsDevice( int width, int height, WindowMode window, bool vsync )
|
||||
public GraphicsDevice( Size size, WindowMode window, bool vsync )
|
||||
{
|
||||
Console.WriteLine("Using Gl renderer");
|
||||
Sdl.SDL_Init( Sdl.SDL_INIT_NOPARACHUTE | Sdl.SDL_INIT_VIDEO );
|
||||
@@ -89,7 +96,7 @@ namespace OpenRA.Renderer.Glsl
|
||||
break;
|
||||
}
|
||||
|
||||
surf = Sdl.SDL_SetVideoMode( width, height, 0, Sdl.SDL_OPENGL | windowFlags );
|
||||
surf = Sdl.SDL_SetVideoMode( size.Width, size.Height, 0, Sdl.SDL_OPENGL | windowFlags );
|
||||
|
||||
Sdl.SDL_WM_SetCaption( "OpenRA", "OpenRA" );
|
||||
Sdl.SDL_ShowCursor( 0 );
|
||||
@@ -115,7 +122,7 @@ namespace OpenRA.Renderer.Glsl
|
||||
throw new InvalidProgramException("Unsupported GPU. See graphics.log for details.");
|
||||
}
|
||||
|
||||
windowSize = new Size( width, height );
|
||||
windowSize = size;
|
||||
|
||||
Gl.glEnableClientState( Gl.GL_VERTEX_ARRAY );
|
||||
CheckGlError();
|
||||
|
||||
@@ -10,22 +10,29 @@
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using OpenRA.FileFormats.Graphics;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
[assembly: Renderer(typeof(OpenRA.Renderer.Null.NullGraphicsDevice))]
|
||||
[assembly: Renderer(typeof(OpenRA.Renderer.Null.DeviceFactory))]
|
||||
|
||||
namespace OpenRA.Renderer.Null
|
||||
{
|
||||
public class DeviceFactory : IDeviceFactory
|
||||
{
|
||||
public IGraphicsDevice Create(Size size, WindowMode windowMode, bool vsync)
|
||||
{
|
||||
return new NullGraphicsDevice( size, windowMode, vsync );
|
||||
}
|
||||
}
|
||||
|
||||
public class NullGraphicsDevice : IGraphicsDevice
|
||||
{
|
||||
public Size WindowSize { get; internal set; }
|
||||
|
||||
public NullGraphicsDevice(int width, int height, WindowMode window, bool vsync)
|
||||
public NullGraphicsDevice(Size size, WindowMode window, bool vsync)
|
||||
{
|
||||
Console.WriteLine("Using Null renderer");
|
||||
WindowSize = new Size(width, height);
|
||||
WindowSize = size;
|
||||
}
|
||||
|
||||
public void EnableScissor(int left, int top, int width, int height) { }
|
||||
|
||||
Reference in New Issue
Block a user