Use env variables for renderer/surface

This commit is contained in:
Dan Balasescu
2023-03-06 19:29:27 +09:00
parent a5bf178b38
commit 10b7eecf50
5 changed files with 20 additions and 26 deletions

View File

@@ -1,11 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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());

View File

@@ -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<ExecutionMode>(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<GraphicsSurfaceType>(Environment.GetEnvironmentVariable("OSU_GRAPHICS_SURFACE"), true, out var surface) ? surface : null;
PREFERRED_GRAPHICS_RENDERER = Environment.GetEnvironmentVariable("OSU_GRAPHICS_RENDERER")?.ToLowerInvariant();
}
}
}

View File

@@ -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.
/// </remarks>
public bool BypassCompositor { get; set; } = true;
/// <summary>
/// The preferred graphics surface.
/// </summary>
public GraphicsSurfaceType? PreferredGraphicsSurface { get; set; }
}
}

View File

@@ -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);

View File

@@ -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()
{