mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Allow enumeration of monitor video modes.
Basically I kept dumping debugging code for this into Clyde startup to test multi-monitor stuff with GLFW so I guess I'm making it official now.
This commit is contained in:
@@ -25,6 +25,34 @@ namespace Robust.Client.Console.Commands
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class MonitorInfoCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "monitorinfo";
|
||||
public string Description => "";
|
||||
public string Help => "Usage: monitorinfo <id>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length < 1)
|
||||
{
|
||||
shell.WriteError("Expected one argument.");
|
||||
return;
|
||||
}
|
||||
|
||||
var clyde = IoCManager.Resolve<IClyde>();
|
||||
var monitor = clyde.EnumerateMonitors().Single(c => c.Id == int.Parse(args[0]));
|
||||
|
||||
shell.WriteLine($"{monitor.Id}: {monitor.Name}");
|
||||
shell.WriteLine($"Video modes:");
|
||||
|
||||
foreach (var mode in monitor.VideoModes)
|
||||
{
|
||||
shell.WriteLine($" {mode.Width}x{mode.Height} {mode.RefreshRate} Hz {mode.RedBits}/{mode.GreenBits}/{mode.BlueBits}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class SetMonitorCommand : IConsoleCommand
|
||||
{
|
||||
|
||||
@@ -470,18 +470,20 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
private sealed class MonitorHandle : IClydeMonitor
|
||||
{
|
||||
public MonitorHandle(int id, string name, Vector2i size, int refreshRate)
|
||||
public MonitorHandle(int id, string name, Vector2i size, int refreshRate, VideoMode[] videoModes)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Size = size;
|
||||
RefreshRate = refreshRate;
|
||||
VideoModes = videoModes;
|
||||
}
|
||||
|
||||
public int Id { get; }
|
||||
public string Name { get; }
|
||||
public Vector2i Size { get; }
|
||||
public int RefreshRate { get; }
|
||||
public IEnumerable<VideoMode> VideoModes { get; }
|
||||
}
|
||||
|
||||
private abstract class MonitorReg
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using OpenToolkit.GraphicsLibraryFramework;
|
||||
using Robust.Shared.Utility;
|
||||
using GlfwVideoMode = OpenToolkit.GraphicsLibraryFramework.VideoMode;
|
||||
|
||||
namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
@@ -39,6 +41,7 @@ namespace Robust.Client.Graphics.Clyde
|
||||
ProcessEvents();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private void WinThreadSetupMonitor(Monitor* monitor)
|
||||
{
|
||||
var id = _nextMonitorId++;
|
||||
@@ -48,12 +51,31 @@ namespace Robust.Client.Graphics.Clyde
|
||||
|
||||
var name = GLFW.GetMonitorName(monitor);
|
||||
var videoMode = GLFW.GetVideoMode(monitor);
|
||||
var modesPtr = GLFW.GetVideoModesRaw(monitor, out var modeCount);
|
||||
var modes = new VideoMode[modeCount];
|
||||
for (var i = 0; i < modes.Length; i++)
|
||||
{
|
||||
modes[i] = ConvertVideoMode(modesPtr[i]);
|
||||
}
|
||||
|
||||
GLFW.SetMonitorUserPointer(monitor, (void*) id);
|
||||
|
||||
_winThreadMonitors.Add(id, new WinThreadMonitorReg {Ptr = monitor});
|
||||
|
||||
SendEvent(new EventMonitorSetup(id, name, *videoMode));
|
||||
SendEvent(new EventMonitorSetup(id, name, ConvertVideoMode(*videoMode), modes));
|
||||
}
|
||||
|
||||
private static VideoMode ConvertVideoMode(in GlfwVideoMode mode)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Width = (ushort) mode.Width,
|
||||
Height = (ushort) mode.Height,
|
||||
RedBits = (byte) mode.RedBits,
|
||||
RefreshRate = (ushort) mode.RefreshRate,
|
||||
GreenBits = (byte) mode.GreenBits,
|
||||
BlueBits = (byte) mode.BlueBits,
|
||||
};
|
||||
}
|
||||
|
||||
private void ProcessSetupMonitor(EventMonitorSetup ev)
|
||||
@@ -61,8 +83,9 @@ namespace Robust.Client.Graphics.Clyde
|
||||
var impl = new MonitorHandle(
|
||||
ev.Id,
|
||||
ev.Name,
|
||||
(ev.Mode.Width, ev.Mode.Height),
|
||||
ev.Mode.RefreshRate);
|
||||
(ev.CurrentMode.Width, ev.CurrentMode.Height),
|
||||
ev.CurrentMode.RefreshRate,
|
||||
ev.AllModes);
|
||||
|
||||
_clyde._monitorHandles.Add(impl);
|
||||
_monitors[ev.Id] = new GlfwMonitorReg
|
||||
|
||||
@@ -210,7 +210,8 @@ namespace Robust.Client.Graphics.Clyde
|
||||
(
|
||||
int Id,
|
||||
string Name,
|
||||
VideoMode Mode
|
||||
VideoMode CurrentMode,
|
||||
VideoMode[] AllModes
|
||||
) : EventBase;
|
||||
|
||||
private record EventMonitorDestroy
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Robust.Shared.Maths;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Client.Graphics
|
||||
{
|
||||
@@ -14,5 +15,7 @@ namespace Robust.Client.Graphics
|
||||
string Name { get; }
|
||||
Vector2i Size { get; }
|
||||
int RefreshRate { get; }
|
||||
|
||||
IEnumerable<VideoMode> VideoModes { get; }
|
||||
}
|
||||
}
|
||||
|
||||
12
Robust.Client/Graphics/VideoMode.cs
Normal file
12
Robust.Client/Graphics/VideoMode.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Robust.Client.Graphics
|
||||
{
|
||||
public struct VideoMode
|
||||
{
|
||||
public ushort Width;
|
||||
public ushort Height;
|
||||
public ushort RefreshRate;
|
||||
public byte RedBits;
|
||||
public byte BlueBits;
|
||||
public byte GreenBits;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user