Skip to content

Commit dd3fb37

Browse files
committed
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 <mary@mary.zone>
1 parent 1d69af0 commit dd3fb37

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

SPB.Testing/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static void Main(string[] args)
3434
Console.WriteLine($"OpenGL renderer: {GL.GetString(StringName.Renderer)}");
3535
Console.WriteLine($"OpenGL context profile mask: {GL.GetInteger((GetPName)All.ContextProfileMask)}");
3636
Console.WriteLine($"OpenGL context flags: {GL.GetInteger((GetPName)All.ContextFlags)}");
37+
Console.WriteLine($"Window swap interval: {window.SwapInterval}");
3738

3839
Thread.Sleep(2000);
3940

SPB/Platform/GLX/GLX.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,6 @@ public enum CreateContext : int
204204

205205
[DllImport(LibraryName, EntryPoint = "glXGetProcAddressARB")]
206206
public static extern IntPtr GetProcAddress(string procName);
207-
208-
209-
[DllImport(LibraryName, EntryPoint = "glXCreateContextAttribsARB")]
210-
public static extern Context CreateContextAttribs(Display display, IntPtr fbConfigs, Context shareContext, bool direct, int[] attributes);
211207
}
212208

213209
internal sealed class Ext

SPB/Platform/GLX/GLXHelper.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Runtime.InteropServices;
34
using System.Runtime.Versioning;
45
using SPB.Graphics;
56
using SPB.Graphics.OpenGL;
@@ -11,6 +12,30 @@ namespace SPB.Platform.GLX
1112
[SupportedOSPlatform("linux")]
1213
public sealed class GLXHelper
1314
{
15+
private static bool _isInit = false;
16+
17+
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
18+
private delegate IntPtr glxCreateContextAttribsARBDelegate(IntPtr display, IntPtr fbConfigs, IntPtr shareContext, bool direct, int[] attributes);
19+
20+
private static glxCreateContextAttribsARBDelegate CreateContextAttribsArb;
21+
22+
private static void EnsureInit()
23+
{
24+
if (!_isInit)
25+
{
26+
CreateContextAttribsArb = Marshal.GetDelegateForFunctionPointer<glxCreateContextAttribsARBDelegate>(GLX.ARB.GetProcAddress("glXCreateContextAttribsARB"));
27+
28+
_isInit = true;
29+
}
30+
}
31+
32+
public static IntPtr CreateContextAttribs(IntPtr display, IntPtr fbConfigs, IntPtr shareContext, bool direct, int[] attributes)
33+
{
34+
EnsureInit();
35+
36+
return CreateContextAttribsArb(display, fbConfigs, shareContext, direct, attributes);
37+
}
38+
1439
public static List<int> FramebufferFormatToVisualAttribute(FramebufferFormat format)
1540
{
1641
List<int> result = new List<int>();

SPB/Platform/GLX/GLXOpenGLContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ public override void Initialize(NativeWindowBase window = null)
7272

7373
IntPtr shareContextHandle = ShareContext == null ? IntPtr.Zero : ShareContext.ContextHandle;
7474

75-
IntPtr context = GLX.ARB.CreateContextAttribs(display, fbConfig, shareContextHandle, DirectRendering, contextAttribute.ToArray());
75+
IntPtr context = GLXHelper.CreateContextAttribs(display, fbConfig, shareContextHandle, DirectRendering, contextAttribute.ToArray());
7676

7777
if (context == IntPtr.Zero)
7878
{
79-
context = GLX.ARB.CreateContextAttribs(display, fbConfig, shareContextHandle, !DirectRendering, contextAttribute.ToArray());
79+
context = GLXHelper.CreateContextAttribs(display, fbConfig, shareContextHandle, !DirectRendering, contextAttribute.ToArray());
8080

8181
DirectRendering = !DirectRendering;
8282
}

0 commit comments

Comments
 (0)