Rendering Architecture
The rendering system consists of four layers:Layer 1: Widget Rendering
Widgets are responsible for their own rendering:Rendering Order
The WidgetManager renders widgets in insertion order (bottom to top):Layer 2: Drawing Primitives
TheDraw namespace provides primitive rendering functions:
Implementation Pattern
Primitives use the global canvas:Optimized Primitives
Performance-critical primitives use direct buffer access:Layer 3: Canvas System
The Canvas provides pixel-level abstraction:Pixel Format
All pixels use 32-bit RGBA format (0xAABBGGRR):Bounds Checking
Canvas provides automatic bounds safety:Memory Layout
Pixels are stored in row-major order:- Cache-friendly: Sequential access along rows
- Simple addressing: Direct calculation of pixel offset
- Standard format: Compatible with most graphics APIs
Layer 4: Platform Abstraction
The platform layer handles OS-specific rendering:Platform Interface
Each platform implements:- Window creation and management
- Event loop processing
- Frame presentation (buffer → screen)
- Input event capture
Platform Implementations
Linux (SDL):Platform Factory
Runtime platform selection:Complete Rendering Flow
A typical frame progresses through all layers:1. Frame Start
Platform layer signals new frame:2. Input Processing
Input is distributed to widgets:3. Canvas Clear
Application typically clears the canvas:4. Widget Rendering
Widgets render in order:render() calls drawing primitives:
5. Primitive Execution
Primitives write to canvas:6. Frame Presentation
Platform displays the pixel buffer:Complete Example
Performance Optimization
Minimize Overdraw
Avoid rendering pixels multiple times:Direct Buffer Access
For performance-critical rendering:Cache-Friendly Rendering
Access pixels in row-major order:Avoid Redundant Rendering
Platform-Specific Considerations
Frame Rate Control
Desktop (SDL): V-sync handled by SDLColor Format Conversion
Some platforms require format conversion:Debugging Rendering
Visualize Bounds
Performance Metrics
See Also
- Architecture Overview - System design
- Widget System - Widget rendering details
- Canvas System - Low-level pixel operations
- Cross-Platform Support - Platform specifics