From dd3fb3703e4e526a2a6609d9da56317c2781d0bf Mon Sep 17 00:00:00 2001 From: Mary Guillemard Date: Wed, 31 Jan 2024 17:41:32 +0100 Subject: [PATCH] glx: use glXGetProcAddressARB to get glXCreateContextAttribsARB This doesn't have to be exported and was found when testing with mesa without glvnd enabled. Signed-off-by: Mary Guillemard --- SPB.Testing/Program.cs | 1 + SPB/Platform/GLX/GLX.cs | 4 ---- SPB/Platform/GLX/GLXHelper.cs | 25 +++++++++++++++++++++++++ SPB/Platform/GLX/GLXOpenGLContext.cs | 4 ++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/SPB.Testing/Program.cs b/SPB.Testing/Program.cs index 786885a..cc0c8ac 100644 --- a/SPB.Testing/Program.cs +++ b/SPB.Testing/Program.cs @@ -34,6 +34,7 @@ static void Main(string[] args) Console.WriteLine($"OpenGL renderer: {GL.GetString(StringName.Renderer)}"); Console.WriteLine($"OpenGL context profile mask: {GL.GetInteger((GetPName)All.ContextProfileMask)}"); Console.WriteLine($"OpenGL context flags: {GL.GetInteger((GetPName)All.ContextFlags)}"); + Console.WriteLine($"Window swap interval: {window.SwapInterval}"); Thread.Sleep(2000); diff --git a/SPB/Platform/GLX/GLX.cs b/SPB/Platform/GLX/GLX.cs index 6d64847..b74b304 100644 --- a/SPB/Platform/GLX/GLX.cs +++ b/SPB/Platform/GLX/GLX.cs @@ -204,10 +204,6 @@ public enum CreateContext : int [DllImport(LibraryName, EntryPoint = "glXGetProcAddressARB")] public static extern IntPtr GetProcAddress(string procName); - - - [DllImport(LibraryName, EntryPoint = "glXCreateContextAttribsARB")] - public static extern Context CreateContextAttribs(Display display, IntPtr fbConfigs, Context shareContext, bool direct, int[] attributes); } internal sealed class Ext diff --git a/SPB/Platform/GLX/GLXHelper.cs b/SPB/Platform/GLX/GLXHelper.cs index a23d76b..7c620e0 100644 --- a/SPB/Platform/GLX/GLXHelper.cs +++ b/SPB/Platform/GLX/GLXHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Runtime.InteropServices; using System.Runtime.Versioning; using SPB.Graphics; using SPB.Graphics.OpenGL; @@ -11,6 +12,30 @@ namespace SPB.Platform.GLX [SupportedOSPlatform("linux")] public sealed class GLXHelper { + private static bool _isInit = false; + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + private delegate IntPtr glxCreateContextAttribsARBDelegate(IntPtr display, IntPtr fbConfigs, IntPtr shareContext, bool direct, int[] attributes); + + private static glxCreateContextAttribsARBDelegate CreateContextAttribsArb; + + private static void EnsureInit() + { + if (!_isInit) + { + CreateContextAttribsArb = Marshal.GetDelegateForFunctionPointer(GLX.ARB.GetProcAddress("glXCreateContextAttribsARB")); + + _isInit = true; + } + } + + public static IntPtr CreateContextAttribs(IntPtr display, IntPtr fbConfigs, IntPtr shareContext, bool direct, int[] attributes) + { + EnsureInit(); + + return CreateContextAttribsArb(display, fbConfigs, shareContext, direct, attributes); + } + public static List FramebufferFormatToVisualAttribute(FramebufferFormat format) { List result = new List(); diff --git a/SPB/Platform/GLX/GLXOpenGLContext.cs b/SPB/Platform/GLX/GLXOpenGLContext.cs index 279af57..ba13dc0 100644 --- a/SPB/Platform/GLX/GLXOpenGLContext.cs +++ b/SPB/Platform/GLX/GLXOpenGLContext.cs @@ -72,11 +72,11 @@ public override void Initialize(NativeWindowBase window = null) IntPtr shareContextHandle = ShareContext == null ? IntPtr.Zero : ShareContext.ContextHandle; - IntPtr context = GLX.ARB.CreateContextAttribs(display, fbConfig, shareContextHandle, DirectRendering, contextAttribute.ToArray()); + IntPtr context = GLXHelper.CreateContextAttribs(display, fbConfig, shareContextHandle, DirectRendering, contextAttribute.ToArray()); if (context == IntPtr.Zero) { - context = GLX.ARB.CreateContextAttribs(display, fbConfig, shareContextHandle, !DirectRendering, contextAttribute.ToArray()); + context = GLXHelper.CreateContextAttribs(display, fbConfig, shareContextHandle, !DirectRendering, contextAttribute.ToArray()); DirectRendering = !DirectRendering; }