How alphapixel/slughorn works
Purpose and Deployment Boundary
slughorn is a C++20, graphics-API-agnostic vector-content preparation library implementing the Slug GPU vector-rendering technique. It converts authored or imported curves into GPU-uploadable atlas data; host applications own shaders, GPU resources, and drawing. Public aggregation and implementation are centered in slughorn/slughorn.hpp and slughorn/slughorn.cpp. CMake builds the library and optional integrations via CMakeLists.txt.
Entry Points
Native consumers include slughorn/slughorn.hpp plus focused backend headers. A Canvas-inspired authoring API begins at slughorn/canvas.hpp. Python/offline processing is exposed through pybind11 binding units rooted at ext/python/slughorn.cpp and ext/python/slughorn-python.hpp. Command-line launchers are supplied as bin/slughorn, bin/slughorn-msdf, and bin/slughorned.
Unified Shape Model and GPU Handoff
The core model represents curves, shapes, layered composite shapes, fills, masks, and rendering metadata in the unified source of truth. slughorn/slughorn.hpp defines the central API/model, while slughorn/render.hpp packages render-facing atlas/geometry data. The key boundary is explicit: slughorn prepares CPU-side data and constraints; an external OpenGL, Vulkan, WebGPU, Metal, DirectX, or scene-graph frontend uploads and renders it.
Authoring and Import Adapters
All sources converge on quadratic Bézier-oriented shape data:
• Native paths, text-like layout operations, gradients, and composition: slughorn/canvas.hpp.
• SVG paths and gradients through NanoSVG: slughorn/nanosvg.hpp.
• Font outlines and COLRv0/COLRv1 color-glyph layers: slughorn/freetype.hpp and slughorn/emoji.hpp.
• Existing drawing-system path ingestion: slughorn/cairo.hpp, slughorn/skia.hpp, and slughorn/blend2d.hpp.
These adapters are intentionally input-side only; they do not import the source library’s renderer or GPU ownership model.
Curve Processing and Atlas Preparation
Curve decomposition and scanline/atlas-oriented processing turn path geometry into data suitable for exact per-fragment curve evaluation. The core processing surface is slughorn/slughorn.hpp; tessellation-related utilities are isolated in slughorn/tessellate.hpp. MSDF generation is supported through the vendored ext/msdfgen, complementing curve atlas data for effects such as inside/outside coverage.
Composition, Masks, and Render Semantics
Shapes can be assembled into ordered CompositeShape layers with individual transforms and fill behavior, including procedural or arbitrary-shape masks. Render descriptors separate geometry preparation from frontend-specific material/shader decisions. Relevant public boundaries are slughorn/render.hpp, slughorn/canvas.hpp, and slughorn/serial.hpp, the latter supporting interchange/serialization including the project’s glTF-compatible JSON direction.
Runtimes and Dependencies
The primary runtime is native C++20. Python bindings use vendored pybind11 (ext/pybind11) and expose core, canvas, render, SVG, FreeType, emoji, and tessellation capabilities through files such as ext/python/slughorn-core.cpp and ext/python/slughorn-render.cpp. Vendored dependencies include NanoSVG (ext/nanosvg), earcut (ext/earcut), JSON (ext/json), and MSDF generation (ext/msdfgen). Skia-related build arguments reside in ext/skia-args.gn; Skia, Cairo, Blend2D, and FreeType are adapter ecosystems rather than slughorn’s rendering runtime.
Main entry points: slughorn.hpp Core model & API · slughorn/slughorn.cpp Core implementation · python/slughorn.cpp Python module · render.hpp Render descriptors
Components 18
Public API
- Core model & API · Unified shapes, curves, fills, masks, and metadata.
slughorn/slughorn.hpp - Render descriptors · CPU-side atlas and geometry packages for host renderers.
slughorn/render.hpp - Serialization · Supports serialization and glTF-compatible JSON direction.
slughorn/serial.hpp
Preparation Pipeline
- Core implementation
slughorn/slughorn.cpp - Tessellation utilities
slughorn/tessellate.hpp - MSDF generation · Generates distance-field data alongside curve atlas data.
ext/msdfgen
Input Adapters
- Canvas authoring · Native path, layout, gradient, and composition input.
slughorn/canvas.hpp - SVG adapter · NanoSVG paths and gradients.
slughorn/nanosvg.hpp - FreeType outlines
slughorn/freetype.hpp - Color glyph layers · COLRv0/COLRv1 glyph composition.
slughorn/emoji.hpp - Drawing path adapters · Cairo, Skia, and Blend2D path ingestion.
slughorn/cairo.hpp
Python Runtime
- Python module · Offline processing entry point.
ext/python/slughorn.cpp - Python binding units · Exposes core, canvas, render, SVG, font, emoji, and tessellation APIs.
ext/python/slughorn-core.cpp - pybind11
ext/pybind11
Other components
- CMake build · Builds the C++ library and optional integrations.
CMakeLists.txt - Native consumers · Own GPU resources, shaders, upload, and drawing.
- Graphics frontends · OpenGL, Vulkan, WebGPU, Metal, DirectX, or scene-graph rendering.
- CLI launchers
bin/slughorn
Connections 17
- CMake build → Core implementation: builds
- Core model & API → Core implementation: implemented by
- Canvas authoring → Core model & API: authors shapes
- SVG adapter → Core model & API: imports paths
- FreeType outlines → Core model & API: imports outlines
- Color glyph layers → Core model & API: adds color layers
- Drawing path adapters → Core model & API: ingests paths
- Core implementation → Tessellation utilities: uses
- Core implementation → MSDF generation: generates distance fields
- Core implementation → Render descriptors: prepares atlas data
- Core model & API → Serialization: serializes model
- Native consumers → Core model & API: uses
- Render descriptors → Graphics frontends: uploaded and rendered by
- pybind11 → Python module: binds with
- Python module → Python binding units: loads
- Python binding units → Core model & API: exposes
- CLI launchers → Python module: launches processing