brutal/Brutal.Slang/SlangInterfaceMarshaller.cs
BRUTAL release 4ac91e105e Update Slang, Vulkan, Gltf and ImGui. Offload natives to sub-packages.
Public-PR: https://github.com/ahwootech/BRUTAL/pull/9
Public-PR: https://github.com/ahwootech/BRUTAL/pull/15
Public-PR: https://github.com/ahwootech/BRUTAL/pull/21
Fixes: ahwootech/BRUTAL#8
Fixes: ahwootech/BRUTAL#22
Co-authored-by: Laurens de Voogd <laurens@devoogd.be>
Co-authored-by: sGo7-Dev <goulax16@gmail.com>
Co-authored-by: Capsup <capsup@live.dk>
2026-10-23 15:07:17 +13:00

23 lines
681 B
C#

using System.Runtime.InteropServices.Marshalling;
namespace Brutal.SlangApi;
[CustomMarshaller(
typeof(CustomMarshallerAttribute.GenericPlaceholder),
MarshalMode.Default,
typeof(SlangInterfaceMarshaller<>)
)]
internal static unsafe class SlangInterfaceMarshaller<T>
where T : class
{
public static T? ConvertToManaged(void* unmanaged) => Slang.WrapBorrowedComInstance<T>((nint)unmanaged);
public static void* ConvertToUnmanaged(T? managed) =>
managed is null ? null : (void*)Slang.GetComInstance<T>(managed);
public static void Free(void* unmanaged)
{
if (unmanaged != null)
Marshal.Release((nint)unmanaged);
}
}