瀏覽代碼

Merge pull request #12056 from AvaloniaUI/ogl-bug

Fix EGL OpenGLControlBase on Win32
Max Katz 2 年之前
父節點
當前提交
856ce39314

+ 1 - 1
src/Avalonia.Base/Platform/Storage/PickerOptions.cs

@@ -6,7 +6,7 @@
 public class PickerOptions
 {
     /// <summary>
-    /// Gets or sets the text that appears in the title bar of a folder dialog.
+    /// Gets or sets the text that appears in the title bar of a picker.
     /// </summary>
     public string? Title { get; set; }
 

+ 9 - 7
src/Windows/Avalonia.Win32/OpenGl/WglDisplay.cs

@@ -38,12 +38,10 @@ namespace Avalonia.Win32.OpenGl
 
         [MemberNotNullWhen(true, nameof(s_wglChoosePixelFormatArb))]
         [MemberNotNullWhen(true, nameof(s_wglCreateContextAttribsArb))]
-        [MemberNotNullWhen(true, nameof(s_glDebugMessageCallback))]
         private static bool Initialize() => _initialized ??= InitializeCore();
 
         [MemberNotNullWhen(true, nameof(s_wglChoosePixelFormatArb))]
         [MemberNotNullWhen(true, nameof(s_wglCreateContextAttribsArb))]
-        [MemberNotNullWhen(true, nameof(s_glDebugMessageCallback))]
         private static bool InitializeCore()
         {
             Dispatcher.UIThread.VerifyAccess();
@@ -74,9 +72,9 @@ namespace Avalonia.Win32.OpenGl
                 Marshal.GetDelegateForFunctionPointer<WglChoosePixelFormatARBDelegate>(
                     wglGetProcAddress("wglChoosePixelFormatARB"));
 
-            s_glDebugMessageCallback =
-                Marshal.GetDelegateForFunctionPointer<GlDebugMessageCallbackDelegate>(
-                    wglGetProcAddress("glDebugMessageCallback"));
+            s_glDebugMessageCallback = wglGetProcAddress("glDebugMessageCallback") is { } setDebugCallback && setDebugCallback != default ?
+                Marshal.GetDelegateForFunctionPointer<GlDebugMessageCallbackDelegate>(setDebugCallback) :
+                null;
             
 
             var formats = new int[1];
@@ -144,8 +142,12 @@ namespace Avalonia.Win32.OpenGl
                             });
                     }
 
-                    using(new WglRestoreContext(dc, context, null))
-                        s_glDebugMessageCallback(Marshal.GetFunctionPointerForDelegate(_debugCallback), IntPtr.Zero);
+                    if (s_glDebugMessageCallback is not null)
+                    {
+                        using (new WglRestoreContext(dc, context, null))
+                            s_glDebugMessageCallback(Marshal.GetFunctionPointerForDelegate(_debugCallback), IntPtr.Zero);
+                    }
+
                     if (context != IntPtr.Zero)
                         return new WglContext(shareContext, version, context, window, dc,
                             _defaultPixelFormat, _defaultPfd);

+ 4 - 0
src/Windows/Avalonia.Win32/Win32GlManager.cs

@@ -20,6 +20,10 @@ static class Win32GlManager
         {
             AvaloniaLocator.CurrentMutable.Bind<IPlatformGraphics>().ToConstant(gl);
         }
+        if (gl is IPlatformGraphicsOpenGlContextFactory openGlFactory)
+        {
+            AvaloniaLocator.CurrentMutable.Bind<IPlatformGraphicsOpenGlContextFactory>().ToConstant(openGlFactory);
+        }
 
         return gl;
     }