daily update on 20240206 by nitload youmu
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -12,16 +13,42 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace System
|
||||
{
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object,
|
||||
/// must be indexed from a <see cref="glHandleSet"/>.
|
||||
/// Direct call will cause <see langword="InvalidOperationException"/>
|
||||
/// </summary>
|
||||
public unsafe struct glHandle
|
||||
{
|
||||
internal uint* valuePtr;
|
||||
|
||||
public glHandle()
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
internal glHandle(uint* val)
|
||||
{
|
||||
valuePtr = val;
|
||||
}
|
||||
|
||||
public uint Value
|
||||
{
|
||||
get { return *valuePtr; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object.
|
||||
/// </summary>
|
||||
public unsafe class glHandle
|
||||
public unsafe class glHandleSet
|
||||
{
|
||||
private readonly uint[] _value;
|
||||
internal int length;
|
||||
internal uint* handle;
|
||||
|
||||
public uint this[int index]
|
||||
public glHandle this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -29,39 +56,27 @@ namespace System
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
return *(handle + index);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (index > length)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
*(handle + index) = value;
|
||||
return new glHandle(handle + index);
|
||||
}
|
||||
}
|
||||
|
||||
public glHandle(int count)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetValue(int index, uint value)
|
||||
{
|
||||
_value[index] = value;
|
||||
}
|
||||
|
||||
public glHandleSet(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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// temporarily release the handle of GLhandle sets.
|
||||
/// Please call <see cref="Pin"/> method before indexing.
|
||||
/// </summary>
|
||||
public void Free()
|
||||
{
|
||||
if (_value == null)
|
||||
@@ -72,6 +87,15 @@ namespace System
|
||||
h.Free();
|
||||
}
|
||||
|
||||
public void Pin()
|
||||
{
|
||||
if (_value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Realse all resource in this handle.
|
||||
/// This will release all resource in this <see cref="glHandle"/>.
|
||||
|
||||
Reference in New Issue
Block a user