using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.AccessControl; using System.Text; using System.Threading.Tasks; namespace System { /// /// A handle to an OpenGL object. /// public unsafe class glHandle { private readonly uint[] _value; internal int length; internal uint* handle; public uint this[int index] { get { if (index > length) { throw new IndexOutOfRangeException(); } return *(handle + index); } set { if (index > length) { throw new IndexOutOfRangeException(); } *(handle + index) = value; } } public glHandle(int count) { _value = new uint[count]; length = count; handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject(); } internal glHandle(uint[] val) { _value = val; length = val.Length; handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject(); } internal glHandle(uint val) { _value = [val]; length = 1; handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject(); } public void Free() { if (_value == null) { return; } GCHandle h = GCHandle.FromIntPtr((IntPtr)handle); h.Free(); } /// /// Realse all resource in this handle. /// This will release all resource in this . /// This will be not usable. /// public void Release() { if (_value == null) { return; } else { GCHandle.FromIntPtr((IntPtr)handle).Free(); handle = (uint*)IntPtr.Zero; } } } }