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
+17
View File
@@ -0,0 +1,17 @@
# Development Tools
This directory contains repository-maintenance and source-generation programs. Tools are kept outside `src` because they help build or maintain StgSharp but are not shipped as part of the runtime libraries.
## Directory map
| Directory | Purpose |
| --- | --- |
| `StgSharp.GenerateGL` | Reads the Khronos `gl.xml` registry, projects the OpenGL 4.6 Core API, analyzes function families, and generates the managed OpenGL bindings used by `StgSharp.Graphics`. |
`StgSharp.GenerateGL` has its own `README.md` with its pipeline, naming rules, and interactive commands. The common direct-generation command is:
```powershell
dotnet run --project tools/StgSharp.GenerateGL/StgSharp.GenerateGL.csproj -- generate src/StgSharp.Graphics/OpenGL/Generated
```
Generated files begin with `// <auto-generated>` and should not be edited manually. Change the registry projection, analysis, naming, or generation code here and regenerate the destination instead.
@@ -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,
@@ -86,6 +86,26 @@ namespace StgSharp.GenerateGL.Naming
.Replace(
"relativeoffset",
"relativeOffset",
StringComparison.Ordinal)
.Replace(
"pname",
"pName",
StringComparison.Ordinal)
.Replace(
"xoffset",
"xOffset",
StringComparison.Ordinal)
.Replace(
"yoffset",
"yOffset",
StringComparison.Ordinal)
.Replace(
"zoffset",
"zOffset",
StringComparison.Ordinal)
.Replace(
"vaobj",
"vertexArray",
StringComparison.Ordinal);
return _attributeParameterWord.Replace(result, "attribute");
}
+4 -1
View File
@@ -60,6 +60,7 @@ Generated files:
- `glconst.cs`: core constants;
- `OpenglContext.g.cs`: the function-pointer table with native names and ABI types;
- `glContextShadow.g.cs`: an identically ordered `nint` table used while loading native entry points;
- `OpenGLFunction.Base.g.cs`: APIs introduced through OpenGL 3.2 and retained in the target profile;
- `OpenGLFunction.v3_3.g.cs` through `OpenGLFunction.v4_6.g.cs`: APIs introduced by each later core version.
@@ -112,6 +113,9 @@ Safe lexical normalization applies to all public methods:
| `attribindex` | `attributeIndex` |
| `bindingindex` | `bindingIndex` |
| `relativeoffset` | `relativeOffset` |
| `pname` | `pName` |
| `xoffset` / `yoffset` / `zoffset` | `xOffset` / `yOffset` / `zOffset` |
| `vaobj` | `vertexArray` |
Families that represent distinct semantics receive explicit names:
@@ -154,4 +158,3 @@ The generator does not emit `<param>` or `<returns>` elements and does not copy
- `Naming/`: C# identifier and semantic-family naming policies;
- `XmlCli.cs`, `RegistryCli.cs`, and `FunctionFamilyCli.cs`: interactive inspection;
- `GenerateCli.cs`: in-memory preview and protected directory output.