Skip to content

Commit

Permalink
glx: use glXGetProcAddressARB to get glXCreateContextAttribsARB
Browse files Browse the repository at this point in the history
This doesn't have to be exported and was found when testing with mesa without glvnd enabled.

Signed-off-by: Mary Guillemard <[email protected]>
  • Loading branch information
marysaka committed Jan 31, 2024
1 parent 1d69af0 commit dd3fb37
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions SPB.Testing/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 0 additions & 4 deletions SPB/Platform/GLX/GLX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions SPB/Platform/GLX/GLXHelper.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<glxCreateContextAttribsARBDelegate>(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<int> FramebufferFormatToVisualAttribute(FramebufferFormat format)
{
List<int> result = new List<int>();
Expand Down
4 changes: 2 additions & 2 deletions SPB/Platform/GLX/GLXOpenGLContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit dd3fb37

Please sign in to comment.