WebGL2 rendering backend for DIR.Lib's
Renderer<TSurface>, hosted in Blazor WebAssembly. The browser sibling of
SdlVulkan.Renderer — same drawing
contract, same MTSDF text pipeline, same shared SdfFontAtlas core.
- Command-buffer interop, not chatty GL calls. Every
Renderermethod synchronously appends fixed-stride opcode records + raw vertex floats to in-memory streams (WebGlContext); onePresent()hands both to the JS shim (wwwroot/webgl-renderer.js) in a single[JSImport]call, and the shim replays them asgl.*calls. Atlas texture traffic rides a separateSyncAtlascall that fires only when glyph pages actually changed. - Text is our own rasterizer, end to end. Glyphs come from DIR.Lib's managed
ManagedFontRasterizeras MTSDF bitmaps, packed by the sharedSdfFontAtlascore (framesInFlight: 1,synchronousRasterize: truefor single-threaded WASM), uploaded viatexSubImage2D, and drawn with the samemedian()+ analytic-sdfEdgefragment shader as the desktop Vulkan renderer. No CSS fonts, no canvas text APIs. - The GL/Vulkan NDC Y-flip lives in the JS-side projection matrix — shader bodies are byte-identical ports of VkPipelineSet's GLSL.
- Pre-bake a
.sdfgglyph cache at build time (seeSdfGlyphDiskCache), fetch it into the WASM in-memory FS, and startup performs zero rasterization.
var renderer = await WebGlRenderer.CreateAsync("my-canvas", 760, 840);
renderer.Clear(background);
/* Renderer<WebGlContext> draw calls — FillRectangle, DrawText, ... */
renderer.Present();The JS shim ships as a static web asset (_content/WebGl.Renderer/webgl-renderer.js) — no
consumer wiring beyond the NuGet reference.
src/WebGl.Renderer.Tests runs headless on desktop .NET: command-stream encoding goldens,
shader-source sanity, and real-font text encoding over a fake JS bridge. Real-browser
compile/visual coverage happens in the consuming app (see the chess project's Chess.Web).