Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to let users pick OpenGL version #921

Merged
merged 19 commits into from Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/Windowing/OpenToolkit.Windowing.Common/Enums/ContextAPI.cs
@@ -0,0 +1,47 @@
//
// ContextAPI.cs
//
// Copyright (C) 2019 OpenTK
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
//

namespace OpenToolkit.Windowing.Common
{
/// <summary>
/// Describes the graphics API you want the context to use.
/// </summary>
public enum ContextAPI
{
/// <summary>
/// Indicates that an API has not been specifically requested for context creation.
/// </summary>
/// <remarks>
/// <para>
/// This is primarily for integrating an external API with this window, such as Vulkan.
/// </para>
/// </remarks>
NoAPI,

/// <summary>
/// Indicates that the context should be created for OpenGL ES.
/// </summary>
OpenGLES,

/// <summary>
/// Indicates that the context should be created for OpenGL.
/// </summary>
OpenGL,

/// <summary>
/// Indicates that the context should be created for Vulkan.
/// </summary>
/// <remarks>
/// <para>
/// As of right now, this does the same thing as <see cref="NoAPI"/>
/// </para>
/// </remarks>
Vulkan,
devvoid marked this conversation as resolved.
Show resolved Hide resolved
}
}
43 changes: 43 additions & 0 deletions src/Windowing/OpenToolkit.Windowing.Common/Enums/ContextFlags.cs
@@ -0,0 +1,43 @@
//
// ContextFlags.cs
//
// Copyright (C) 2019 OpenTK
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
//

using System;

namespace OpenToolkit.Windowing.Common
{
/// <summary>
/// Enumerates various flags that affect the creation of new GraphicsContexts.
/// </summary>
[Flags]
public enum ContextFlags
{
/// <summary>
/// The default value of the GraphicsContextFlags enumeration.
/// </summary>
Default = 0,

/// <summary>
/// Indicates that this is a debug GraphicsContext. Debug contexts may provide
/// additional debugging information at the cost of performance.
/// </summary>
Debug = 1,

/// <summary>
/// Indicates that this is a forward compatible GraphicsContext. Forward-compatible contexts
/// do not support functionality marked as deprecated in the current GraphicsContextVersion.
/// </summary>
/// <remarks>Forward-compatible contexts are defined only for OpenGL versions 3.0 and later.</remarks>
ForwardCompatible = 2,

/// <summary>
/// Indicates that this GraphicsContext is intended for offscreen rendering.
/// </summary>
Offscreen = 4,
}
}
27 changes: 27 additions & 0 deletions src/Windowing/OpenToolkit.Windowing.Common/Enums/ContextProfile.cs
@@ -0,0 +1,27 @@
//
// ContextProfile.cs
//
// Copyright (C) 2019 OpenTK
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
//

namespace OpenToolkit.Windowing.Common
{
/// <summary>
/// Selects the profile for the context's graphics API. This only applies on OpenGL 3.2 upwards, and has no effect on older versions.
/// </summary>
public enum ContextProfile
{
/// <summary>
/// Selects compatability profile. You should only use this if maintaining legacy code.
/// </summary>
Compatability,

/// <summary>
/// Selects core profile. All new projects should use this unless they have a good reason not to.
/// </summary>
Core,
}
}
Expand Up @@ -7,6 +7,7 @@
// of the MIT license. See the LICENSE file for details.
//

using System;
using OpenToolkit.Mathematics;
using OpenToolkit.Windowing.Common.Input;

Expand Down Expand Up @@ -39,6 +40,26 @@ public interface INativeWindowProperties
/// </summary>
Monitor CurrentMonitor { get; set; }

/// <summary>
/// Gets a value representing the current graphics API.
/// </summary>
ContextAPI API { get; }

/// <summary>
/// Gets a value representing the current graphics API profile.
/// </summary>
ContextProfile Profile { get; }

/// <summary>
/// Gets a value representing the current graphics profile flags.
/// </summary>
ContextFlags Flags { get; }

/// <summary>
/// Gets a value representing the current version of the graphics API.
/// </summary>
Version APIVersion { get; }

/// <summary>
/// Gets or sets the clipboard string.
/// </summary>
Expand Down
Expand Up @@ -21,10 +21,6 @@
<ProjectReference Include="..\..\OpenToolkit.Mathematics\OpenToolkit.Mathematics.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Enums" />
</ItemGroup>

<Import Project="..\..\..\props\common.props" />
<Import Project="..\..\..\props\nuget-common.props" />
<Import Project="..\..\..\props\stylecop.props" />
Expand Down
49 changes: 49 additions & 0 deletions src/Windowing/OpenToolkit.Windowing.Desktop/NativeWindow.cs
Expand Up @@ -108,6 +108,18 @@ public string Title
}
}

/// <inheritdoc />
public ContextAPI API { get; }

/// <inheritdoc />
public ContextProfile Profile { get; }

/// <inheritdoc />
public ContextFlags Flags { get; }

/// <inheritdoc />
public Version APIVersion { get; }

private Monitor _currentMonitor;

/// <summary>
Expand Down Expand Up @@ -466,6 +478,43 @@ public NativeWindow(INativeWindowProperties settings)
break;
}

switch (API)
{
case ContextAPI.Vulkan:
case ContextAPI.NoAPI:
devvoid marked this conversation as resolved.
Show resolved Hide resolved
Glfw.WindowHint(WindowHintClientApi.ClientApi, ClientApi.NoApi);
break;

case ContextAPI.OpenGLES:
Glfw.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlEsApi);
break;

case ContextAPI.OpenGL:
Glfw.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlApi);
break;

default:
throw new ArgumentOutOfRangeException();
}

Glfw.WindowHint(WindowHintInt.ContextVersionMajor, APIVersion.Major);
Glfw.WindowHint(WindowHintInt.ContextVersionMinor, APIVersion.Minor);

if (Flags.HasFlag(ContextFlags.ForwardCompatible))
{
Glfw.WindowHint(WindowHintBool.OpenGLForwardCompat, true);
}

if (Flags.HasFlag(ContextFlags.Debug))
{
Glfw.WindowHint(WindowHintBool.OpenGLDebugContext, true);
}

Glfw.WindowHint
(
WindowHintOpenGlProfile.OpenGlProfile, (OpenGlProfile)Profile
);

Glfw.WindowHint(WindowHintBool.Focused, settings.IsFocused);
_windowBorder = settings.WindowBorder;

Expand Down
Expand Up @@ -52,6 +52,11 @@ public NativeWindowSettings()
Width = 640;
Height = 360;

API = ContextAPI.OpenGL;
Profile = ContextProfile.Core;
Flags = ContextFlags.Default;
APIVersion = new Version(3, 3);

IsFullscreen = false;

Exists = true;
Expand All @@ -66,6 +71,26 @@ public NativeWindowSettings()
/// <inheritdoc />
public string ClipboardString { get; set; }

/// <summary>
/// Gets or sets a value representing the current graphics API.
/// </summary>
public ContextAPI API { get; set; }
devvoid marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets a value representing the current graphics API profile.
/// </summary>
public ContextProfile Profile { get; set; }

/// <summary>
/// Gets or sets a value representing the current graphics profile flags.
/// </summary>
public ContextFlags Flags { get; set; }

/// <summary>
/// Gets or sets a value representing the current version of the graphics API.
/// </summary>
public Version APIVersion { get; set; }
devvoid marked this conversation as resolved.
Show resolved Hide resolved

/// <inheritdoc />
public Monitor CurrentMonitor { get; set; }

Expand Down