diff options
Diffstat (limited to 'vulkan')
| -rw-r--r-- | vulkan/PNext.cs | 46 | ||||
| -rw-r--r-- | vulkan/vulkan.csproj | 2 |
2 files changed, 47 insertions, 1 deletions
diff --git a/vulkan/PNext.cs b/vulkan/PNext.cs new file mode 100644 index 0000000..783e757 --- /dev/null +++ b/vulkan/PNext.cs @@ -0,0 +1,46 @@ +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +// +// Copyright (c) 2022 JP Bruyère +using System; +using System.Linq; +using System.Runtime.InteropServices; + +namespace Vulkan +{ + /// <summary> + /// Helper class to construct pnext chain + /// </summary> + public class PNext<T> : IDisposable where T : struct + { + IntPtr handle; + /// <summary> + /// Allocate on HGlobal a new structure of type T, ensure instance is Disposed. + /// </summary> + public PNext () { + init(); + } + /// <summary> + /// Allocate on HGlobal a new structure of type T and set the pNext field, + /// ensure instance is Disposed. + /// </summary> + public PNext (IntPtr pNext) { + init(); + Marshal.WriteIntPtr(handle + 4, pNext); + } + void init() { + handle = Marshal.AllocHGlobal(Marshal.SizeOf<T>()); + Type t = typeof(T); + StructureTypeAttribute st = (StructureTypeAttribute)t.GetCustomAttributes(typeof(StructureTypeAttribute), false).FirstOrDefault(); + Marshal.WriteInt32(handle, st.StructureType); + } + /// <summary> + /// Get value of T + /// </summary> + public T Val => Marshal.PtrToStructure<T> (handle); + public static implicit operator IntPtr(PNext<T> pn) => pn.handle; + public void Dispose() + { + Marshal.FreeHGlobal(handle); + } + } +} diff --git a/vulkan/vulkan.csproj b/vulkan/vulkan.csproj index f90c5cb..209502d 100644 --- a/vulkan/vulkan.csproj +++ b/vulkan/vulkan.csproj @@ -3,7 +3,7 @@ <PropertyGroup> <TargetFrameworks>netstandard2.1</TargetFrameworks> - <AssemblyVersion>0.4.2</AssemblyVersion> + <AssemblyVersion>0.5.0</AssemblyVersion> <AssemblyName>Vulkan</AssemblyName> <PackageVersion>$(AssemblyVersion)</PackageVersion> |