Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fd87a4c
Merge remote-tracking branch 'upstream/master'
devvoid Jul 3, 2019
f33881d
Merge remote-tracking branch 'upstream/master'
devvoid Jul 4, 2019
8665500
Add IsRunningSlowlyThreshold
devvoid Jul 5, 2019
95b833e
Remove extra <
devvoid Jul 5, 2019
669b409
Add IsRunningSlowlyThreshold
devvoid Jul 5, 2019
967f33e
Add IsRunningSlowly to the proposal
devvoid Jul 5, 2019
f56c399
Update docs for IsRunningSlowly to match new implementation
devvoid Jul 5, 2019
1fe3e68
Merge remote-tracking branch 'origin/windowing-cleanups' into windowi…
devvoid Jul 5, 2019
cd048ba
Update some documentation text, add newlines for easier reading
devvoid Jul 5, 2019
a369cea
Documentation improvements
devvoid Jul 5, 2019
eb75877
Merge remote-tracking branch 'origin/windowing-cleanups' into windowi…
devvoid Jul 5, 2019
7bf5425
Typo in comment
devvoid Jul 5, 2019
5c37d58
Add missing enums
devvoid Jul 5, 2019
261b1c5
Throw exception if requested ISilkPlatform is not applicable
devvoid Jul 5, 2019
4418c7b
Merge remote-tracking branch 'origin/windowing-cleanups' into windowi…
devvoid Jul 5, 2019
019c00f
Use backticks around all type names for consistency
devvoid Jul 5, 2019
a1b855c
Better document the platform-picking system
devvoid Jul 5, 2019
34c29d5
More docs, change exception type
devvoid Jul 5, 2019
881132a
Merge remote-tracking branch 'origin/windowing-cleanups' into windowi…
devvoid Jul 5, 2019
e56951d
Add docs to ISilkPlatform
devvoid Jul 5, 2019
61e8715
Missed a slash
devvoid Jul 5, 2019
eb41639
Documentation in GlfwPlatform
devvoid Jul 5, 2019
72435a5
Remove default from GlfwWindow constructor
devvoid Jul 5, 2019
2ded92a
Add newline
devvoid Jul 5, 2019
356ad08
Wrong cref
devvoid Jul 5, 2019
d141fa3
Add newline
devvoid Jul 5, 2019
63b17e0
Calculate fps instead of storing it directly
devvoid Jul 5, 2019
b168852
Merge remote-tracking branch 'origin/windowing-cleanups' into windowi…
devvoid Jul 5, 2019
0e357db
Replace tabs with spaces for consistency
devvoid Jul 5, 2019
381ed6b
Missed newline
devvoid Jul 5, 2019
cd8b572
Accidental paste
devvoid Jul 5, 2019
d99cb06
.NET platform -> native backend
devvoid Jul 5, 2019
8ad1e11
Replace reflection-related docs with what it actually does
devvoid Jul 5, 2019
b2752b6
Don't round the results
devvoid Jul 5, 2019
a3b562c
Merge remote-tracking branch 'origin/windowing-cleanups' into windowi…
devvoid Jul 5, 2019
4a1137e
Don't throw exception if an improper platform is set
devvoid Jul 5, 2019
98ac8c3
Update documentation to match recent changes
devvoid Jul 5, 2019
ea9071d
IsRunningSlowlyThreshold -> RunningSlowTolerance
devvoid Jul 5, 2019
7cea692
Merge remote-tracking branch 'origin/windowing-cleanups' into windowi…
devvoid Jul 5, 2019
8235241
Update IsRunningSlowly to RunningSlowTolerance
devvoid Jul 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
458 changes: 318 additions & 140 deletions documentation/proposals/Proposal - Windowing.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Silk.NET.Windowing.Common
public enum WindowBorder
{
/// <summary>
/// The window can be resized by grabbing its border.
/// The window can be resized by clicking and dragging its border.
/// </summary>
Resizable = 0,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@

namespace Silk.NET.Windowing.Common
{
/// <summary>
/// An interface that provides windowing for its respective native backend.
/// </summary>
public interface ISilkPlatform
{
/// <summary>
/// Gets a value indicating whether this <see cref="ISilkPlatform"/> should be used, based on the
/// current runtime/environment.
/// </summary>
bool IsApplicable { get; }

/// <summary>
/// Creates a window with the given options.
/// </summary>
/// <param name="options">The initial settings this window should open with.</param>
/// <returns>An implementation of <see cref="IWindow"/></returns>
IWindow GetWindow(WindowOptions options);
}
}
}
5 changes: 3 additions & 2 deletions src/Windowing/Silk.NET.Windowing.Common/Interfaces/IWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public interface IWindow : IWindowProperties, IWindowFunctions, IWindowEvents
IntPtr Handle { get; }

/// <summary>
/// If true, the window has failed to reach the target framerate for five consecutive frames. You can use this
/// to do things such as lowering visual fidelity to increase framerates on lower-end machines.
/// If true, the window has failed to reach the target framerate for multiple consecutive frames, as defined
/// in <see cref="IWindowProperties.RunningSlowTolerance"/>. You can use this to do things such as lowering
/// visual fidelity to increase framerates on lower-end machines.
/// </summary>
bool IsRunningSlowly { get; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ namespace Silk.NET.Windowing.Common
public interface IWindowProperties
{
/// <summary>
/// Gets or sets whether or not the window is visible.
/// Whether or not the window is visible.
/// </summary>
bool IsVisible { get; set; }

/// <summary>
/// If true, both updates and rendering will happen on the same thread. If false, both updating and rendering
/// will be run on their own threads. Default is true.
/// will be run on their own threads.
/// </summary>
bool UseSingleThreadedWindow { get; }

/// <summary>
/// The position of the window. Integer vector. If set to -1, use the backend default.
/// Default is -1 for both components.
/// The position of the window. If set to -1, use the backend default.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -35,7 +34,7 @@ public interface IWindowProperties
Point Position { get; set; }

/// <summary>
/// Gets or sets the size of the window in pixels.
/// The size of the window in pixels.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -55,7 +54,7 @@ public interface IWindowProperties
double UpdatesPerSecond { get; set; }

/// <summary>
/// Gets the graphics API the window will use.
/// The graphics API to use, and associated configurations.
/// </summary>
GraphicsAPI API { get; }

Expand All @@ -65,18 +64,24 @@ public interface IWindowProperties
string Title { get; set; }

/// <summary>
/// Gets or sets the window state.
/// The window state.
/// </summary>
WindowState WindowState { get; set; }

/// <summary>
/// Gets or sets the window border.
/// The window border.
/// </summary>
WindowBorder WindowBorder { get; set; }

/// <summary>
/// Gets or sets the VSync mode.
/// The VSync mode.
/// </summary>
VSyncMode VSync { get; set; }

/// <summary>
/// The number of frames the window needs to be running slowly for before <see cref="IWindow.IsRunningSlowly"/>
/// is set to true.
/// </summary>
int RunningSlowTolerance { get; set; }
}
}
8 changes: 6 additions & 2 deletions src/Windowing/Silk.NET.Windowing.Common/WindowOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ public struct WindowOptions : IWindowProperties

/// <inheritdoc />
public VSyncMode VSync { get; set; }

/// <inheritdoc />
public int RunningSlowTolerance { get; set; }

/// <summary>
/// Creates a new WindowOptions struct, with sensible defaults.
/// </summary>
public WindowOptions(bool isVisible, bool useSingleThreadedWindow, Point position, Size size,
double framesPerSecond,
double updatesPerSecond, GraphicsAPI api, string title, WindowState windowState, WindowBorder windowBorder,
VSyncMode vSync)
VSyncMode vSync, int isRunningSlowlyThreshold)
{
IsVisible = isVisible;
UseSingleThreadedWindow = useSingleThreadedWindow;
Expand All @@ -64,13 +67,14 @@ public WindowOptions(bool isVisible, bool useSingleThreadedWindow, Point positio
WindowState = windowState;
WindowBorder = windowBorder;
VSync = vSync;
RunningSlowTolerance = isRunningSlowlyThreshold;
}

/// <summary>
/// Convinience wrapper around creating a new WindowProperties with the default values.
/// </summary>
public static WindowOptions Default { get; } = new WindowOptions(true, true, new Point(-1, -1),
new Size(1280, 720), 0.0, 0.0, GraphicsAPI.Default,
"Silk.NET Window", WindowState.Normal, WindowBorder.Resizable, VSyncMode.On);
"Silk.NET Window", WindowState.Normal, WindowBorder.Resizable, VSyncMode.On, 5);
}
}
5 changes: 5 additions & 0 deletions src/Windowing/Silk.NET.Windowing.Desktop/GlfwPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

namespace Silk.NET.Windowing.Desktop
{
/// <summary>
/// A GLFW-based backend.
/// </summary>
public class GlfwPlatform : ISilkPlatform
{
/// <inheritdoc />
public bool IsApplicable
{
get
Expand All @@ -26,6 +30,7 @@ public bool IsApplicable
}
}

/// <inheritdoc />
public IWindow GetWindow(WindowOptions options)
{
return new GlfwWindow(options);
Expand Down
20 changes: 9 additions & 11 deletions src/Windowing/Silk.NET.Windowing.Desktop/GlfwWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public class GlfwWindow : IWindow
private double updatePeriod;
private double renderPeriod;

private double updatesPerSecond;
private double framesPerSecond;

/// <summary>
/// Create and open a new GlfwWindow.
/// </summary>
Expand Down Expand Up @@ -137,13 +134,17 @@ public GlfwWindow(WindowOptions options)
WindowState = options.WindowState;
Position = options.Position;
VSync = options.VSync;
RunningSlowTolerance = options.RunningSlowTolerance;

InitializeCallbacks();
}
}

/// <inheritdoc />
public int RunningSlowTolerance { get; set; }

/// <inheritdoc />
public bool IsRunningSlowly => _isRunningSlowlyTries > 5;
public bool IsRunningSlowly => _isRunningSlowlyTries > RunningSlowTolerance;

/// <inheritdoc />
public bool IsVisible
Expand Down Expand Up @@ -219,12 +220,11 @@ public Size Size
}

/// <inheritdoc />
public double FramesPerSecond {
get => framesPerSecond;
public double FramesPerSecond
{
get => 1.0 / renderPeriod;
set
{
framesPerSecond = value;

if (value <= double.Epsilon) {
renderPeriod = 0.0;
return;
Expand All @@ -237,11 +237,9 @@ public double FramesPerSecond {
/// <inheritdoc />
public double UpdatesPerSecond
{
get => updatesPerSecond;
get => 1.0 / updatePeriod;
set
{
updatesPerSecond = value;

if (value <= double.Epsilon) {
updatePeriod = 0.0;
return;
Expand Down
4 changes: 3 additions & 1 deletion src/Windowing/Silk.NET.Windowing/Silk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public static class Silk
/// <summary>
/// Reflects over the current AppDomain in an attempt to resolve an <see cref="ISilkPlatform" />.
/// </summary>
/// <exception cref="NotSupportedException">Thrown f no applicable <see cref="ISilkPlatform" /> was found.</exception>
/// <exception cref="NotSupportedException">
/// Thrown if no applicable <see cref="ISilkPlatform" /> was found.
/// </exception>
public static void Init()
{
var glfwPlatform = new GlfwPlatform();
Expand Down
8 changes: 8 additions & 0 deletions src/Windowing/Silk.NET.Windowing/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@

namespace Silk.NET.Windowing
{
/// <summary>
/// Convenience wrapper for easily creating a Silk.NET window.
/// </summary>
public static class Window
{
/// <summary>
/// Create a window on the current platform.
/// </summary>
/// <param name="options">The window to use.</param>
/// <returns>A Silk.NET window using the current platform.</returns>
public static IWindow Create(WindowOptions options)
{
if (Silk.CurrentPlatform == null) {
Expand Down