diff --git a/osu.Framework.Tests/Program.cs b/osu.Framework.Tests/Program.cs index 7b7b2c33c..8fb25e4db 100644 --- a/osu.Framework.Tests/Program.cs +++ b/osu.Framework.Tests/Program.cs @@ -1,11 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Linq; -using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Platform; namespace osu.Framework.Tests @@ -17,15 +14,8 @@ namespace osu.Framework.Tests { bool benchmark = args.Contains(@"--benchmark"); bool portable = args.Contains(@"--portable"); - GraphicsSurfaceType? surfaceType = Enum.TryParse(args.GetNext("--surface"), true, out GraphicsSurfaceType type) ? type : null; - HostOptions options = new HostOptions - { - PortableInstallation = portable, - PreferredGraphicsSurface = surfaceType - }; - - using (GameHost host = Host.GetSuitableDesktopHost(@"visual-tests", options)) + using (GameHost host = Host.GetSuitableDesktopHost(@"visual-tests", new HostOptions { PortableInstallation = portable })) { if (benchmark) host.Run(new AutomatedVisualTestGame()); diff --git a/osu.Framework/FrameworkEnvironment.cs b/osu.Framework/FrameworkEnvironment.cs index e94a38819..4eed4d717 100644 --- a/osu.Framework/FrameworkEnvironment.cs +++ b/osu.Framework/FrameworkEnvironment.cs @@ -11,12 +11,16 @@ namespace osu.Framework public static readonly ExecutionMode? STARTUP_EXECUTION_MODE; public static readonly bool NO_TEST_TIMEOUT; public static readonly bool FORCE_TEST_GC; + public static readonly GraphicsSurfaceType? PREFERRED_GRAPHICS_SURFACE; + public static readonly string? PREFERRED_GRAPHICS_RENDERER; static FrameworkEnvironment() { STARTUP_EXECUTION_MODE = Enum.TryParse(Environment.GetEnvironmentVariable("OSU_EXECUTION_MODE"), true, out var mode) ? mode : null; NO_TEST_TIMEOUT = Environment.GetEnvironmentVariable("OSU_TESTS_NO_TIMEOUT") == "1"; FORCE_TEST_GC = Environment.GetEnvironmentVariable("OSU_TESTS_FORCED_GC") == "1"; + PREFERRED_GRAPHICS_SURFACE = Enum.TryParse(Environment.GetEnvironmentVariable("OSU_GRAPHICS_SURFACE"), true, out var surface) ? surface : null; + PREFERRED_GRAPHICS_RENDERER = Environment.GetEnvironmentVariable("OSU_GRAPHICS_RENDERER")?.ToLowerInvariant(); } } } diff --git a/osu.Framework/HostOptions.cs b/osu.Framework/HostOptions.cs index fad01010a..b31824f0a 100644 --- a/osu.Framework/HostOptions.cs +++ b/osu.Framework/HostOptions.cs @@ -30,10 +30,5 @@ namespace osu.Framework /// If the SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR environment variable is set, this property will have no effect. /// public bool BypassCompositor { get; set; } = true; - - /// - /// The preferred graphics surface. - /// - public GraphicsSurfaceType? PreferredGraphicsSurface { get; set; } } } diff --git a/osu.Framework/Platform/GameHost.cs b/osu.Framework/Platform/GameHost.cs index 44f5429d3..4c4364460 100644 --- a/osu.Framework/Platform/GameHost.cs +++ b/osu.Framework/Platform/GameHost.cs @@ -328,16 +328,15 @@ namespace osu.Framework.Platform protected virtual IRenderer CreateRenderer() { - switch (Options.PreferredGraphicsSurface) + switch (FrameworkEnvironment.PREFERRED_GRAPHICS_RENDERER) { - default: - case GraphicsSurfaceType.OpenGL: - return new GLRenderer(); - - case GraphicsSurfaceType.Metal: - case GraphicsSurfaceType.Vulkan: - case GraphicsSurfaceType.Direct3D11: + case "veldrid": return new VeldridRenderer(); + + default: + case "gl": + case "opengl": + return new GLRenderer(); } } @@ -718,7 +717,7 @@ namespace osu.Framework.Platform SetupForRun(); - GraphicsSurfaceType surfaceType = Options.PreferredGraphicsSurface ?? GraphicsSurfaceType.OpenGL; + GraphicsSurfaceType surfaceType = FrameworkEnvironment.PREFERRED_GRAPHICS_SURFACE ?? GraphicsSurfaceType.OpenGL; Logger.Log("Using renderer: " + Renderer.GetType().ReadableName()); Logger.Log("Using graphics surface: " + surfaceType); diff --git a/osu.Framework/Platform/Windows/WindowsGameHost.cs b/osu.Framework/Platform/Windows/WindowsGameHost.cs index 2b1e3b80a..ce86ace31 100644 --- a/osu.Framework/Platform/Windows/WindowsGameHost.cs +++ b/osu.Framework/Platform/Windows/WindowsGameHost.cs @@ -65,7 +65,13 @@ namespace osu.Framework.Platform.Windows .Concat(new InputHandler[] { new WindowsMouseHandler() }); } - protected override IRenderer CreateRenderer() => Options.PreferredGraphicsSurface == null ? new WindowsGLRenderer(this) : base.CreateRenderer(); + protected override IRenderer CreateRenderer() + { + if (FrameworkEnvironment.PREFERRED_GRAPHICS_RENDERER != null || FrameworkEnvironment.PREFERRED_GRAPHICS_SURFACE != null) + return base.CreateRenderer(); + + return new WindowsGLRenderer(this); + } protected override void SetupForRun() {