Skip to content

Commit 4210917

Browse files
committed
Create CLAUDE.md
1 parent 5720f1e commit 4210917

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
vger is a GPU-accelerated vector graphics renderer written in C with Swift bindings, designed for iOS and macOS. It renders primitives analytically in fragment shaders rather than using CPU tessellation, achieving high performance for immediate-mode UIs.
8+
9+
## Architecture
10+
11+
### Core Components
12+
13+
- **C Core (`Sources/vger/`)**: The main rendering engine written in C/C++/Objective-C++ with Metal shaders
14+
- `vger.h`: Main API interface - review this for all available rendering functions
15+
- `vger.mm`: Core implementation with Metal rendering logic
16+
- `vgerRenderer.mm`: Main renderer class handling Metal command encoding
17+
- `vgerPathScanner.mm`: Path processing and horizontal slab decomposition for fills
18+
- `vgerGlyphCache.mm`: Text rendering with glyph atlas management
19+
- `vger.metal`: Fragment shaders for primitive rendering
20+
21+
- **Swift Layer (`Sources/vgerSwift/`)**: SwiftUI integration and higher-level APIs
22+
- `VgerView.swift`: SwiftUI view wrapper for Metal rendering
23+
- `Renderer.swift`: Metal rendering coordinator
24+
- `TextureRenderer.swift`: Additional texture rendering utilities
25+
26+
- **Demo App (`Demo/`)**: Complete iOS/macOS SwiftUI application demonstrating usage
27+
- Cross-platform implementation showing VgerView integration
28+
- Examples of text, shapes, SVG rendering, and various primitives
29+
30+
### Key Design Patterns
31+
32+
- **Immediate Mode**: All drawing commands are recorded per frame, no retained geometry
33+
- **GPU-Centric**: Fragment shaders handle primitive evaluation, minimal CPU work
34+
- **Instanced Rendering**: Each primitive renders as a quad with shader-computed geometry
35+
- **Paint System**: Separate paint objects for colors, gradients, textures, and patterns
36+
- **Transform Stack**: Standard graphics transform state with save/restore
37+
38+
## Development Commands
39+
40+
### Building
41+
```bash
42+
# Build the project
43+
./build.sh
44+
45+
# Or use xcodebuild directly
46+
xcodebuild -scheme vger -sdk macosx -destination "name=My Mac"
47+
```
48+
49+
### Testing
50+
```bash
51+
# Run all tests
52+
./test.sh
53+
54+
# Or use xcodebuild directly
55+
xcodebuild test -scheme vger -sdk macosx -destination "name=My Mac"
56+
```
57+
58+
### Swift Package Manager
59+
This project uses SPM and can be built with:
60+
```bash
61+
swift build
62+
swift test
63+
```
64+
65+
## Usage Patterns
66+
67+
### Basic C API Usage
68+
```c
69+
vgerContext vg = vgerNew(0, MTLPixelFormatBGRA8Unorm);
70+
vgerBegin(vg, width, height, devicePixelRatio);
71+
72+
// Create paint and draw primitives
73+
vgerPaintIndex paint = vgerColorPaint(vg, (vector_float4){1,0,0,1});
74+
vgerFillCircle(vg, center, radius, paint);
75+
76+
vgerEncode(vg, commandBuffer, renderPassDescriptor);
77+
```
78+
79+
### SwiftUI Integration
80+
```swift
81+
VgerView(renderCallback: { vger, size in
82+
let paint = vgerColorPaint(vger, SIMD4<Float>(1,0,1,1))
83+
vgerFillRect(vger, min, max, cornerRadius, paint)
84+
})
85+
```
86+
87+
## Key Implementation Details
88+
89+
- **Path Fills**: Uses reverse Loop-Blinn technique in fragment shader to avoid solving quadratic equations
90+
- **Text Rendering**: Glyph atlas with SDF-based rendering for scalable text
91+
- **Buffering**: Supports double/triple buffering schemes via creation flags
92+
- **Layers**: Multi-layer rendering support (up to 4 layers)
93+
- **Transform Stack**: Full 2D transformation support with save/restore
94+
95+
## Test Structure
96+
97+
Tests are in `Tests/vgerTests/` and include:
98+
- Basic primitive rendering tests with reference images
99+
- Path scanning and fill algorithm tests
100+
- Glyph cache and text rendering tests
101+
- SDF computation tests
102+
- Texture management tests
103+
104+
Reference images in `Tests/vgerTests/images/` are used for visual regression testing.

0 commit comments

Comments
 (0)