daily update on 20240305 by nitload youmu

This commit is contained in:
YoumuLiu
2024-03-05 10:17:02 +08:00
parent 1f2fca4c8f
commit 6a0cccae79
156 changed files with 23040 additions and 1385 deletions
+54 -42
View File
@@ -17,15 +17,13 @@ namespace StgSharp.Graphics
{
private static ConcurrentQueue<IntPtr> glActionQueue;
private static GLparamQueue paramQueue;
private FrameTimeoutException refreshSignal = new();
private GLcontext* api;
private FrameTimeoutException refreshSignal = new();
private IntPtr SwapBufferPtr = (IntPtr)(delegate*<IntPtr, void>)&InternalIO.glfwSwapBuffers;
GLcontext* IglFunc.Context
internal void ShowDequeueStream()
{
get => api;
paramQueue.ShowDequeueLog();
}
internal GLonUpdate(GLcontext* context)
@@ -38,6 +36,11 @@ namespace StgSharp.Graphics
api = context;
}
GLcontext* IglFunc.Context
{
get => api;
}
internal static GLparamQueue ParamQueue
{
get { return paramQueue; }
@@ -84,8 +87,8 @@ namespace StgSharp.Graphics
void IglFunc.BindBuffer(BufferType bufferType, glHandle handle)
{
M128 m = default;
m.UInt32[0] = (uint)bufferType;
m.UInt64[1] = (ulong)handle.Handle;
m.Write<uint>(0, (uint)bufferType);
m.Write<ulong>(1, (ulong)handle.valuePtr);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(BindBufferPtr);
}
@@ -94,8 +97,8 @@ namespace StgSharp.Graphics
void IglFunc.BindTexture(uint type, glHandle texture)
{
M128 m = default;
m.UInt64[1] = (ulong)texture.valuePtr;
m.UInt32[0] = (uint)type;
m.Write<uint>(0, (uint)type);
m.Write<ulong>(1, (ulong)texture.valuePtr);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(BindTexturePtr);
}
@@ -110,6 +113,7 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.Clear(MaskBufferBit mask)
{
paramQueue.Enqueue((int)mask);
glActionQueue.Enqueue(ClearPtr);
}
@@ -126,22 +130,10 @@ namespace StgSharp.Graphics
glActionQueue.Enqueue(ClearGraphicErrorPtr);
}
glHandleSet IglFunc.CompileShader(ShaderType shaderType, params string[] shaderCode)
unsafe void IglFunc.CompileShader(glHandle shaderhandle)
{
int l = shaderCode.Length;
if (l == 0)
{
throw new ArgumentException("Should input at least one piece of shader code");
}
glHandleSet shaderHandle = new glHandleSet(shaderCode.Length);
paramQueue.Enqueue((int)shaderType, l);
for (int i = 0; i < l; i++)
{
GCHandle codePtr = GCHandle.Alloc(Encoding.UTF8.GetBytes(shaderCode[i] + '\0'), GCHandleType.Pinned);
paramQueue.Enqueue((IntPtr)(shaderHandle.handle + i), codePtr.AddrOfPinnedObject());
}
paramQueue.Enqueue((IntPtr)shaderhandle.valuePtr);
glActionQueue.Enqueue(CompileShaderPtr);
return shaderHandle;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -153,18 +145,31 @@ namespace StgSharp.Graphics
return h;
}
//TODO
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandleSet IglFunc.CreateProgram(int count)
{
M128 m = default;
glHandleSet h = new glHandleSet(count);
m.UInt64[0] = (ulong)h.handle;
m.Int32[2] = count;
m.Write<ulong>(0, (ulong)h.handle);
m.Write<int>(2, count);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(CreateProgramSetPtr);
return h;
}
glHandleSet IglFunc.CreateShaderSet(int count, ShaderType type)
{
glHandleSet ret = new glHandleSet(count);
M128 m = new M128();
m.Write<int>(0, count);
m.Write<uint>(1, (uint)type);
m.Write<ulong>(1, (ulong)ret.handle);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(CreateShaderPtr);
return ret;
}
IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share)
{
byte[] tittleBytes = Encoding.UTF8.GetBytes(tittle);
@@ -203,8 +208,8 @@ namespace StgSharp.Graphics
unsafe void IglFunc.DeleteBuffer(glHandle handle)
{
M128 m = default;
m.UInt64[0] = (ulong)handle.Handle;
m.UInt32[2] = 1;
m.Write<ulong>(0, (ulong)handle.valuePtr);
m.Write(2, 1);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(DeleBufferPtr);
}
@@ -212,16 +217,16 @@ namespace StgSharp.Graphics
unsafe void IglFunc.DeleteBuffers(glHandleSet handle)
{
M128 m = default;
m.UInt32[2] = (uint)handle.length;
m.UInt64[0] = (ulong)handle.handle;
m.Write<uint>(2, (uint)handle.length);
m.Write<ulong>(0, (ulong)handle.handle);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(DeleBufferPtr);
}
unsafe void IglFunc.DeleteVertexArrays(glHandleSet arrays)
{
M128 m = default; m.UInt64[1] = (ulong)arrays.handle;
m.Int32[0] = arrays.length;
M128 m = default; m.Write<ulong>(1, (ulong)arrays.handle);
m.Write<int>(0, arrays.length);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(DeleteVertexArrayPtr);
}
@@ -258,7 +263,7 @@ namespace StgSharp.Graphics
unsafe glHandleSet IglFunc.GenBuffers(int count)
{
glHandleSet h = new glHandleSet(count);
M128 m = default; m.UInt32[2] = (uint)count; m.UInt64[0] = (ulong)h.handle;
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(GenBufferPtr);
return h;
@@ -267,7 +272,7 @@ namespace StgSharp.Graphics
unsafe glHandleSet IglFunc.GenTextures(int count)
{
glHandleSet h = new glHandleSet(count);
M128 m = default; m.UInt32[2] = (uint)count; m.UInt64[0] = (ulong)h.handle;
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(GenTexturesPtr);
return h;
@@ -276,7 +281,7 @@ namespace StgSharp.Graphics
unsafe glHandleSet IglFunc.GenVertexArrays(int count)
{
glHandleSet h = new glHandleSet(count);
M128 m = default; m.UInt32[2] = (uint)count; m.UInt64[0] = (ulong)h.handle;
M128 m = default; m.Write<uint>(2, (uint)count); m.Write<ulong>(0, (ulong)h.handle);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(GenTexturesPtr);
return h;
@@ -286,9 +291,9 @@ namespace StgSharp.Graphics
unsafe glSHandle IglFunc.GetUniformLocation(glHandle program, string ptr)
{
glSHandle h = glSHandle.Alloc(0);
M128 m;
m.UInt64[0] = (ulong)program.Handle;
m.UInt64[1] = (ulong)GCHandle.Alloc(Encoding.UTF8.GetBytes(ptr)).AddrOfPinnedObject();
M128 m = default;
m.Write<ulong>(0, (ulong)program.Handle);
m.Write<ulong>(1, (ulong)GCHandle.Alloc(Encoding.UTF8.GetBytes(ptr)).AddrOfPinnedObject());
paramQueue.Enqueue(m);
paramQueue.Enqueue((IntPtr)h.valuePtr);
glActionQueue.Enqueue(GetUniformLocationPtr);
@@ -310,6 +315,12 @@ namespace StgSharp.Graphics
InternalIO.glfwSwapBuffers(form.windowID);
}
void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
{
paramQueue.Enqueue(shaderHandle);
paramQueue.Enqueue(codeStream);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.MakeContexCurrent(Form form)
{
@@ -330,7 +341,8 @@ namespace StgSharp.Graphics
void IglFunc.SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage)
{
paramQueue.Enqueue((uint)bufferType, (uint)usage);
paramQueue.Enqueue((IntPtr)(Marshal.SizeOf<T>() * bufferArray.Length), GCHandle.Alloc(bufferArray).AddrOfPinnedObject());
paramQueue.Enqueue((IntPtr)(Marshal.SizeOf<T>() * bufferArray.Length));
paramQueue.Enqueue<T>(bufferArray);
glActionQueue.Enqueue(BufferDataPtr);
}
@@ -359,9 +371,9 @@ namespace StgSharp.Graphics
void IglFunc.TextureParameter(int target, uint pname, int param)
{
M128 m = default;
m.Int32[0] = target;
m.UInt32[2] = pname;
m.Int32[3] = param;
m.Write<int>(0, target);
m.Write<uint>(2, pname);
m.Write<int>(3, param);
paramQueue.Enqueue(m);
glActionQueue.Enqueue(TextureParameterPtr);
}
@@ -382,11 +394,11 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void frameworkHandleEnqueue(IntPtr methodHandle, params M128[] param)
{
glActionQueue.Enqueue(methodHandle);
foreach (M128 item in param)
{
paramQueue.Enqueue(item);
}
glActionQueue.Enqueue(methodHandle);
}
}
}