Skip to content

Commit

Permalink
Merge pull request #5682 from peppy/renderer-config-fallback
Browse files Browse the repository at this point in the history
Allow renderer choice to be stored in user configuration (and add automatic fallbacks)
  • Loading branch information
smoogipoo committed Mar 21, 2023
2 parents 1ff6694 + 0fffc81 commit 2ba7466
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 59 deletions.
43 changes: 43 additions & 0 deletions osu.Framework.Tests/Visual/Platform/TestSceneRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.

using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Platform;

namespace osu.Framework.Tests.Visual.Platform
{
[Ignore("This test cannot be run in headless mode (a renderer is required).")]
public partial class TestSceneRenderer : FrameworkTestScene
{
[Resolved]
private GameHost host { get; set; } = null!;

[Resolved]
private FrameworkConfigManager config { get; set; } = null!;

[SetUp]
public void SetUp() => Schedule(() =>
{
Add(new SpriteText
{
Text = $"Renderer: {host.ResolvedRenderer} ({host.Renderer.GetType().Name} / {host.Window.GraphicsSurface.Type})",
Font = FrameworkFont.Regular.With(size: 24),
});
Add(new BasicDropdown<RendererType>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Items = host.GetPreferredRenderersForCurrentPlatform().OrderBy(t => t),
Current = config.GetBindable<RendererType>(FrameworkSetting.Renderer),
Width = 200f,
});
});
}
}
2 changes: 1 addition & 1 deletion osu.Framework.iOS/IOSGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public IOSGameHost(IOSGameView gameView)
this.gameView = gameView;
}

protected override IRenderer CreateRenderer() => new IOSGLRenderer(gameView);
protected override IRenderer CreateGLRenderer() => new IOSGLRenderer(gameView);

protected override void SetupForRun()
{
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Configuration/FrameworkConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected override void InitialiseDefaults()
SetDefault(FrameworkSetting.SizeFullscreen, new Size(9999, 9999), new Size(320, 240));
SetDefault(FrameworkSetting.FrameSync, FrameSync.Limit2x);
SetDefault(FrameworkSetting.WindowMode, WindowMode.Windowed);
SetDefault(FrameworkSetting.Renderer, RendererType.Automatic);
SetDefault(FrameworkSetting.ShowUnicode, false);
SetDefault(FrameworkSetting.Locale, string.Empty);

Expand Down Expand Up @@ -90,6 +91,7 @@ public enum FrameworkSetting

SizeFullscreen,

Renderer,
WindowMode,
ConfineMouseMode,
FrameSync,
Expand Down
28 changes: 28 additions & 0 deletions osu.Framework/Configuration/RendererType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.

using System.ComponentModel;

namespace osu.Framework.Configuration
{
public enum RendererType
{
[Description("Automatic")]
Automatic,

[Description("Metal")]
Metal,

[Description("Vulkan")]
Vulkan,

[Description("Direct3D 11")]
Direct3D11,

[Description("OpenGL")]
OpenGL,

[Description("OpenGL (Legacy)")]
OpenGLLegacy,
}
}

0 comments on commit 2ba7466

Please sign in to comment.