SwCanvas for CPU-based software rendering and GlCanvas for GPU-accelerated WebGL rendering.
SwCanvas (Software Rendering)
SwCanvas uses CPU-based rendering, providing maximum compatibility across platforms and browsers.
SwCanvas Props
Width of the canvas in CSS pixels.
Height of the canvas in CSS pixels.
Device pixel ratio for high-DPI displays. Automatically defaults to the window’s pixel ratio.
Optional function to customize WebAssembly file paths. Useful for CDN configurations.
When to Use SwCanvas
Maximum Compatibility
Works on all browsers and devices without WebGL support requirements.
Simple Graphics
Best for basic vector graphics with moderate complexity.
Static Content
Ideal for graphics that don’t require frequent updates.
Predictable Performance
CPU-based rendering provides consistent, predictable performance.
GlCanvas (WebGL Rendering)
GlCanvas uses GPU-accelerated WebGL rendering for better performance with complex scenes.
GlCanvas Props
Required unique identifier for the canvas element. Used by WebGL context to bind to the canvas.
Width of the canvas in CSS pixels.
Height of the canvas in CSS pixels.
Device pixel ratio for high-DPI displays.
Optional function to customize WebAssembly file paths.
When to Use GlCanvas
Complex Graphics
Better performance for scenes with many shapes and complex paths.
Animations
GPU acceleration provides smoother animations and frequent updates.
High Performance
Offloads rendering to GPU for faster processing.
Modern Browsers
Requires WebGL support (available in all modern browsers).
Key Differences
Rendering Backend
Rendering Backend
- SwCanvas: CPU-based software rendering using Canvas 2D API
- GlCanvas: GPU-accelerated rendering using WebGL
Performance Characteristics
Performance Characteristics
- SwCanvas: Linear performance degradation with complexity. Best for simple to moderate graphics.
- GlCanvas: Better performance with complex scenes due to GPU parallelization.
Browser Compatibility
Browser Compatibility
- SwCanvas: Works on all browsers, including older ones without WebGL
- GlCanvas: Requires WebGL support (available in all modern browsers since ~2015)
Required Props
Required Props
- SwCanvas: Only requires
widthandheight - GlCanvas: Requires
width,height, and a uniqueid
Color Space
Color Space
- SwCanvas: Uses
ABGR8888(premultiplied alpha) - GlCanvas: Uses
ABGR8888S(straight alpha)
Choosing the Right Canvas
Assess Your Requirements
Consider the complexity of your graphics, target browsers, and performance needs.
Start with SwCanvas
For most use cases, SwCanvas provides excellent compatibility and sufficient performance.