Skip to content

Commit 6751f78

Browse files
authored
Merge pull request #22924 from peppy/add-renderer-selection
Add ability to select renderer
2 parents 8ad62c2 + 292486c commit 6751f78

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
lines changed

osu.Game/Localisation/GraphicsSettingsStrings.cs

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public static class GraphicsSettingsStrings
1919
/// </summary>
2020
public static LocalisableString RendererHeader => new TranslatableString(getKey(@"renderer_header"), @"Renderer");
2121

22+
/// <summary>
23+
/// "Renderer"
24+
/// </summary>
25+
public static LocalisableString Renderer => new TranslatableString(getKey(@"renderer"), @"Renderer");
26+
2227
/// <summary>
2328
/// "Frame limiter"
2429
/// </summary>
@@ -144,6 +149,12 @@ public static class GraphicsSettingsStrings
144149
/// </summary>
145150
public static LocalisableString Png => new TranslatableString(getKey(@"png_lossless"), @"PNG (lossless)");
146151

152+
/// <summary>
153+
/// "In order to change the renderer, the game will close. Please open it again."
154+
/// </summary>
155+
public static LocalisableString ChangeRendererConfirmation =>
156+
new TranslatableString(getKey(@"change_renderer_configuration"), @"In order to change the renderer, the game will close. Please open it again.");
157+
147158
private static string getKey(string key) => $"{prefix}:{key}";
148159
}
149160
}

osu.Game/Overlays/Settings/Sections/Graphics/RendererSettings.cs

+69-4
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4-
#nullable disable
5-
4+
using System.Linq;
5+
using osu.Framework;
66
using osu.Framework.Allocation;
77
using osu.Framework.Configuration;
8+
using osu.Framework.Extensions;
89
using osu.Framework.Graphics;
910
using osu.Framework.Localisation;
1011
using osu.Framework.Platform;
1112
using osu.Game.Configuration;
13+
using osu.Game.Graphics.UserInterface;
1214
using osu.Game.Localisation;
15+
using osu.Game.Overlays.Dialog;
1316

1417
namespace osu.Game.Overlays.Settings.Sections.Graphics
1518
{
1619
public partial class RendererSettings : SettingsSubsection
1720
{
1821
protected override LocalisableString Header => GraphicsSettingsStrings.RendererHeader;
1922

23+
private bool automaticRendererInUse;
24+
2025
[BackgroundDependencyLoader]
21-
private void load(FrameworkConfigManager config, OsuConfigManager osuConfig)
26+
private void load(FrameworkConfigManager config, OsuConfigManager osuConfig, IDialogOverlay? dialogOverlay, OsuGame? game, GameHost host)
2227
{
23-
// NOTE: Compatability mode omitted
28+
var renderer = config.GetBindable<RendererType>(FrameworkSetting.Renderer);
29+
automaticRendererInUse = renderer.Value == RendererType.Automatic;
30+
31+
SettingsEnumDropdown<RendererType> rendererDropdown;
32+
2433
Children = new Drawable[]
2534
{
35+
rendererDropdown = new RendererSettingsDropdown
36+
{
37+
LabelText = GraphicsSettingsStrings.Renderer,
38+
Current = renderer,
39+
Items = host.GetPreferredRenderersForCurrentPlatform().OrderBy(t => t),
40+
Keywords = new[] { @"compatibility", @"directx" },
41+
},
2642
// TODO: this needs to be a custom dropdown at some point
2743
new SettingsEnumDropdown<FrameSync>
2844
{
@@ -41,6 +57,55 @@ private void load(FrameworkConfigManager config, OsuConfigManager osuConfig)
4157
Current = osuConfig.GetBindable<bool>(OsuSetting.ShowFpsDisplay)
4258
},
4359
};
60+
61+
renderer.BindValueChanged(r =>
62+
{
63+
if (r.NewValue == host.ResolvedRenderer)
64+
return;
65+
66+
// Need to check startup renderer for the "automatic" case, as ResolvedRenderer above will track the final resolved renderer instead.
67+
if (r.NewValue == RendererType.Automatic && automaticRendererInUse)
68+
return;
69+
70+
dialogOverlay?.Push(new ConfirmDialog(GraphicsSettingsStrings.ChangeRendererConfirmation, () => game?.AttemptExit(), () =>
71+
{
72+
renderer.Value = automaticRendererInUse ? RendererType.Automatic : host.ResolvedRenderer;
73+
}));
74+
});
75+
76+
// TODO: remove this once we support SDL+android.
77+
if (RuntimeInfo.OS == RuntimeInfo.Platform.Android)
78+
{
79+
rendererDropdown.Items = new[] { RendererType.Automatic, RendererType.OpenGLLegacy };
80+
rendererDropdown.SetNoticeText("New renderer support for android is coming soon!", true);
81+
}
82+
}
83+
84+
private partial class RendererSettingsDropdown : SettingsEnumDropdown<RendererType>
85+
{
86+
protected override OsuDropdown<RendererType> CreateDropdown() => new RendererDropdown();
87+
88+
protected partial class RendererDropdown : DropdownControl
89+
{
90+
private RendererType hostResolvedRenderer;
91+
private bool automaticRendererInUse;
92+
93+
[BackgroundDependencyLoader]
94+
private void load(FrameworkConfigManager config, GameHost host)
95+
{
96+
var renderer = config.GetBindable<RendererType>(FrameworkSetting.Renderer);
97+
automaticRendererInUse = renderer.Value == RendererType.Automatic;
98+
hostResolvedRenderer = host.ResolvedRenderer;
99+
}
100+
101+
protected override LocalisableString GenerateItemText(RendererType item)
102+
{
103+
if (item == RendererType.Automatic && automaticRendererInUse)
104+
return LocalisableString.Interpolate($"{base.GenerateItemText(item)} ({hostResolvedRenderer.GetDescription()})");
105+
106+
return base.GenerateItemText(item);
107+
}
108+
}
44109
}
45110
}
46111
}

0 commit comments

Comments
 (0)