daily update on 20240403 by nitload youmu
This commit is contained in:
@@ -44,39 +44,27 @@ namespace StgSharp.Graphics
|
||||
/// <summary>
|
||||
/// A handle to an OpenGL object,
|
||||
/// must be indexed from a <see cref="glHandleSet"/>.
|
||||
/// Direct call will cause <see langword="InvalidOperationException"/>
|
||||
/// Attempt at direct creating an instance will cause <see cref="InvalidOperationException"/>
|
||||
/// </summary>
|
||||
public unsafe struct glHandle
|
||||
{
|
||||
|
||||
internal glHandleSet source;
|
||||
internal uint* valuePtr;
|
||||
|
||||
private glHandle(IntPtr handle)
|
||||
internal glHandle(int index, GCHandle arrayHandle)
|
||||
{
|
||||
this.valuePtr = (uint*)handle;
|
||||
source = null;
|
||||
}
|
||||
|
||||
internal glHandle(uint* val, glHandleSet set)
|
||||
{
|
||||
source = set;
|
||||
valuePtr = val;
|
||||
valuePtr = ((uint*)GCHandle.ToIntPtr(arrayHandle)) + index;
|
||||
}
|
||||
|
||||
[Obsolete("Cannot init instance of this type", true)]
|
||||
public glHandle()
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (source.handle == (uint*)0)
|
||||
{
|
||||
throw new InvalidOperationException($"Handle set {nameof(source)} is not pinned.");
|
||||
}
|
||||
return (IntPtr)valuePtr;
|
||||
}
|
||||
}
|
||||
@@ -85,68 +73,29 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
get
|
||||
{
|
||||
if (source.handle == (uint*)0)
|
||||
{
|
||||
throw new InvalidOperationException($"Handle set {nameof(source)} is not pinned.");
|
||||
}
|
||||
return *valuePtr;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (source.handle == (uint*)0)
|
||||
{
|
||||
throw new InvalidOperationException($"Handle set {nameof(source)} is not pinned.");
|
||||
}
|
||||
*valuePtr = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static glHandle Zero => Alloc(0);
|
||||
|
||||
internal uint DirectValue => *valuePtr;
|
||||
|
||||
public static glHandle Alloc(uint value)
|
||||
{
|
||||
glHandle ret = default;
|
||||
ret.source = new glHandleSet(1);
|
||||
ret.valuePtr = ret.source.handle;
|
||||
*ret.valuePtr = value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static glHandle Alloc(IntPtr handle)
|
||||
{
|
||||
return new glHandle(handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public unsafe struct glSHandle
|
||||
{
|
||||
|
||||
internal glHandleSet source;
|
||||
internal int* valuePtr;
|
||||
|
||||
internal glSHandle(int* val, glHandleSet set)
|
||||
internal glSHandle(int index, glHandleSet set)
|
||||
{
|
||||
source = set;
|
||||
valuePtr = val;
|
||||
|
||||
}
|
||||
|
||||
public static glSHandle Zero => Alloc(0);
|
||||
|
||||
internal int DirectValue => *valuePtr;
|
||||
|
||||
public static glSHandle Alloc(int value)
|
||||
{
|
||||
glSHandle ret = default;
|
||||
ret.source = new glHandleSet(1);
|
||||
ret.valuePtr = (int*)ret.source.handle;
|
||||
*ret.valuePtr = value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public unsafe class glArrayHandle
|
||||
@@ -202,15 +151,20 @@ namespace StgSharp.Graphics
|
||||
public unsafe class glHandleSet
|
||||
{
|
||||
|
||||
private readonly uint[] _value;
|
||||
internal uint* handle;
|
||||
private uint[] _value;
|
||||
internal GCHandle handle;
|
||||
internal int length;
|
||||
|
||||
public glHandleSet(int count)
|
||||
{
|
||||
_value = new uint[count];
|
||||
length = count;
|
||||
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
|
||||
handle = GCHandle.Alloc(_value);
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get => GCHandle.ToIntPtr(handle);
|
||||
}
|
||||
|
||||
public glHandle this[int index]
|
||||
@@ -221,7 +175,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
return new glHandle(handle + index, this);
|
||||
return new glHandle(index, this.handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +187,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
return new glSHandle(((int*)handle) + index, this);
|
||||
return new glSHandle((int)index, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,30 +207,6 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// temporarily release the handle of GLhandle sets.
|
||||
/// Please call <see cref="Pin"/> method before indexing.
|
||||
/// </summary>
|
||||
public void Free()
|
||||
{
|
||||
if (_value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
GCHandle h = GCHandle.FromIntPtr((IntPtr)handle);
|
||||
h.Free();
|
||||
handle = (uint*)0;
|
||||
}
|
||||
|
||||
public void Pin()
|
||||
{
|
||||
if (_value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
handle = (uint*)GCHandle.Alloc(_value, GCHandleType.Pinned).AddrOfPinnedObject();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Release all resource in this handle.
|
||||
/// This will release all resource in this <see cref="glHandle"/>.
|
||||
@@ -284,17 +214,19 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
if (_value == null)
|
||||
if (handle == default)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
GCHandle.FromIntPtr((IntPtr)handle).Free();
|
||||
handle = (uint*)IntPtr.Zero;
|
||||
handle.Free();
|
||||
_value = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetValue(int index, uint value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user