genericed graphic vector design

This commit is contained in:
Youmu Liu
2026-08-28 18:09:56 +08:00
parent 3cba929599
commit 0b2593a5f6
64 changed files with 1890 additions and 2229 deletions
@@ -80,6 +80,9 @@ namespace StgSharp.GenerateGL.Generation
new GeneratedFile(
"OpenglContext.g.cs",
GenerateContext(commands, typeMapper)),
new GeneratedFile(
"glContextShadow.g.cs",
GenerateContextShadow(commands)),
};
for (int index = 0; index < managedGroups.Count; index++)
{
@@ -329,11 +332,10 @@ namespace StgSharp.GenerateGL.Generation
AppendGeneratedHeader(builder, "Desktop OpenGL core function pointer table");
builder.Append("namespace StgSharp.Graphics.OpenGL\n");
builder.Append("{\n");
builder.Append(" [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]\n");
builder.Append(" public unsafe partial struct OpenglContext\n");
builder.Append(" {\n");
foreach (GlCommandDefinition command in commands.OrderBy(
value => value.Name,
StringComparer.Ordinal))
foreach (GlCommandDefinition command in OrderCommands(commands))
{
builder.Append(" internal delegate* unmanaged<");
foreach (GlParameterDefinition parameter in command.Parameters)
@@ -353,6 +355,38 @@ namespace StgSharp.GenerateGL.Generation
return builder.ToString();
}
private static string GenerateContextShadow(
IReadOnlyList<GlCommandDefinition> commands
)
{
StringBuilder builder = new StringBuilder(64 * 1024);
AppendGeneratedHeader(builder, "Native-address shadow of the OpenGL function pointer table");
builder.Append("namespace StgSharp.Graphics.OpenGL\n");
builder.Append("{\n");
builder.Append(" [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]\n");
builder.Append(" internal struct glContextShadow\n");
builder.Append(" {\n");
foreach (GlCommandDefinition command in OrderCommands(commands))
{
builder.Append(" internal nint ");
builder.Append(command.Name);
builder.Append(";\n");
}
builder.Append(" }\n");
builder.Append("}\n");
return builder.ToString();
}
private static IEnumerable<GlCommandDefinition> OrderCommands(
IReadOnlyList<GlCommandDefinition> commands
)
{
return commands.OrderBy(
value => value.Name,
StringComparer.Ordinal);
}
private static string GenerateFunctions(
IReadOnlyList<ManagedMethodDefinition> methods,
string description,