diff --git a/源代码/.vs/ProjectEvaluation/stgsharpdevelop.metadata.v7.bin b/源代码/.vs/ProjectEvaluation/stgsharpdevelop.metadata.v7.bin index c79a967d..144b224c 100644 Binary files a/源代码/.vs/ProjectEvaluation/stgsharpdevelop.metadata.v7.bin and b/源代码/.vs/ProjectEvaluation/stgsharpdevelop.metadata.v7.bin differ diff --git a/源代码/.vs/ProjectEvaluation/stgsharpdevelop.projects.v7.bin b/源代码/.vs/ProjectEvaluation/stgsharpdevelop.projects.v7.bin index cd84aafa..494ff2aa 100644 Binary files a/源代码/.vs/ProjectEvaluation/stgsharpdevelop.projects.v7.bin and b/源代码/.vs/ProjectEvaluation/stgsharpdevelop.projects.v7.bin differ diff --git a/源代码/.vs/StgSharpDevelop/DesignTimeBuild/.dtbcache.v2 b/源代码/.vs/StgSharpDevelop/DesignTimeBuild/.dtbcache.v2 index 8ed00bcf..49c84181 100644 Binary files a/源代码/.vs/StgSharpDevelop/DesignTimeBuild/.dtbcache.v2 and b/源代码/.vs/StgSharpDevelop/DesignTimeBuild/.dtbcache.v2 differ diff --git a/源代码/.vs/StgSharpDevelop/FileContentIndex/08bcfdd4-276b-424e-b2af-8e784bf74dd7.vsidx b/源代码/.vs/StgSharpDevelop/FileContentIndex/08bcfdd4-276b-424e-b2af-8e784bf74dd7.vsidx new file mode 100644 index 00000000..033ee35d Binary files /dev/null and b/源代码/.vs/StgSharpDevelop/FileContentIndex/08bcfdd4-276b-424e-b2af-8e784bf74dd7.vsidx differ diff --git a/源代码/.vs/StgSharpDevelop/FileContentIndex/816e2b85-238a-4758-b4e4-636e6b010bf4.vsidx b/源代码/.vs/StgSharpDevelop/FileContentIndex/816e2b85-238a-4758-b4e4-636e6b010bf4.vsidx new file mode 100644 index 00000000..993af607 Binary files /dev/null and b/源代码/.vs/StgSharpDevelop/FileContentIndex/816e2b85-238a-4758-b4e4-636e6b010bf4.vsidx differ diff --git a/源代码/.vs/StgSharpDevelop/FileContentIndex/ab381359-0f74-4688-8524-1394cc646ca2.vsidx b/源代码/.vs/StgSharpDevelop/FileContentIndex/ab381359-0f74-4688-8524-1394cc646ca2.vsidx deleted file mode 100644 index 9137c64b..00000000 Binary files a/源代码/.vs/StgSharpDevelop/FileContentIndex/ab381359-0f74-4688-8524-1394cc646ca2.vsidx and /dev/null differ diff --git a/源代码/.vs/StgSharpDevelop/FileContentIndex/b581d321-5c55-4b87-971a-7c8d487112fe.vsidx b/源代码/.vs/StgSharpDevelop/FileContentIndex/b581d321-5c55-4b87-971a-7c8d487112fe.vsidx deleted file mode 100644 index 7ba9c3f9..00000000 Binary files a/源代码/.vs/StgSharpDevelop/FileContentIndex/b581d321-5c55-4b87-971a-7c8d487112fe.vsidx and /dev/null differ diff --git a/源代码/.vs/StgSharpDevelop/FileContentIndex/c1100f01-f137-4a5f-8cdf-0d75e4298590.vsidx b/源代码/.vs/StgSharpDevelop/FileContentIndex/c1100f01-f137-4a5f-8cdf-0d75e4298590.vsidx new file mode 100644 index 00000000..8eeacc50 Binary files /dev/null and b/源代码/.vs/StgSharpDevelop/FileContentIndex/c1100f01-f137-4a5f-8cdf-0d75e4298590.vsidx differ diff --git a/源代码/.vs/StgSharpDevelop/FileContentIndex/e44676b3-3b9e-43be-b83f-9bd614ff5355.vsidx b/源代码/.vs/StgSharpDevelop/FileContentIndex/c39bbd2d-3c5e-4617-8a2f-57433dcc6fb3.vsidx similarity index 64% rename from 源代码/.vs/StgSharpDevelop/FileContentIndex/e44676b3-3b9e-43be-b83f-9bd614ff5355.vsidx rename to 源代码/.vs/StgSharpDevelop/FileContentIndex/c39bbd2d-3c5e-4617-8a2f-57433dcc6fb3.vsidx index 93b661eb..abea8f4b 100644 Binary files a/源代码/.vs/StgSharpDevelop/FileContentIndex/e44676b3-3b9e-43be-b83f-9bd614ff5355.vsidx and b/源代码/.vs/StgSharpDevelop/FileContentIndex/c39bbd2d-3c5e-4617-8a2f-57433dcc6fb3.vsidx differ diff --git a/源代码/.vs/StgSharpDevelop/FileContentIndex/cf700889-bd68-425b-9302-5f42980a13e8.vsidx b/源代码/.vs/StgSharpDevelop/FileContentIndex/cf700889-bd68-425b-9302-5f42980a13e8.vsidx deleted file mode 100644 index 6258490e..00000000 Binary files a/源代码/.vs/StgSharpDevelop/FileContentIndex/cf700889-bd68-425b-9302-5f42980a13e8.vsidx and /dev/null differ diff --git a/源代码/.vs/StgSharpDevelop/FileContentIndex/ef9ec330-67c5-4a9b-b34a-0e9bbb90b630.vsidx b/源代码/.vs/StgSharpDevelop/FileContentIndex/ef9ec330-67c5-4a9b-b34a-0e9bbb90b630.vsidx deleted file mode 100644 index 4c3e0fa3..00000000 Binary files a/源代码/.vs/StgSharpDevelop/FileContentIndex/ef9ec330-67c5-4a9b-b34a-0e9bbb90b630.vsidx and /dev/null differ diff --git a/源代码/.vs/StgSharpDevelop/FileContentIndex/f208a6ac-ee12-4f28-ae4d-390ed8b542c9.vsidx b/源代码/.vs/StgSharpDevelop/FileContentIndex/f208a6ac-ee12-4f28-ae4d-390ed8b542c9.vsidx new file mode 100644 index 00000000..1a57f948 Binary files /dev/null and b/源代码/.vs/StgSharpDevelop/FileContentIndex/f208a6ac-ee12-4f28-ae4d-390ed8b542c9.vsidx differ diff --git a/源代码/.vs/StgSharpDevelop/v17/.futdcache.v2 b/源代码/.vs/StgSharpDevelop/v17/.futdcache.v2 index a6cacbb3..66141ba4 100644 Binary files a/源代码/.vs/StgSharpDevelop/v17/.futdcache.v2 and b/源代码/.vs/StgSharpDevelop/v17/.futdcache.v2 differ diff --git a/源代码/.vs/StgSharpDevelop/v17/.suo b/源代码/.vs/StgSharpDevelop/v17/.suo index c231d05d..727dc529 100644 Binary files a/源代码/.vs/StgSharpDevelop/v17/.suo and b/源代码/.vs/StgSharpDevelop/v17/.suo differ diff --git a/源代码/.vs/StgSharpDevelop/v17/Browse.VC.db b/源代码/.vs/StgSharpDevelop/v17/Browse.VC.db index d4ad0b15..6de08835 100644 Binary files a/源代码/.vs/StgSharpDevelop/v17/Browse.VC.db and b/源代码/.vs/StgSharpDevelop/v17/Browse.VC.db differ diff --git a/源代码/BenchMark/Program.cs b/源代码/BenchMark/Program.cs index 29f1a90b..185e6656 100644 --- a/源代码/BenchMark/Program.cs +++ b/源代码/BenchMark/Program.cs @@ -14,32 +14,16 @@ namespace BenchMark static void Main(string[] args) { - Calculator c = new Calculator(); - c.PtrSub(); - var sum = BenchmarkRunner.Run(typeof(Calculator).Assembly); + uint[] array = new uint[] { 0, 10, 2, 3 }; + + fixed (uint* ptr = array) + { + IntPtr p = (IntPtr)ptr; + Console.WriteLine(*((uint*)p + 1)); + } + } } - public struct Calculator - { - public static int Sub(int left, int right) - { - return left - right; - } - - [Benchmark] - public unsafe void DeleSub() - { - Func SubDele = Sub; - SubDele(1, 0); - } - - [Benchmark] - public unsafe void PtrSub() - { - delegate* SubPtr = ⋐ - SubPtr(1, 0); - } - } } \ No newline at end of file diff --git a/源代码/BenchMark/bin/Release/net6.0/BenchMark.dll b/源代码/BenchMark/bin/Release/net6.0/BenchMark.dll index d44e7e46..6fe78566 100644 Binary files a/源代码/BenchMark/bin/Release/net6.0/BenchMark.dll and b/源代码/BenchMark/bin/Release/net6.0/BenchMark.dll differ diff --git a/源代码/BenchMark/bin/Release/net6.0/BenchMark.exe b/源代码/BenchMark/bin/Release/net6.0/BenchMark.exe index a6611d5f..9403f766 100644 Binary files a/源代码/BenchMark/bin/Release/net6.0/BenchMark.exe and b/源代码/BenchMark/bin/Release/net6.0/BenchMark.exe differ diff --git a/源代码/BenchMark/bin/Release/net6.0/BenchMark.pdb b/源代码/BenchMark/bin/Release/net6.0/BenchMark.pdb index 547bc56e..ceb6515c 100644 Binary files a/源代码/BenchMark/bin/Release/net6.0/BenchMark.pdb and b/源代码/BenchMark/bin/Release/net6.0/BenchMark.pdb differ diff --git a/源代码/BenchMark/obj/Release/net6.0/BenchMark.AssemblyInfo.cs b/源代码/BenchMark/obj/Release/net6.0/BenchMark.AssemblyInfo.cs index 1d74aa5f..0271213e 100644 --- a/源代码/BenchMark/obj/Release/net6.0/BenchMark.AssemblyInfo.cs +++ b/源代码/BenchMark/obj/Release/net6.0/BenchMark.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("BenchMark")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Release")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5d778e0f2f6e677453cebc990919697968c771f9")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8548757bbf17cb04ef554babef5b140fd02c1f53")] [assembly: System.Reflection.AssemblyProductAttribute("BenchMark")] [assembly: System.Reflection.AssemblyTitleAttribute("BenchMark")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/源代码/BenchMark/obj/Release/net6.0/BenchMark.AssemblyInfoInputs.cache b/源代码/BenchMark/obj/Release/net6.0/BenchMark.AssemblyInfoInputs.cache index 6f06c4c5..97f47a6f 100644 --- a/源代码/BenchMark/obj/Release/net6.0/BenchMark.AssemblyInfoInputs.cache +++ b/源代码/BenchMark/obj/Release/net6.0/BenchMark.AssemblyInfoInputs.cache @@ -1 +1 @@ -a69f4baa1be073def38e9acf0067382f3fca5213a8a52e99918a4b8263c622a4 +82cb96ae7382da519b6703c815654474e1b0440eedcbbdfb523d786d8786efff diff --git a/源代码/BenchMark/obj/Release/net6.0/BenchMark.dll b/源代码/BenchMark/obj/Release/net6.0/BenchMark.dll index d44e7e46..6fe78566 100644 Binary files a/源代码/BenchMark/obj/Release/net6.0/BenchMark.dll and b/源代码/BenchMark/obj/Release/net6.0/BenchMark.dll differ diff --git a/源代码/BenchMark/obj/Release/net6.0/BenchMark.pdb b/源代码/BenchMark/obj/Release/net6.0/BenchMark.pdb index 547bc56e..ceb6515c 100644 Binary files a/源代码/BenchMark/obj/Release/net6.0/BenchMark.pdb and b/源代码/BenchMark/obj/Release/net6.0/BenchMark.pdb differ diff --git a/源代码/BenchMark/obj/Release/net6.0/BenchMark.sourcelink.json b/源代码/BenchMark/obj/Release/net6.0/BenchMark.sourcelink.json index 0fffb972..27ffda5d 100644 --- a/源代码/BenchMark/obj/Release/net6.0/BenchMark.sourcelink.json +++ b/源代码/BenchMark/obj/Release/net6.0/BenchMark.sourcelink.json @@ -1 +1 @@ -{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/5d778e0f2f6e677453cebc990919697968c771f9/*"}} \ No newline at end of file +{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/8548757bbf17cb04ef554babef5b140fd02c1f53/*"}} \ No newline at end of file diff --git a/源代码/BenchMark/obj/Release/net6.0/apphost.exe b/源代码/BenchMark/obj/Release/net6.0/apphost.exe index a6611d5f..9403f766 100644 Binary files a/源代码/BenchMark/obj/Release/net6.0/apphost.exe and b/源代码/BenchMark/obj/Release/net6.0/apphost.exe differ diff --git a/源代码/BenchMark/obj/Release/net6.0/ref/BenchMark.dll b/源代码/BenchMark/obj/Release/net6.0/ref/BenchMark.dll index 265d0d40..f358582a 100644 Binary files a/源代码/BenchMark/obj/Release/net6.0/ref/BenchMark.dll and b/源代码/BenchMark/obj/Release/net6.0/ref/BenchMark.dll differ diff --git a/源代码/BenchMark/obj/Release/net6.0/refint/BenchMark.dll b/源代码/BenchMark/obj/Release/net6.0/refint/BenchMark.dll index 265d0d40..f358582a 100644 Binary files a/源代码/BenchMark/obj/Release/net6.0/refint/BenchMark.dll and b/源代码/BenchMark/obj/Release/net6.0/refint/BenchMark.dll differ diff --git a/源代码/StgSharp/Graphics/GL/Buffer/texture.cs b/源代码/StgSharp/Graphics/GL/Buffer/texture.cs index 25a5d83d..11d296c9 100644 --- a/源代码/StgSharp/Graphics/GL/Buffer/texture.cs +++ b/源代码/StgSharp/Graphics/GL/Buffer/texture.cs @@ -13,13 +13,13 @@ namespace StgSharp.Graphics public unsafe class Texture { internal static bool[] unitActivated = new bool[16]; - internal glHandle _textureHandle; + internal glHandleSet _textureHandle; internal Image[] sourceList; private IglFunc GL; internal Texture(uint n, IglFunc gl) { - _textureHandle = new glHandle((int)n); + _textureHandle = new glHandleSet((int)n); sourceList = new Image[n]; GL = gl; GL.GenTextures(n, _textureHandle); diff --git a/源代码/StgSharp/Graphics/GL/GLhandle.cs b/源代码/StgSharp/Graphics/GL/GLhandle.cs index d28a24dd..8ecb6981 100644 --- a/源代码/StgSharp/Graphics/GL/GLhandle.cs +++ b/源代码/StgSharp/Graphics/GL/GLhandle.cs @@ -21,20 +21,57 @@ namespace System public unsafe struct glHandle { internal uint* valuePtr; + internal glHandleSet source; public glHandle() { throw new InvalidOperationException(); } - internal glHandle(uint* val) + public static glHandle Alloc(uint value) { + glHandle ret = default; + ret.source = new glHandleSet(1); + *ret.valuePtr = value; + return ret; + } + + internal glHandle(uint* val, glHandleSet set) + { + source = set; valuePtr = val; } + public IntPtr Handle + { + get + { + if (source.handle == (uint*)0) + { + throw new InvalidOperationException($"Handle set {nameof(source)} is not pinned."); + } + return (IntPtr)valuePtr; + } + } + public uint Value { - get { return *valuePtr; } + 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; + } } } @@ -56,10 +93,11 @@ namespace System { throw new IndexOutOfRangeException(); } - return new glHandle(handle + index); + return new glHandle(handle + index, this); } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetValue(int index, uint value) { @@ -85,6 +123,7 @@ namespace System } GCHandle h = GCHandle.FromIntPtr((IntPtr)handle); h.Free(); + handle = (uint*)0; } public void Pin() diff --git a/源代码/StgSharp/Graphics/GL/GLonRender.cs b/源代码/StgSharp/Graphics/GL/GLonRender.cs index 54a1df40..2af1feb0 100644 --- a/源代码/StgSharp/Graphics/GL/GLonRender.cs +++ b/源代码/StgSharp/Graphics/GL/GLonRender.cs @@ -52,12 +52,13 @@ namespace StgSharp.Graphics [MethodImpl(MethodImplOptions.AggressiveInlining)] void IglFunc.AttachShader(glHandle program, glHandle shader) { - api->glAttachShader(program.value, shader.value); + api->glAttachShader(*program.valuePtr, *shader.valuePtr); } - void IglFunc.BindBuffer(BufferType bufferType, uint index) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + void IglFunc.BindBuffer(BufferType bufferType, glHandle handle) { - api->glBindBuffer((uint)bufferType, index); + api->glBindBuffer((uint)bufferType, *handle.valuePtr); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -67,9 +68,9 @@ namespace StgSharp.Graphics } [MethodImpl(MethodImplOptions.AggressiveInlining)] - void IglFunc.BindVertexArray(uint index) + void IglFunc.BindVertexArray(glHandle handle) { - api->glBindVertexArray(index); + api->glBindVertexArray(handle.Value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -90,61 +91,73 @@ namespace StgSharp.Graphics while (api->glGetError() != 0) { } } - glHandle IglFunc.CompileShader(string shaderCode, ShaderType shaderType) + glHandleSet IglFunc.CompileShader(ShaderType shaderType, params string[] shaderCodeArray) { - uint shaderID; - shaderCode += '\0'; - shaderID = InternalIO.InternalLoadShaderCode(shaderCode, (int)shaderType); - if (shaderID == 0) //compile error handler + int l = shaderCodeArray.Length; + if (l == 0) { - IntPtr logPtr = InternalIO.InternalReadLog(); - string log; - try + throw new ArgumentException("At least one pice of code is required."); + } + glHandleSet handleSet = new glHandleSet(l); + for (int i = 0; i < l; i++) + { + uint shaderID; + byte[] data = Encoding.UTF8.GetBytes(shaderCodeArray[i] + '\0'); + fixed (byte* codePtr = data) { - byte[] logByte = new byte[512]; - Marshal.Copy(logPtr, logByte, 0, 512); - log = Encoding.UTF8.GetString(logByte); - log = log.Replace("\0", ""); - - bool isUseful = false; - foreach (char item in log) + shaderID = InternalIO.InternalLoadShaderCode(codePtr, (int)shaderType); + } + if (shaderID == 0) //compile error handler + { + IntPtr logPtr = InternalIO.InternalReadLog(); + string log; + try { - if (!char.IsControl(item)) + byte[] logByte = new byte[512]; + Marshal.Copy(logPtr, logByte, 0, 512); + log = Encoding.UTF8.GetString(logByte); + log = log.Replace("\0", ""); + + bool isUseful = false; + foreach (char item in log) { - isUseful = true; break; + if (!char.IsControl(item)) + { + isUseful = true; break; + } + } + if (!isUseful) + { + throw new Exception(); } } - if (!isUseful) + catch (Exception) { - throw new Exception(); + log = "Failed to compile shader.\n" + + "Failed to get GLSL compiler log"; } - } - catch (Exception) - { - log = "Failed to compile shader.\n" + - "Failed to get GLSL compiler log"; - } - InternalIO.InternalWriteLog(log, LogType.Error); + InternalIO.InternalWriteLog(log, LogType.Error); + } + handleSet.SetValue(i, shaderID); } - return new glHandle(shaderID); + return handleSet; } [MethodImpl(MethodImplOptions.AggressiveInlining)] glHandle IglFunc.CreateProgram() { - return new glHandle(api->glCreateProgram()); + return glHandle.Alloc(api->glCreateProgram()); } [MethodImpl(MethodImplOptions.AggressiveInlining)] unsafe glHandleSet IglFunc.CreateProgram(int count) { glHandleSet h = new glHandleSet(count); - glHandle* p = h.handle; for (int i = 0; i < count; i++) { - *(p + i) = api->glCreateProgram(); + h.SetValue(i, api->glCreateProgram()); } return h; } @@ -178,7 +191,7 @@ namespace StgSharp.Graphics [MethodImpl(MethodImplOptions.AggressiveInlining)] unsafe glHandle IglFunc.CreatGraphicProgram() { - return new glHandle(api->glCreateProgram()); + return glHandle.Alloc(api->glCreateProgram()); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -260,7 +273,7 @@ namespace StgSharp.Graphics } catch (Exception ex) { - /* + /**/ InternalIO.InternalWriteLog( error + ex.StackTrace, LogType.Error diff --git a/源代码/StgSharp/Graphics/GL/GLonTimeout.cs b/源代码/StgSharp/Graphics/GL/GLonTimeout.cs index 554b2e3d..7e6cf666 100644 --- a/源代码/StgSharp/Graphics/GL/GLonTimeout.cs +++ b/源代码/StgSharp/Graphics/GL/GLonTimeout.cs @@ -27,11 +27,11 @@ namespace StgSharp.Graphics void IglFunc.AttachShader(glHandle program, glHandle shader) => throw signal; - void IglFunc.BindBuffer(BufferType bufferType, uint index) => throw signal; + void IglFunc.BindBuffer(BufferType bufferType, glHandle handle) => throw signal; void IglFunc.BindTexture(uint type, uint texture) => throw signal; - void IglFunc.BindVertexArray(uint index) => throw signal; + void IglFunc.BindVertexArray(glHandle handle) => throw signal; void IglFunc.Clear(MaskBufferBit mask) => throw signal; @@ -51,7 +51,7 @@ namespace StgSharp.Graphics glHandle IglFunc.CreatGraphicProgram() => throw signal; - public void DeleteBuffer(uint handle) => throw signal; + void IglFunc.DeleteBuffer(glHandle handle) => throw signal; void IglFunc.DeleteBuffers(glHandleSet handle) => throw signal; diff --git a/源代码/StgSharp/Graphics/GL/GLonUpdate.cs b/源代码/StgSharp/Graphics/GL/GLonUpdate.cs index 0921d829..dcbbfc80 100644 --- a/源代码/StgSharp/Graphics/GL/GLonUpdate.cs +++ b/源代码/StgSharp/Graphics/GL/GLonUpdate.cs @@ -67,40 +67,39 @@ namespace StgSharp.Graphics } [MethodImpl(MethodImplOptions.AggressiveInlining)] - void IglFunc.BindBuffer(BufferType bufferType, uint index) + void IglFunc.BindBuffer(BufferType bufferType, glHandle handle) { - paramQueue.Enqueue((uint)bufferType, index); - glActionQueue.Enqueue(BindBufferPtr - ); + M128 m = default; + m.UInt32[0] = (uint)bufferType; + m.IntPtr1 = handle.Handle; + paramQueue.Enqueue(m); + glActionQueue.Enqueue(BindBufferPtr); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void IglFunc.BindTexture(uint type, uint texture) { - glActionQueue.Enqueue( - () => api->glBindTexture((uint)type, texture) - ); + paramQueue.Enqueue(type, texture); + glActionQueue.Enqueue(BindTexturePtr); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - void IglFunc.BindVertexArray(uint index) + void IglFunc.BindVertexArray(glHandle index) { - glActionQueue.Enqueue( - () => api->glBindVertexArray((uint)index) - ); + paramQueue.Enqueue(index); + glActionQueue.Enqueue(BindVertexArrayPtr); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void IglFunc.Clear(MaskBufferBit mask) { - glActionQueue.Enqueue( - () => api->glClear((uint)mask) - ); + glActionQueue.Enqueue(ClearPtr); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void IglFunc.ClearColor(float R, float G, float B, float A) { + paramQueue.Enqueue(R, G, B, A); glActionQueue.Enqueue(ClearColorPtr); } @@ -138,21 +137,22 @@ namespace StgSharp.Graphics [MethodImpl(MethodImplOptions.AggressiveInlining)] glHandle IglFunc.CreateProgram() { - glHandle h = new glHandle(1); - glActionQueue.Enqueue( - () => - { - int ret = (int)api->glCreateProgram(); - Interlocked.Add(ref id, ret + 1); - } - ); + glHandle h = glHandle.Alloc(1); + paramQueue.Enqueue(h); + glActionQueue.Enqueue(CreateProgramPtr); return h; } [MethodImpl(MethodImplOptions.AggressiveInlining)] glHandleSet IglFunc.CreateProgram(int count) { - throw new NotImplementedException(); + M128 m = default; + glHandleSet h = new glHandleSet(count); + m.IntPtr0 = (IntPtr)h.handle; + m.Int32[2] = count; + paramQueue.Enqueue(m); + glActionQueue.Enqueue(CreateProgramSetPtr); + return h; } IntPtr IglFunc.CreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share) @@ -184,42 +184,31 @@ namespace StgSharp.Graphics [MethodImpl(MethodImplOptions.AggressiveInlining)] glHandle IglFunc.CreatGraphicProgram() { - glHandle h = new glHandle(1); - glActionQueue.Enqueue( - () => - { - Interlocked.Add(ref id, (int)(api->glCreateProgram() + 1)); - } - ); + glHandle h = glHandle.Alloc(1); + paramQueue.Enqueue(h); + glActionQueue.Enqueue(CreateProgramPtr); return h; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - unsafe void IglFunc.DeleteBuffer(uint handle) + unsafe void IglFunc.DeleteBuffer(glHandle handle) { - glActionQueue.Enqueue( - () => - { - uint target = handle; - api->glDeleteBuffers(1, &target); - } - ); + M128 m = new M128() { IntPtr0 = handle.Handle }; + m.UInt32[2] = 1; + paramQueue.Enqueue(m); + glActionQueue.Enqueue(DeleBufferPtr); } unsafe void IglFunc.DeleteBuffers(glHandleSet handle) { - glActionQueue.Enqueue( - () => - { - uint[] h = handle; - fixed (uint* p = h) - { - api->glDeleteBuffers(count, p); - } - } - ); + M128 m = default; + m.UInt32[2] = (uint)handle.length; + m.IntPtr0 = (IntPtr)handle.handle; + paramQueue.Enqueue(m); + glActionQueue.Enqueue(DeleBufferPtr); } + //TODO: 从这里开始 unsafe void IglFunc.DeleteVertexArrays(glHandleSet arrays) { glActionQueue.Enqueue( diff --git a/源代码/StgSharp/Graphics/GL/GLonUpdateInternal.cs b/源代码/StgSharp/Graphics/GL/GLonUpdateInternal.cs index a7ec9523..9db32368 100644 --- a/源代码/StgSharp/Graphics/GL/GLonUpdateInternal.cs +++ b/源代码/StgSharp/Graphics/GL/GLonUpdateInternal.cs @@ -19,6 +19,8 @@ namespace StgSharp.Graphics internal IntPtr ClearColorPtr = (IntPtr)(delegate*)&InternalClearColor; internal IntPtr ClearGraphicErrorPtr = (IntPtr)(delegate*)&InternalClearGraphicError; internal IntPtr CompileShaderPtr = (IntPtr)(delegate*)&InternalCompileShader; + IntPtr BindTexturePtr = (IntPtr)(delegate*)&InternalBindTexture; + IntPtr BindVertexArrayPtr = (IntPtr)(delegate*)&InternalBindVertexArray; private IntPtr ClearPtr = (IntPtr)(delegate*)&InternalClear; private static void InternalActiveTexture() @@ -37,9 +39,23 @@ namespace StgSharp.Graphics private static void InternalBindBuffer() { - uint t, i; - paramQueue.TryDequeue(out t, out i); - paramQueue.context->glBindBuffer(t, i); + M128 m = default; + paramQueue.TryDequeue(out m); + paramQueue.context->glBindBuffer(m.UInt32[0], *(uint*)m.IntPtr1); + } + + private static void InternalBindTexture() + { + uint t, te; + paramQueue.TryDequeue(out t, out te); + paramQueue.context->glBindTexture(t, te); + } + + private static void InternalBindVertexArray() + { + IntPtr i; + paramQueue.TryDequeue(out i); + paramQueue.context->glBindVertexArray(*(uint*)i); } private static void InternalClear() @@ -115,51 +131,35 @@ namespace StgSharp.Graphics throw new NotImplementedException(); } - private void InternalBindTexture(uint type, uint texture) - { - uint t, te; - paramQueue.TryDequeue(out t, out te); - paramQueue.context->glBindTexture(t, te); - } - - private void InternalBindVertexArray(uint index) - { - uint i; - paramQueue.TryDequeue(out i); - paramQueue.context->glBindVertexArray(i); - } - - private glHandle InternalCreateProgram() + IntPtr CreateProgramPtr = (IntPtr)(delegate*)&InternalCreateProgram; + private static void InternalCreateProgram() { IntPtr programHandle = default; paramQueue.TryDequeue(out programHandle); *(uint*)programHandle = paramQueue.context->glCreateProgram(); - return default; } - private glHandleSet InternalCreateProgram(int count) + + IntPtr CreateProgramSetPtr = (IntPtr)(delegate*)&InternalCreateProgramSet; + private static void InternalCreateProgramSet() { - throw new NotImplementedException(); + IntPtr programHandle; + M128 m = default; + paramQueue.TryDequeue(out m); + programHandle = m.IntPtr0; + for (int i = 0; i < m.Int32[2]; i++) + { + *((uint*)programHandle + i) = paramQueue.context->glCreateProgram(); + } } - private IntPtr InternalCreateWindowHandle(int width, int height, string tittle, IntPtr monitor, Form share) - { - throw new NotImplementedException(); - } + internal IntPtr DeleBufferPtr = (IntPtr)(delegate*)&InternalDeleteBuffer; - private glHandle InternalCreatGraphicProgram() + private static void InternalDeleteBuffer() { - throw new NotImplementedException(); - } - - private void InternalDeleteBuffer(uint handle) - { - throw new NotImplementedException(); - } - - private void InternalDeleteBuffers(glHandleSet handle) - { - throw new NotImplementedException(); + M128 m = default; + paramQueue.TryDequeue(out m); + paramQueue.context->glDeleteBuffers(m.UInt32[2], (uint*)m.IntPtr0); } private void InternalDeleteVertexArrays(glHandleSet arrays) diff --git a/源代码/StgSharp/Graphics/IglFunc.cs b/源代码/StgSharp/Graphics/IglFunc.cs index a1afda27..34cc5548 100644 --- a/源代码/StgSharp/Graphics/IglFunc.cs +++ b/源代码/StgSharp/Graphics/IglFunc.cs @@ -45,12 +45,13 @@ namespace StgSharp.Graphics /// A shader part to attach void AttachShader(glHandle program, glHandle shader); + //TODO:BindBuffer注释没写完 /// /// Bind the indexed buffer object to certain type of buffer /// /// - /// - void BindBuffer(BufferType bufferType, uint index); + /// + void BindBuffer(BufferType bufferType, glHandle handle); /// /// Same function as OpenGL api, glBindTexture. @@ -63,7 +64,7 @@ namespace StgSharp.Graphics /// Same function as OpenGL api, glBindVertexArray /// /// - void BindVertexArray(uint index); + void BindVertexArray(glHandle index); /// /// Clear buffers to preset values @@ -87,11 +88,11 @@ namespace StgSharp.Graphics /// /// Conpile the provided shader code in string form. /// - /// A string represent the shader's code + /// A string array contains all shaders' code /// An enum represent the type of the shader to /// conpile, including vertex shader and fragment shader. /// An handle of conpiled shader - glHandleSet CompileShader(ShaderType shaderType, params string[] shaderCode); + glHandleSet CompileShader(ShaderType shaderType, params string[] shaderCodeArray); /// /// Same function as OpenGL api, glCreateProgram @@ -123,7 +124,7 @@ namespace StgSharp.Graphics /// Same function as OpenGL api, glDeleteBuffer. This method can delete one buffer in one call /// /// a handle representing the buffer to be deleted - unsafe void DeleteBuffer(uint handle); + void DeleteBuffer(glHandle handle); /// /// Same function as OpenGL api, glDeleteBuffer. This method can delete a sets of buffers in one call. diff --git a/源代码/StgSharp/Logic/glParamQueue.cs b/源代码/StgSharp/Logic/glParamQueue.cs index 9cf496dc..700b12ef 100644 --- a/源代码/StgSharp/Logic/glParamQueue.cs +++ b/源代码/StgSharp/Logic/glParamQueue.cs @@ -28,6 +28,12 @@ namespace StgSharp.Logic paramQueue.Enqueue(v); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Enqueue(M128 m) + { + paramQueue.Enqueue(m); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(uint u0) { @@ -81,21 +87,6 @@ namespace StgSharp.Logic paramQueue.Enqueue(m); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void TryDequeue(out glHandle handle) - { - M128 ret; - if (paramQueue.TryDequeue(out ret)) - { - handle.valuePtr = (uint*)ret.IntPtr0; - } - else - { - InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error); - throw new Exception(); - } - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(glHandle handle, glHandle handle1) { @@ -105,22 +96,6 @@ namespace StgSharp.Logic paramQueue.Enqueue(m); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void TryDequeue(out glHandle handle, out glHandle handle1) - { - M128 ret; - if (paramQueue.TryDequeue(out ret)) - { - handle.valuePtr = (uint*)ret.IntPtr0; - handle1.valuePtr = (uint*)ret.IntPtr1; - } - else - { - InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error); - throw new Exception(); - } - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(int i0) { @@ -159,6 +134,40 @@ namespace StgSharp.Logic paramQueue.Enqueue(m); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void TryDequeue(out M128 m) + { + paramQueue.TryDequeue(out m); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void TryDequeue(out glHandle handle) + { + M128 ret; + if (paramQueue.TryDequeue(out ret)) + { + handle.valuePtr = (uint*)ret.IntPtr0; + } + else + { + InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error); + throw new Exception(); + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void TryDequeue(out glHandle handle, out glHandle handle1) + { + M128 ret; + if (paramQueue.TryDequeue(out ret)) + { + handle.valuePtr = (uint*)ret.IntPtr0; + handle1.valuePtr = (uint*)ret.IntPtr1; + } + else + { + InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error); + throw new Exception(); + } + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void TryDequeue(out int i0) { diff --git a/源代码/StgSharpDebug/obj/x64/Benchmark/net6.0/StgSharpDebug.AssemblyInfo.cs b/源代码/StgSharpDebug/obj/x64/Benchmark/net6.0/StgSharpDebug.AssemblyInfo.cs index 6d8cc99e..98e39ef1 100644 --- a/源代码/StgSharpDebug/obj/x64/Benchmark/net6.0/StgSharpDebug.AssemblyInfo.cs +++ b/源代码/StgSharpDebug/obj/x64/Benchmark/net6.0/StgSharpDebug.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Benchmark")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5d778e0f2f6e677453cebc990919697968c771f9")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] [assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/源代码/StgSharpDebug/obj/x64/Benchmark/net6.0/StgSharpDebug.AssemblyInfoInputs.cache b/源代码/StgSharpDebug/obj/x64/Benchmark/net6.0/StgSharpDebug.AssemblyInfoInputs.cache index 604a21d1..eb493cd1 100644 --- a/源代码/StgSharpDebug/obj/x64/Benchmark/net6.0/StgSharpDebug.AssemblyInfoInputs.cache +++ b/源代码/StgSharpDebug/obj/x64/Benchmark/net6.0/StgSharpDebug.AssemblyInfoInputs.cache @@ -1 +1 @@ -064c7856d60414ec06cfa2c8f7e2587373d5fb684c182dbac647ea2ac6067752 +e340c06b75b4a2ce53efde5f4632c7a375a08a6b1987e3663da0e443a4eb16a3