Skip to content

Commit 9001b79

Browse files
authored
Merge pull request #1292 from dotnet/openal-soft-buffer-callback
Implement AL_SOFT_callback_buffer extension
2 parents e098367 + 82e7406 commit 9001b79

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Silk.NET.OpenAL.Extensions.Soft
5+
{
6+
/// <summary>
7+
/// Strings for the AL_SOFT_callback_buffer extension.
8+
/// </summary>
9+
public enum SoftBufferCallback
10+
{
11+
/// <summary>
12+
/// Query only. The function address for the callback currently
13+
/// set on the buffer, from the last call to alBufferCallbackSOFT. A call to
14+
/// alBufferData will reset this to NULL.
15+
/// </summary>
16+
Function = 0x19A0,
17+
/// <summary>
18+
/// Query only. The user data pointer that will be passed to the
19+
/// callback, from the last call to alBufferCallbackSOFT. A call to
20+
/// alBufferData will reset this to NULL.
21+
/// </summary>
22+
UserParam = 0x19A1
23+
}
24+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Silk.NET.Core.Attributes;
5+
using Silk.NET.Core.Contexts;
6+
using Silk.NET.Core.Native;
7+
using Silk.NET.OpenAL;
8+
9+
namespace Silk.NET.OpenAL.Extensions.Soft
10+
{
11+
/// <summary>
12+
/// Exposes the public API of functions added by AL_SOFT_callback_buffer
13+
/// </summary>
14+
[NativeApi(Prefix = "al")]
15+
[Extension("AL_SOFT_callback_buffer")]
16+
public unsafe partial class SoftCallbackBuffer : NativeExtension<AL>
17+
{
18+
/// <inheritdoc cref="ExtensionBase" />
19+
public SoftCallbackBuffer(INativeContext ctx)
20+
: base(ctx)
21+
{
22+
}
23+
24+
/// <inheritdoc />
25+
[NativeApi(EntryPoint = "BufferCallbackSOFT")]
26+
public partial void BufferCallback(uint buffer, BufferFormat format, int freq, PfnBufferCallback callback, void* userPtr);
27+
28+
/// <inheritdoc />
29+
[NativeApi(EntryPoint = "GetBufferPtrSOFT")]
30+
public partial void GetBufferPtr(uint buffer, SoftBufferCallback param, void** ptr);
31+
32+
/// <inheritdoc />
33+
[NativeApi(EntryPoint = "GetBuffer3PtrSOFT")]
34+
public partial void GetBuffer3Ptr(uint buffer, SoftBufferCallback param, void** ptr0, void** ptr1, void** ptr2);
35+
36+
/// <inheritdoc />
37+
[NativeApi(EntryPoint = "GetBufferPtrvSOFT")]
38+
public partial void GetBufferPtrv(uint buffer, SoftBufferCallback param, void** ptr);
39+
}
40+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Runtime.InteropServices;
6+
using Silk.NET.Core.Native;
7+
8+
namespace Silk.NET.OpenAL.Extensions.Soft
9+
{
10+
public readonly unsafe struct PfnBufferCallback : IDisposable
11+
{
12+
private readonly void* _handle;
13+
public delegate* unmanaged[Cdecl]<void*, void*, int, int> Handle => (delegate* unmanaged[Cdecl]<void*, void*, int, int>) this._handle;
14+
public PfnBufferCallback
15+
(
16+
delegate* unmanaged[Cdecl]<void*, void*, int, int> ptr
17+
) => this._handle = ptr;
18+
19+
public PfnBufferCallback
20+
(
21+
BufferCallbackType proc
22+
) => this._handle = (void*) SilkMarshal.DelegateToPtr(proc);
23+
24+
public static PfnBufferCallback From(BufferCallbackType proc) => new PfnBufferCallback(proc);
25+
public void Dispose() => SilkMarshal.Free((nint) this._handle);
26+
27+
public static implicit operator nint(PfnBufferCallback pfn) => (nint) pfn.Handle;
28+
public static explicit operator PfnBufferCallback(nint pfn)
29+
=> new PfnBufferCallback((delegate* unmanaged[Cdecl]<void*, void*, int, int>) pfn);
30+
31+
public static implicit operator PfnBufferCallback(BufferCallbackType proc)
32+
=> new PfnBufferCallback(proc);
33+
34+
public static explicit operator BufferCallbackType(PfnBufferCallback pfn)
35+
=> SilkMarshal.PtrToDelegate<BufferCallbackType>(pfn);
36+
37+
public static implicit operator delegate* unmanaged[Cdecl]<void*, void*, int, int>(PfnBufferCallback pfn) => pfn.Handle;
38+
public static implicit operator PfnBufferCallback(delegate* unmanaged[Cdecl]<void*, void*, int, int> ptr) => new PfnBufferCallback(ptr);
39+
}
40+
41+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
42+
public unsafe delegate int BufferCallbackType(void* userPtr, void* samplerData, int numBytes);
43+
}

0 commit comments

Comments
 (0)