Skip to content

Add Draw System design: BYOR (Bring Your Own Renderer) architecture#6

Merged
dgellow merged 1 commit intomainfrom
claude/review-zig-project-design-01V6PVtvqvBVjF7P6z9xcXwS
Dec 3, 2025
Merged

Add Draw System design: BYOR (Bring Your Own Renderer) architecture#6
dgellow merged 1 commit intomainfrom
claude/review-zig-project-design-01V6PVtvqvBVjF7P6z9xcXwS

Conversation

@dgellow
Copy link
Copy Markdown
Owner

@dgellow dgellow commented Dec 2, 2025

Summary

Adds comprehensive Draw System documentation to DESIGN.md, establishing the Bring Your Own Renderer (BYOR) architecture inspired by Dear ImGui's backend system.

Design Highlights

  • BYOR Philosophy: zig-gui outputs draw commands; users implement rendering however they want (game engines, embedded, GPU-accelerated)
  • Draw Pipeline: Widget calls → Layout compute → Draw generation → Backend render
  • Deferred Generation: Draw commands generated after layout computation enables correct clipping, z-ordering, and batched rendering

Key Data Structures

Structure Purpose
DrawPrimitive Union: fill_rect, stroke_rect, text, line, vertices
DrawCommand Primitive + clip_rect + layer + widget_id
DrawList Accumulates commands with clip/layer stacks
DrawData Final output passed to backends
RenderBackend Vtable interface for backend implementations

Memory Budget (Embedded)

~3.6 KB for 32 widgets on 32KB targets (11% of budget), with immediate rendering mode option for extreme constraints.

Planned Backends

  • SdlOpenGlBackend, SdlSoftwareBackend (Desktop)
  • SoftwareBackend (Embedded, Headless)
  • WebGpuBackend (Browser)
  • MetalBackend (macOS, iOS)
  • VulkanBackend (Desktop, Android)

@dgellow dgellow marked this pull request as draft December 3, 2025 00:19
Document the BYOR (Bring Your Own Renderer) architecture inspired by
Dear ImGui's backend system. The library outputs draw commands; users
implement rendering however they want.

Key design elements:
- Draw pipeline: widget calls → layout compute → draw generation → backend
- DrawPrimitive union: fill_rect, stroke_rect, text, line, vertices
- DrawCommand with clip_rect, layer, and widget_id for z-ordering
- DrawList with clip/layer stack management
- DrawData output structure for backends
- RenderBackend vtable interface
- WidgetRenderInfo for storing widget data during UI function calls
- Example backends: SDL+OpenGL and Software rasterizer (embedded)
- Memory budget analysis: ~3.6 KB for 32KB embedded targets (11%)
- Planned backends: SDL, Software, WebGPU, Metal, Vulkan
@dgellow dgellow force-pushed the claude/review-zig-project-design-01V6PVtvqvBVjF7P6z9xcXwS branch from bd59d5a to b02a3db Compare December 3, 2025 09:25
@dgellow dgellow changed the title Rewrite widget ID system with full debug support Add Draw System design: BYOR (Bring Your Own Renderer) architecture Dec 3, 2025
@dgellow dgellow marked this pull request as ready for review December 3, 2025 09:28
@dgellow dgellow merged commit e64d864 into main Dec 3, 2025
7 of 13 checks passed
@dgellow dgellow deleted the claude/review-zig-project-design-01V6PVtvqvBVjF7P6z9xcXwS branch December 3, 2025 09:29
dgellow pushed a commit that referenced this pull request Dec 5, 2025
Add CLAUDE.md rule #6: "Design the Complete Solution"
- Never design incomplete solutions or defer hard problems
- Design for FULL requirements from the start
- Include support for hard cases in interface even if impl comes later
- Goal: complete design, incremental implementation

Update text rendering README.md:
- Replace "Phase 1/2/3" with "Implementation Order"
- Replace "Deferred to Phase 3" with explicit scope decisions:
  - Out of Scope: SDF, subpixel, variable fonts (with reasons)
  - In Design, Pending: bidi, shaping, color emoji (interface ready)
- Add "Complete System Architecture" diagram showing all providers
- Update Bidi section: "Interface fully supports bidi" not "limitation"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants