blinc_gpu
Part of the Blinc UI Framework
This crate is a component of Blinc, a GPU-accelerated UI framework for Rust. For full documentation and guides, visit the Blinc documentation.
GPU renderer for Blinc UI using wgpu with SDF-based rendering.
Overview
blinc_gpu provides high-performance GPU rendering for the Blinc UI framework. It uses Signed Distance Field (SDF) techniques for crisp, resolution-independent rendering of UI primitives.
Features
- SDF Primitives: Rounded rectangles, circles, ellipses with perfect anti-aliasing
- Shadows: Gaussian blur shadows via error function approximation
- Gradients: Linear and radial gradient fills
- Glass/Vibrancy: Backdrop blur effects for frosted glass UI
- Text Rendering: SDF-based text with glyph atlases
- Image Rendering: Efficient texture-based image display
- Compositing: Layer blending with various blend modes
- Cross-Platform: Works on macOS, Windows, Linux, iOS, Android, and WebGPU
Architecture
blinc_gpu
├── renderer.rs # Main GpuRenderer
├── primitives.rs # GPU primitive types
├── paint.rs # Paint context implementation
├── text/ # Text rendering pipeline
├── image/ # Image rendering pipeline
├── shaders/ # WGSL shader modules
│ ├── sdf.wgsl # SDF primitive rendering
│ ├── text.wgsl # Text/glyph rendering
│ ├── glass.wgsl # Glass blur effects
│ ├── blur.wgsl # Gaussian blur
│ └── image.wgsl # Image rendering
└── backbuffer.rs # Double/triple buffering
Rendering Pipeline
- Primitive Collection: UI elements converted to
GpuPrimitiveinstances - Batching: Primitives grouped by type and texture
- SDF Rendering: Shapes rendered using signed distance functions
- Compositing: Layers blended in correct order
- Output: Final frame presented to surface
Shader Features
SDF Primitives
// Rounded rectangle with per-corner radius
fn sdf_rounded_rect(p: vec2<f32>, size: vec2<f32>, radii: vec4<f32>) -> f32
// Perfect anti-aliasing at any scale
fn alpha_from_sdf(d: f32) -> f32
Glass Effects
// Frosted glass with backdrop blur
fn glass_blur(uv: vec2<f32>, blur_radius: f32) -> vec4<f32>
// Vibrancy with tint and saturation
fn apply_vibrancy(color: vec4<f32>, tint: vec4<f32>, saturation: f32) -> vec4<f32>
Shadows
// Gaussian shadow via error function
fn shadow_alpha(d: f32, blur: f32) -> f32
Usage
use ;
// Create renderer
let renderer = new;
// Create primitives
let rect = rect
.with_color
.with_corner_radius
.with_border;
// Render
renderer.render_primitives;
Performance
- Instanced Rendering: Single draw call for multiple primitives
- Texture Atlasing: Glyphs and icons packed into atlases
- Batch Optimization: Automatic primitive batching
- GPU-side AA: Anti-aliasing computed in shader
Requirements
- wgpu-compatible GPU
- Vulkan, Metal, DX12, or WebGPU backend
License
MIT OR Apache-2.0