-
-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Monitor video modes and gamma correction (#114)
* Start implementing monitor video modes * Move MonitorPlayground to dotnet 3.0 Rider's built-in dotnet SDK only supports 3.0 right now * Add Gamma * Add GetAllVideoModes * Review changes
- Loading branch information
Showing
4 changed files
with
137 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 47 additions & 17 deletions
64
src/Windowing/Silk.NET.Windowing.Common/Interfaces/IMonitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,47 @@ | ||
// This file is part of Silk.NET. | ||
// | ||
// You may modify and distribute Silk.NET under the terms | ||
// of the MIT license. See the LICENSE file for details. | ||
|
||
using System.Drawing; | ||
|
||
namespace Silk.NET.Windowing.Common | ||
{ | ||
public interface IMonitor : IWindowHost | ||
{ | ||
string Name { get; } | ||
int Index { get; } | ||
Rectangle Bounds { get; } | ||
VideoMode VideoMode { get; } | ||
} | ||
} | ||
// This file is part of Silk.NET. | ||
// | ||
// You may modify and distribute Silk.NET under the terms | ||
// of the MIT license. See the LICENSE file for details. | ||
|
||
using System.Collections.Generic; | ||
using System.Drawing; | ||
|
||
namespace Silk.NET.Windowing.Common | ||
{ | ||
/// <summary> | ||
/// An interface representing a monitor. | ||
/// </summary> | ||
public interface IMonitor : IWindowHost | ||
{ | ||
/// <summary> | ||
/// The name of this monitor. | ||
/// </summary> | ||
string Name { get; } | ||
|
||
/// <summary> | ||
/// The index of this monitor. | ||
/// </summary> | ||
int Index { get; } | ||
|
||
/// <summary> | ||
/// The bounds of this monitor. | ||
/// </summary> | ||
Rectangle Bounds { get; } | ||
|
||
/// <summary> | ||
/// The current video mode of this monitor. | ||
/// </summary> | ||
VideoMode VideoMode { get; } | ||
|
||
/// <summary> | ||
/// This monitor's gamma correction. | ||
/// </summary> | ||
float Gamma { get; set; } | ||
|
||
/// <summary> | ||
/// Get all video modes that this monitor supports. | ||
/// </summary> | ||
/// <returns>An array of all video modes.</returns> | ||
IEnumerable<VideoMode> GetAllVideoModes(); | ||
} | ||
} |
144 changes: 85 additions & 59 deletions
144
src/Windowing/Silk.NET.Windowing.Desktop/GlfwMonitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,85 @@ | ||
// This file is part of Silk.NET. | ||
// | ||
// You may modify and distribute Silk.NET under the terms | ||
// of the MIT license. See the LICENSE file for details. | ||
|
||
using System; | ||
using System.Drawing; | ||
using Silk.NET.GLFW; | ||
using Silk.NET.Windowing.Common; | ||
using VideoMode = Silk.NET.Windowing.Common.VideoMode; | ||
|
||
namespace Silk.NET.Windowing.Desktop | ||
{ | ||
internal unsafe class GlfwMonitor : IMonitor | ||
{ | ||
public Monitor* Handle { get; } | ||
|
||
public GlfwMonitor(Monitor* monitor, int index) | ||
{ | ||
Handle = monitor; | ||
Index = index; | ||
} | ||
|
||
public IWindow CreateWindow(WindowOptions opts) | ||
{ | ||
if (opts.WindowState == WindowState.Fullscreen) | ||
{ | ||
return new GlfwWindow(opts, null, this); | ||
} | ||
|
||
opts.Position = new Point(opts.Position.X + Bounds.X, opts.Position.Y + Bounds.Y); | ||
return new GlfwWindow(opts, null, null); | ||
} | ||
|
||
public string Name => GlfwProvider.GLFW.Value.GetMonitorName(Handle); | ||
public int Index { get; } | ||
|
||
public Rectangle Bounds | ||
{ | ||
get | ||
{ | ||
GlfwProvider.GLFW.Value.GetMonitorWorkarea(Handle, out var x, out var y, out var w, out var h); | ||
return new Rectangle(x, y, w, h); | ||
} | ||
} | ||
|
||
public VideoMode VideoMode | ||
{ | ||
get | ||
{ | ||
var videoMode = GlfwProvider.GLFW.Value.GetVideoMode(Handle); | ||
return new VideoMode( | ||
new Size(videoMode->Width, videoMode->Height), | ||
videoMode->RefreshRate | ||
); | ||
} | ||
} | ||
} | ||
} | ||
// This file is part of Silk.NET. | ||
// | ||
// You may modify and distribute Silk.NET under the terms | ||
// of the MIT license. See the LICENSE file for details. | ||
|
||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using Silk.NET.GLFW; | ||
using Silk.NET.Windowing.Common; | ||
using VideoMode = Silk.NET.Windowing.Common.VideoMode; | ||
|
||
namespace Silk.NET.Windowing.Desktop | ||
{ | ||
internal unsafe class GlfwMonitor : IMonitor | ||
{ | ||
private float _gamma = 1.0f; | ||
|
||
public Monitor* Handle { get; } | ||
|
||
public GlfwMonitor(Monitor* monitor, int index) | ||
{ | ||
Handle = monitor; | ||
Index = index; | ||
} | ||
|
||
public IWindow CreateWindow(WindowOptions opts) | ||
{ | ||
if (opts.WindowState == WindowState.Fullscreen) | ||
{ | ||
return new GlfwWindow(opts, null, this); | ||
} | ||
|
||
opts.Position = new Point(opts.Position.X + Bounds.X, opts.Position.Y + Bounds.Y); | ||
return new GlfwWindow(opts, null, null); | ||
} | ||
|
||
public string Name => GlfwProvider.GLFW.Value.GetMonitorName(Handle); | ||
public int Index { get; } | ||
|
||
public Rectangle Bounds | ||
{ | ||
get | ||
{ | ||
GlfwProvider.GLFW.Value.GetMonitorWorkarea(Handle, out var x, out var y, out var w, out var h); | ||
return new Rectangle(x, y, w, h); | ||
} | ||
} | ||
|
||
public VideoMode VideoMode | ||
{ | ||
get | ||
{ | ||
var videoMode = GlfwProvider.GLFW.Value.GetVideoMode(Handle); | ||
return new VideoMode( | ||
new Size(videoMode->Width, videoMode->Height), | ||
videoMode->RefreshRate | ||
); | ||
} | ||
} | ||
|
||
public float Gamma | ||
{ | ||
get => _gamma; | ||
set | ||
{ | ||
_gamma = value; | ||
GlfwProvider.GLFW.Value.SetGamma(Handle, value); | ||
} | ||
} | ||
|
||
public IEnumerable<VideoMode> GetAllVideoModes() | ||
{ | ||
var rawVideoModes = GlfwProvider.GLFW.Value.GetVideoModes(Handle, out var count); | ||
|
||
var videoModes = new List<VideoMode>(); | ||
|
||
for (var i = 0; i < count; i++) | ||
{ | ||
videoModes.Add(new VideoMode(new Size(rawVideoModes[i].Width, rawVideoModes[i].Height), rawVideoModes[i].RefreshRate)); | ||
} | ||
|
||
return videoModes; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters