Skip to content

Commit

Permalink
Fix ALC_EXT_EFX hack (#1770)
Browse files Browse the repository at this point in the history
* Fix ALC_EXT_EFX hack

* Fix extension loading test

---------

Co-authored-by: arcraith <[email protected]>
  • Loading branch information
okaniku and doobah authored Nov 8, 2023
1 parent 9618279 commit 82785b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/OpenAL/Silk.NET.OpenAL.Tests/ExtensionLoadingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public ExtensionLoadingTests(ITestOutputHelper testOutputHelper)
[UnmanagedCallersOnly(CallConvs = new []{typeof(CallConvCdecl)})]
public static unsafe int AlwaysZero(byte* name) => 0;

[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
public static unsafe Context* GetCurrentContext() => null;

[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
public static unsafe Device* GetContextsDevice(Context* ctx) => null;

public unsafe delegate nint LoaderDelegate(byte* name);
public unsafe delegate nint ContextLoaderDelegate(void* device, byte* name);

Expand All @@ -51,6 +57,8 @@ public static unsafe Func<string, nint> GetLoader(bool alwaysPresent, out nint l
"alcIsExtensionPresent" or "alIsExtensionPresent" => alwaysPresent
? (nint) (delegate* unmanaged[Cdecl]<byte*, int>) &AlwaysOne
: (nint) (delegate* unmanaged[Cdecl]<byte*, int>) &AlwaysZero,
"alcGetCurrentContext" => (nint) (delegate* unmanaged[Cdecl]<Context*>) &GetCurrentContext,
"alcGetContextsDevice" => (nint) (delegate* unmanaged[Cdecl]<Context*, Device*>) &GetContextsDevice,
"alGetProcAddress" => wrapper[0],
"alcGetProcAddress" => wrapper[1],
"alGetEnumValue" => (nint) (delegate* unmanaged[Cdecl]<byte*, int>) &AlwaysZero,
Expand Down
6 changes: 4 additions & 2 deletions src/OpenAL/Silk.NET.OpenAL/AL/AL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public override unsafe bool IsExtensionPresent(string name)
SilkMarshal.StringIntoSpan(name, nameNative, NativeStringEncoding.UTF8);
fixed (byte* namePtr = nameNative)
{
return ((delegate* unmanaged[Cdecl]<byte*, char>) Context.GetProcAddress("alcIsExtensionPresent"))
(namePtr) == 1;
var currentContext = ((delegate* unmanaged[Cdecl]<Context*>) Context.GetProcAddress("alcGetCurrentContext"))();
var currentDevice = ((delegate* unmanaged[Cdecl]<Context*, Device*>) Context.GetProcAddress("alcGetContextsDevice"))(currentContext);
return ((delegate* unmanaged[Cdecl]<Device*, byte*, char>) Context.GetProcAddress("alcIsExtensionPresent"))
(currentDevice, namePtr) == 1;
}
}

Expand Down

0 comments on commit 82785b9

Please sign in to comment.