From 3c0787c6a9d4f272af2ace50e38549d3418465bb Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Mon, 16 Nov 2009 11:17:20 +0000 Subject: [PATCH] Make context current on loading thread and be more defensive when retrieving unmanaged entry points. Resolves issue [#1378]: "OpenGL Extensions test fails". --- Source/Examples/OpenTK/Test/Extensions.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Source/Examples/OpenTK/Test/Extensions.cs b/Source/Examples/OpenTK/Test/Extensions.cs index 6bd6d9c3..a9ad6aea 100644 --- a/Source/Examples/OpenTK/Test/Extensions.cs +++ b/Source/Examples/OpenTK/Test/Extensions.cs @@ -55,9 +55,15 @@ namespace Examples.WinForms { Application.Idle -= StartAsync; - // Create a context in order to load all GL methods (GL.LoadAll() is called automatically.) - using (GLControl control = new GLControl(GraphicsMode.Default, 3, 0, GraphicsContextFlags.Default)) + // Create a context to load all GL entry points. + // The loading part is handled automatically by OpenTK. + using (INativeWindow window = new OpenTK.NativeWindow()) + using (IGraphicsContext context = new GraphicsContext(GraphicsMode.Default, window.WindowInfo, 3, 0, GraphicsContextFlags.Default)) { + window.ProcessEvents(); + context.MakeCurrent(window.WindowInfo); + (context as IGraphicsContextInternal).LoadAll(); + TextBoxVendor.Text = GL.GetString(StringName.Vendor); TextBoxRenderer.Text = GL.GetString(StringName.Renderer); TextBoxVersion.Text = GL.GetString(StringName.Version); @@ -73,11 +79,14 @@ namespace Examples.WinForms foreach (Function f in LoadFunctionsFromType(typeof(GL))) { + FieldInfo @delegate = delegates.GetField(f.EntryPoint, + BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); + // Only show a function as supported when all relevant overloads are supported. if (!functions.ContainsKey(f)) - functions.Add(f, (bool)delegates.GetField(f.EntryPoint).GetValue(null)); + functions.Add(f, @delegate != null && @delegate.GetValue(null) != null); else - functions[f] &= (bool)delegates.GetField(f.EntryPoint).GetValue(null); + functions[f] &= @delegate != null && @delegate.GetValue(null) != null; } // Count supported functions using the delegates directly.