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 5 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
27 changes: 27 additions & 0 deletions src/Windowing/OpenToolkit.Windowing.Common/Enums/OpenGLVersion.cs
@@ -0,0 +1,27 @@
//
// OpenGLVersion.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 OpenGL version you want the window to use.
/// </summary>
public enum OpenGLVersion
{
/// <summary>
/// Selects core profile OpenGL 3.3
/// </summary>
OPENGL_3_3_CORE,
devvoid marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Selects compatability profile OpenGL 3.3
/// </summary>
OPENGL_3_3_COMPAT,
devvoid marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Up @@ -39,6 +39,11 @@ public interface INativeWindowProperties
/// </summary>
Monitor CurrentMonitor { get; set; }

/// <summary>
/// Gets a value representing the current OpenGL version.
/// </summary>
OpenGLVersion Version { 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
33 changes: 33 additions & 0 deletions src/Windowing/OpenToolkit.Windowing.Desktop/NativeWindow.cs
Expand Up @@ -108,6 +108,9 @@ public string Title
}
}

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

private Monitor _currentMonitor;

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

int major, minor;
bool isCompat;

switch (Version)
{
case OpenGLVersion.OPENGL_3_3_CORE:
major = 3;
minor = 3;
isCompat = false;
break;

case OpenGLVersion.OPENGL_3_3_COMPAT:
major = 3;
minor = 3;
isCompat = true;
break;

default:
throw new Exception("Could not find version requested");
devvoid marked this conversation as resolved.
Show resolved Hide resolved
}

Glfw.WindowHint(WindowHintInt.ContextVersionMajor, major);
Glfw.WindowHint(WindowHintInt.ContextVersionMinor, minor);

Glfw.WindowHint
(
WindowHintOpenGlProfile.OpenGlProfile,
isCompat ? OpenGlProfile.Compat : OpenGlProfile.Core
);

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

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

Version = OpenGLVersion.OPENGL_3_3_CORE;

IsFullscreen = false;

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

/// <summary>
/// Gets or sets a value representing the current OpenGL version.
/// </summary>
public OpenGLVersion Version { get; set; }

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

Expand Down