daily update on 20240203 by nitloadd youmu. New glhandle setup.
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Realse all resource in this handle.
|
||||
/// This will release all resource in this <see cref="glHandle"/>.
|
||||
/// This <see langword="glHandle"/> will be not usable.
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
if (_value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
GCHandle.FromIntPtr((IntPtr)handle).Free();
|
||||
handle = (uint*)IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user