daily update on 20231111 by nitload youmu

This commit is contained in:
Nitload
2023-11-11 17:12:37 +08:00
parent 26c7dafc2c
commit dac5f2455b
98 changed files with 10065 additions and 6029 deletions
+18 -25
View File
@@ -15,15 +15,14 @@ namespace StgSharp.Graphics
private int problemAPIcount = 0;
public unsafe IntPtr LoadGLfunc([MarshalAs(UnmanagedType.LPStr)] string name)
public unsafe IntPtr LoadGLfunc(string name)
{
string log = $"Attempt to load ";
IntPtr ret = InternalIO.glfw.GetProcAddress(name);
if (ret == default)
{
InternalIO.InternalWriteLog(
$"Cannot load OpenGL api called {name}, this api may not exist or supported.",
LogType.Warning);
InternalIO.InternalAppendLog(
$"Cannot load OpenGL api called {name}, this api may not exist or supported.");
missingAPIcount++;
return ret;
}
@@ -33,16 +32,13 @@ namespace StgSharp.Graphics
public unsafe void LoadGlapi()
{
GLcontext* context = (GLcontext*)InternalIO.internalCreatGLcontext(LoadGLfunc);
if ((ulong)context == 0)
{
throw new Exception($"Failed to load OpenGL api for current context \"{(ulong)glContext}\"");
}
InternalIO.InternalLoaderLoadGLapi(glContext, LoadGLfunc);
//check out if all api is converted correctely.
FieldInfo[] fieldInfos = typeof(GLcontext).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo[] target = typeof(GLcontext).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
string problemLog = "Have problem in converting the fallowing GL API to C# delegates:\n";
foreach (FieldInfo item in fieldInfos)
foreach (FieldInfo item in target)
{
if (item.FieldType.Name.Contains("PFNG"))
{
@@ -62,23 +58,23 @@ namespace StgSharp.Graphics
InternalIO.InternalWriteLog("Attempt to reload GL APIs", LogType.Info);
//use IntPtr as interface
GLcontextIO* iopack = (GLcontextIO*)context;
TypedReference contextref = __makeref(*glContext);
GLcontextIO* iopack = (GLcontextIO*)glContext;
TypedReference iosource = __makeref(*iopack);
FieldInfo[] source = typeof(GLcontextIO).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
foreach (FieldInfo item in source)
foreach (FieldInfo item in target)
{
if (item.FieldType.IsSubclassOf(typeof(Delegate))
&& item.GetValue(*context) == null)
&& item.GetValueDirect(contextref) == null)
{
IntPtr funcPtr = LoadGLfunc(item.Name);
if (funcPtr != IntPtr.Zero)
IntPtr proc = default;
proc = LoadGLfunc("gl" + item.Name);
if (proc != IntPtr.Zero)
{
try
{
Delegate dele = Marshal.GetDelegateForFunctionPointer(funcPtr, item.FieldType);
item.SetValue(*context, dele);
Delegate dele = Marshal.GetDelegateForFunctionPointer(proc, item.FieldType);
item.SetValueDirect(contextref, dele);
}
catch (Exception ex)
{
@@ -87,13 +83,10 @@ namespace StgSharp.Graphics
LogType.Error);
}
}
}
}
}
glContext = context;
GL.gl = glContext;
}