Override context creation in GLArea.
authorJarl Gullberg <jarl.gullberg@gmail.com>
Sun, 1 Oct 2017 18:11:58 +0000 (20:11 +0200)
committerJarl Gullberg <jarl.gullberg@gmail.com>
Sun, 1 Oct 2017 18:11:58 +0000 (20:11 +0200)
This allows forward compatible and debug contexts to be created, and
provides more descriptive exceptions in the case where the context
cannot be created with the requested settings.

src/OpenTK.GLWidget/GLWidget.cs

index 54b6bd7..afe0ffe 100644 (file)
@@ -109,6 +109,22 @@ namespace OpenTK
             return true;
         }
 
+
+        /// <inheritdoc />
+        protected override GLContext OnCreateContext()
+        {
+            var gdkGLContext = Window.CreateGlContext();
+
+            GetRequiredVersion(out var major, out var minor);
+            gdkGLContext.SetRequiredVersion(major, minor);
+
+            gdkGLContext.DebugEnabled = GraphicsContextFlags.HasFlag(GraphicsContextFlags.Debug);
+            gdkGLContext.ForwardCompatible = GraphicsContextFlags.HasFlag(GraphicsContextFlags.ForwardCompatible);
+
+            gdkGLContext.Realize();
+            return gdkGLContext;
+        }
+
         /// <summary>
         /// Destructs this object.
         /// </summary>