daily update on 2024.03.18 by itload youmu

This commit is contained in:
YoumuLiu
2024-03-19 02:41:04 +08:00
parent 15bf989285
commit 0c50c6282e
200 changed files with 7663 additions and 3455 deletions
+67 -44
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLhandle.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
@@ -18,12 +48,14 @@ namespace StgSharp.Graphics
/// </summary>
public unsafe struct glHandle
{
internal glHandleSet source;
internal uint* valuePtr;
[Obsolete("Cannot init instance of this type", true)]
public glHandle()
private glHandle(IntPtr handle)
{
this.valuePtr = (uint*)handle;
source = null;
}
internal glHandle(uint* val, glHandleSet set)
@@ -32,15 +64,9 @@ namespace StgSharp.Graphics
valuePtr = val;
}
private glHandle(IntPtr handle)
[Obsolete("Cannot init instance of this type", true)]
public glHandle()
{
this.valuePtr = (uint*)handle;
source = null;
}
public static glHandle Zero
{
get { return Alloc(0); }
}
public IntPtr Handle
@@ -75,13 +101,9 @@ namespace StgSharp.Graphics
}
}
internal uint DirectValue
{
get
{
return *valuePtr;
}
}
public static glHandle Zero => Alloc(0);
internal uint DirectValue => *valuePtr;
public static glHandle Alloc(uint value)
{
@@ -97,10 +119,12 @@ namespace StgSharp.Graphics
{
return new glHandle(handle);
}
}
public unsafe struct glSHandle
{
internal glHandleSet source;
internal int* valuePtr;
@@ -110,29 +134,25 @@ namespace StgSharp.Graphics
valuePtr = val;
}
public static glSHandle Zero
{
get { return Alloc(0); }
}
public static glSHandle Zero => Alloc(0);
internal int DirectValue
{
get { return *valuePtr; }
}
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 = (int)value;
*ret.valuePtr = value;
return ret;
}
}
//TODO 发现一个大问题,paramQueue大多数时候取出的是数组,不是数组句柄,也就是说其内存将被长期固定且不能回收,这是内存泄漏
public unsafe class glArrayHandle
{
internal readonly Array a;
internal GCHandle handle;
@@ -142,20 +162,6 @@ namespace StgSharp.Graphics
handle = GCHandle.Alloc(array, GCHandleType.Pinned);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glArrayHandle CopyAlloc<T>(T[] array) where T : struct
{
Array copy = new T[array.Length];
array.CopyTo(copy, 0);
return new glArrayHandle(copy);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glArrayHandle Alloc<T>(T[] array) where T : struct
{
return new glArrayHandle(array);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IntPtr AddressOfArray()
{
@@ -169,11 +175,26 @@ namespace StgSharp.Graphics
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glArrayHandle Alloc<T>(T[] array) where T : struct
{
return new glArrayHandle(array);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glArrayHandle CopyAlloc<T>(T[] array) where T : struct
{
Array copy = new T[array.Length];
array.CopyTo(copy, 0);
return new glArrayHandle(copy);
}
public void Release()
{
handle.Free();
handle = default;
}
}
/// <summary>
@@ -181,9 +202,10 @@ namespace StgSharp.Graphics
/// </summary>
public unsafe class glHandleSet
{
private readonly uint[] _value;
internal uint* handle;
internal int length;
private readonly uint[] _value;
public glHandleSet(int count)
{
@@ -212,13 +234,13 @@ namespace StgSharp.Graphics
{
throw new IndexOutOfRangeException();
}
return new glSHandle((int*)handle + index, this);
return new glSHandle(((int*)handle) + index, this);
}
}
public static void Copy(in glHandleSet source, glHandleSet target)
{
if (source == null || target == null)
if ((source == null) || (target == null))
{
throw new NullReferenceException();
}
@@ -279,5 +301,6 @@ namespace StgSharp.Graphics
{
_value[index] = value;
}
}
}