From 94e264970442cceab341752ca283051c4578be0f Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Thu, 14 Nov 2013 08:30:11 +0100 Subject: [PATCH] Cleaned up context profile selection Added support for WGL_create_context profiles and added methods for the selection of context flags and profile. --- .../Platform/Windows/Bindings/WglEnums.cs | 5 ++++- .../OpenTK/Platform/Windows/WinGLContext.cs | 22 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/Bindings/WglEnums.cs b/Source/OpenTK/Platform/Windows/Bindings/WglEnums.cs index 2af7d61c..6b4dc73d 100644 --- a/Source/OpenTK/Platform/Windows/Bindings/WglEnums.cs +++ b/Source/OpenTK/Platform/Windows/Bindings/WglEnums.cs @@ -5,13 +5,16 @@ namespace OpenTK.Platform.Windows public enum ArbCreateContext { + CoreProfileBit = 0x0001, + CompatibilityProfileBit = 0x0002, DebugBit = 0x0001, ForwardCompatibleBit = 0x0002, MajorVersion = 0x2091, MinorVersion = 0x2092, LayerPlane = 0x2093, - Flags = 0x2094, + ContextFlags = 0x2094, ErrorInvalidVersion = 0x2095, + ProfileMask = 0x9126 } public enum WGL_ARB_buffer_region diff --git a/Source/OpenTK/Platform/Windows/WinGLContext.cs b/Source/OpenTK/Platform/Windows/WinGLContext.cs index 67b8e269..8fb57376 100644 --- a/Source/OpenTK/Platform/Windows/WinGLContext.cs +++ b/Source/OpenTK/Platform/Windows/WinGLContext.cs @@ -122,9 +122,10 @@ namespace OpenTK.Platform.Windows attributes.Add(minor); if (flags != 0) { - attributes.Add((int)ArbCreateContext.Flags); -#warning "This is not entirely correct: Embedded is not a valid flag! We need to add a GetARBContextFlags(GraphicsContextFlags) method." - attributes.Add((int)flags); + attributes.Add((int)ArbCreateContext.ContextFlags); + attributes.Add((int)GetARBContextFlags(flags)); + attributes.Add((int)ArbCreateContext.ProfileMask); + attributes.Add((int)GetARBContextProfile(flags)); } // According to the docs, " specifies a list of attributes for the context. // The list consists of a sequence of pairs terminated by the @@ -181,6 +182,21 @@ namespace OpenTK.Platform.Windows } } + static ArbCreateContext GetARBContextFlags(GraphicsContextFlags flags) + { + ArbCreateContext result = 0; + result |= (flags & GraphicsContextFlags.ForwardCompatible) != 0 ? + ArbCreateContext.CoreProfileBit : ArbCreateContext.CompatibilityProfileBit; + return result; + } + + static ArbCreateContext GetARBContextProfile(GraphicsContextFlags flags) + { + ArbCreateContext result = 0; + result |= (flags & GraphicsContextFlags.Debug) != 0 ? ArbCreateContext.DebugBit : 0; + return result; + } + public WinGLContext(ContextHandle handle, WinWindowInfo window, IGraphicsContext sharedContext, int major, int minor, GraphicsContextFlags flags) {