Skip to main content

Renderer

Struct Renderer 

Source
pub struct Renderer {
Show 17 fields triangle: TrianglePipeline, quad: QuadPipeline, sprite: SpritePipeline, graphics: GraphicsPipeline, text: TextPipeline, flex_text: FlexTextPipeline, mesh: MeshPipeline, advanced_blend: AdvancedBlendPipelines, blit: BlitPipeline, clip: ClipPipeline, path_clip: PathClipPipeline, mask_texture: MaskTexturePipeline, path_mask_texture: PathMaskTexturePipeline, mask_compose: MaskComposePipeline, mask_combine: MaskCombinePipeline, mask_cache: RefCell<MaskCache>, output_format: TextureFormat,
}
Expand description

2D renderer.

Owns the GPU pipelines used to draw scenes onto a [wgpu::TextureView]. Construct one per output format (surface or RenderTexture).

Fields§

§triangle: TrianglePipeline§quad: QuadPipeline§sprite: SpritePipeline§graphics: GraphicsPipeline§text: TextPipeline§flex_text: FlexTextPipeline§mesh: MeshPipeline§advanced_blend: AdvancedBlendPipelines§blit: BlitPipeline§clip: ClipPipeline§path_clip: PathClipPipeline§mask_texture: MaskTexturePipeline§path_mask_texture: PathMaskTexturePipeline§mask_compose: MaskComposePipeline§mask_combine: MaskCombinePipeline§mask_cache: RefCell<MaskCache>§output_format: TextureFormat

Implementations§

Source§

impl Renderer

Source

pub fn new( app: &Application, output_format: TextureFormat, ) -> Result<Self, Error>

Construct a renderer that targets the given color format.

§Errors

Currently infallible; reserved for future pipeline-creation failures.

Source

pub fn apply_advanced_blend( &self, app: &Application, mode: BlendMode, backdrop: &RenderTexture, foreground: &RenderTexture, output: &RenderTexture, )

Compose two render-textures via an advanced (Tier C) blend mode.

backdrop is the previously-rendered destination, foreground is this node’s contribution rendered into its own RT, and the composite lands in output. All three must share dimensions and the format the renderer was constructed against.

§Panics

Panics if mode is a standard (GPU-native) blend mode — those don’t have a per-mode pipeline registered. Use the standard pipelines (via render_stage + Container::blend_mode) for those.

Source

pub fn render(&self, app: &Application, view: &TextureView, clear: Color)

Clear the target with clear, then draw the M0.5 hardcoded triangle.

Source

pub fn render_quad( &self, app: &Application, view: &TextureView, clear: Color, texture: &Texture, model: Mat4, tint: Color, )

Clear the target with clear, then draw a single textured quad.

Source

pub fn render_stage( &self, app: &Application, view: &TextureView, clear: Color, stage: &Stage, ) -> RenderStats

Clear the target, traverse stage, draw every visible node.

Two paths internally:

  • Fast path (no advanced blend modes AND no clipped containers): one render pass directly into view, batching by pipeline + blend mode.
  • Slow path (any node uses an advanced blend mode OR has a clip mask set): allocate internal RenderTextures at app.width()/app.height(), render the scene minus the affected subtrees, then for each affected node render its subtree into a foreground RT, optionally apply_clip it, and composite onto the in-progress destination (advanced blend modes use apply_advanced_blend; clipped containers use source-over via the blit pipeline). Final blit to view.

Slow-path RT dimensions track Application::width() / Application::height(); for views whose dims diverge from the app config, use a matching AppConfig or pre-render into a fixed-size RenderTexture.

Returns RenderStats with the resulting draw-call and sprite counts.

Source

pub fn apply_clip( &self, app: &Application, shape: MaskShape, foreground: &RenderTexture, output: &RenderTexture, )

Apply a MaskShape clip to foreground, writing the masked result to output. Pixels outside the mask have their alpha zeroed.

Auto-dispatched by render_stage when a container’s Container::clip is set; this method is also exposed for callers who pre-render a foreground RT manually and want to mask it without going through the full scene-graph path.

Source

pub fn apply_clip_vector( &self, app: &Application, vector: &Vector, foreground: &RenderTexture, output: &RenderTexture, )

Vector-driven variant of Self::apply_clip (M-VEC.6 / AUT-58). Generates the mask via the M-DYN.1 path (cached) and composes against the foreground via Self::apply_mask_to_texture. Accepts paths.

Source

pub fn apply_privacy_blur( &self, app: &Application, shape: MaskShape, radius: f32, base: &RenderTexture, output: &RenderTexture, )

Composition primitive — render base, blurred only inside shape, into output. Outside the shape the pixels are preserved as-is.

Started life as the AUT-20 rectangle privacy blur; AUT-21 generalized it to any MaskShape (rounded rect today; ellipse / circle / freehand path follow in AUT-30/-34/-35). Calling with MaskShape::Rect reproduces the AUT-20 behavior; MaskShape::RoundedRect redacts with cinematic rounded corners matching modern app surfaces.

Pipeline (all RTs match base’s dimensions at the renderer’s output format):

  base ─ BlurFilter(radius) ─►  blur_rt
                                  │
                                  ├─ ClipPipeline(shape) ─►  masked_rt
                                  │
  base ─────────────────────────► output  (Blit::REPLACE)
                                  │
  masked_rt ────────────────────► output  (Blit::ALPHA_BLENDING — over)

shape is in NDC [-1, +1]² (screen space). radius is the Gaussian blur radius in pixels; AUT-22 will expose this as a scene-data parameter rather than just a method argument.

Use this when you’ve pre-rendered a frame into base (e.g. the recording surface) and want to redact a known region. Future enhancement: a Container node type that triggers this automatically during scene traversal.

Source

pub fn apply_privacy_blur_vector( &self, app: &Application, vector: &Vector, radius: f32, base: &RenderTexture, output: &RenderTexture, )

Vector-driven variant of Self::apply_privacy_blur (M-VEC.4 / AUT-56). Same composition shape but the mask is produced from a Vector instead of a MaskShape, unlocking path support and the M-DYN.2 cache for repeated regions across frames.

Pipeline:

  base ─ BlurFilter(radius) ──────────► blur_rt
                                             │
  vector ─ generate_vector_mask_texture ─► mask_rt
                                             │
                         (blur_rt × mask_rt) ► masked_rt
                                             │
  base ───────────────────────────────────► output  (REPLACE)
  masked_rt ──────────────────────────────► output  (compose_over)
Source

pub fn apply_solid_redaction( &self, app: &Application, shape: MaskShape, color: Color, base: &RenderTexture, output: &RenderTexture, )

Composition primitive — render base, with shape filled by a flat color (M-MASK / AUT-23 solid redaction). Outside the shape the pixels are preserved as-is.

The companion to Self::apply_privacy_blur. Privacy blur is polish (the redacted region still has texture); solid redaction is trust (the region is replaced with an opaque fill). Use this for content where partial reconstruction must be impossible — API keys, passwords, secrets.

Pipeline:

  fill_rt    ← cleared to `color` (RP LoadOp::Clear)
                                  │
                                  ├─ ClipPipeline(shape) ─►  masked_rt
                                  │
  base ─────────────────────────► output  (Blit::REPLACE)
                                  │
  masked_rt ────────────────────► output  (Blit::ALPHA_BLENDING — over)

Tip: use a fully-opaque color (alpha 1.0) for true redaction; a partial alpha will let base show through proportionally, which defeats the “trust” use case.

Source

pub fn apply_solid_redaction_vector( &self, app: &Application, vector: &Vector, color: Color, base: &RenderTexture, output: &RenderTexture, )

Vector-driven variant of Self::apply_solid_redaction (M-VEC.5 / AUT-57). Same composition shape, but the mask is produced from a Vector — including freehand polygons via VectorShape::Path.

Source

pub fn combine_masks( &self, app: &Application, a: &RenderTexture, b: &RenderTexture, op: MaskCombineOp, output: &RenderTexture, )

Combine two alpha-mask textures via a boolean operation (M-VEC.11 / AUT-63). The resulting mask is itself a regular alpha-mask RenderTexture and can drive any downstream composition primitive (apply_mask_to_texture, compose_blur_through_mask, etc.).

Source

pub fn compose_blur_through_mask( &self, app: &Application, base: &RenderTexture, radius: f32, mask: &RenderTexture, output: &RenderTexture, )

Compose privacy blur through an explicit alpha-mask texture (M-DYN.3 / AUT-45). Lower-level than Self::apply_privacy_blur: the caller supplies the mask texture, which lets multiple effects share one mask without regenerating it. Same composition shape as the high-level method:

  base ─ BlurFilter(radius) ──► blur_rt
                                   │
                 blur_rt × mask  ── masked_rt   ← apply_mask_to_texture
                                   │
  base ─────────────────────────► output  (REPLACE)
  masked_rt ─────────────────────► output  (compose_over)

Use case: when a region is being privacy-blurred and solid-redacted and spotlighted on the same frame, generate the mask once via Self::cached_vector_mask_texture and pass the result to all three composition primitives.

Source

pub fn compose_solid_through_mask( &self, app: &Application, base: &RenderTexture, color: Color, mask: &RenderTexture, output: &RenderTexture, )

Compose solid-color redaction through an explicit alpha-mask texture (M-DYN.4 / AUT-46). Sister of Self::compose_blur_through_mask — same shape, but the “what’s inside” is a solid color instead of a blur.

Source

pub fn compose_dim_through_inverted_mask( &self, app: &Application, base: &RenderTexture, dim_color: Color, inverted_mask: &RenderTexture, output: &RenderTexture, )

Compose dim-outside (spotlight) through an explicit inverted alpha-mask texture (M-DYN.5 / AUT-47). The mask should already be inverted (e.g., from Self::cached_mask_texture_inverted); this primitive just composes a constant dim_color through it.

Source

pub fn apply_mask_to_texture( &self, app: &Application, foreground: &RenderTexture, mask: &RenderTexture, output: &RenderTexture, )

Compose foreground × mask.alpha into output (M-VEC.4..6 / AUT-56..58 building block). The mask texture must store coverage in alpha (the format produced by Self::generate_mask_texture et al).

All three RTs must share dimensions and format. This is the primitive that the vector-driven privacy blur / redaction / spotlight refactor uses internally; expose it as part of the public surface so app-level code (when it lands) can drive composition through the same path.

Source

pub fn generate_mask_texture( &self, app: &Application, shape: MaskShape, w: u32, h: u32, ) -> RenderTexture

Generate an alpha-mask RenderTexture for shape at (w, h) (M-DYN.1 / AUT-43). The texture stores coverage as (m, m, m, m) so consumers can either alpha-multiply (sample .a) or display as a grayscale silhouette.

This primitive owns only coverage. Privacy blur, redaction, and spotlight composition layers (M-DYN.3+, M-VEC.4+) consume these textures separately. The cache (AUT-44) layers on top to avoid regenerating identical masks every frame.

Source

pub fn generate_vector_mask_texture( &self, app: &Application, vector: &Vector, w: u32, h: u32, ) -> RenderTexture

Generate an alpha-mask RenderTexture for a Vector primitive (M-VEC.3 / AUT-55). Routes to the analytic-SDF or path-mask path depending on the underlying VectorShape.

Only Vector::shape is consulted — fill / stroke / opacity / transform don’t affect mask coverage. transform does shift the SDF center / path points if honored; for V1 we ignore it (the mask is always evaluated in NDC against the raw shape data).

This is the bridge used by M-VEC.4..6: any caller that wants to drive a mask from vector data uses this entry point, and the underlying primitive (privacy blur, redaction, spotlight) gets the same alpha texture regardless of which VectorShape variant produced it.

Source

pub fn cached_vector_mask_texture( &self, app: &Application, vector: &Vector, w: u32, h: u32, ) -> Arc<RenderTexture>

Cached variant of Self::generate_vector_mask_texture. Analytic shapes go through the M-DYN.2 cache; path shapes bypass (V1: paths not cached — see M-DYN.2’s chapter).

Source

pub fn cached_mask_texture( &self, app: &Application, shape: MaskShape, w: u32, h: u32, ) -> Arc<RenderTexture>

Cached variant of Self::generate_mask_texture (M-DYN.2 / AUT-44). Returns an Arc<RenderTexture> that may be shared across the cache and other call sites; identical (shape, w, h) inputs reuse the same GPU texture across frames instead of regenerating.

Cache eviction is FIFO at 64 entries (see the MAX_ENTRIES constant in crate::render::mask_cache). f32 fields hash by exact bits, so callers re-passing the same shape value Just Work.

Source

pub fn cached_mask_texture_inverted( &self, app: &Application, shape: MaskShape, w: u32, h: u32, ) -> Arc<RenderTexture>

Cached + inverted variant.

Source

pub fn mask_cache_stats(&self) -> (u64, u64)

Returns (hits, misses) for the mask texture cache. Useful for tests and observability.

Source

pub fn clear_mask_cache(&self)

Drop every entry in the mask texture cache. Call when the renderer’s underlying resources change (e.g., format swap) or in tests that want to start from a clean slate.

Source

pub fn generate_mask_texture_inverted( &self, app: &Application, shape: MaskShape, w: u32, h: u32, ) -> RenderTexture

Inverse variant of Self::generate_mask_texture: pixels outside the shape are opaque, inside are transparent. Used by spotlight / dim-outside composition (M-DYN.5).

Source

pub fn generate_path_mask_texture( &self, app: &Application, points: &[Vec2], w: u32, h: u32, ) -> RenderTexture

Generate an alpha-mask RenderTexture for a freehand polygon (M-DYN.1 / AUT-43, path variant). Up to 32 vertices honored (uniform-buffer cap; same as apply_path_clip).

Source

pub fn apply_path_clip( &self, app: &Application, points: &[Vec2], foreground: &RenderTexture, output: &RenderTexture, )

Apply a freehand polygon mask to foreground, writing the masked result to output (M-MASK / AUT-35).

points is a closed polygon in NDC [-1, +1]². Up to MAX_PATH_POINTS (32) vertices are honored; the rest are silently ignored. Pixels inside the polygon pass through foreground unchanged; pixels outside drop to alpha 0.

Implementation note: the WGSL fragment shader runs a crossings-test point-in-polygon at every pixel — no tessellation, no SDF. AA is hard-edge for V1; the rasterized output is integer-pixel accurate (Jordan curve theorem).

Source

pub fn apply_solid_redaction_path( &self, app: &Application, points: &[Vec2], color: Color, base: &RenderTexture, output: &RenderTexture, )

Composition primitive — render base, with points (a closed polygon in NDC) filled by color (M-MASK / AUT-35 freehand solid redaction). Outside the polygon: base preserved.

Sister to Self::apply_solid_redaction but with a freehand polygon instead of a MaskShape. Same four-stage composition (clear fill / mask / blit base / compose over) — the only difference is the masking pass uses Self::apply_path_clip instead of the SDF clip.

Source

pub fn apply_spotlight( &self, app: &Application, shape: MaskShape, dim_color: Color, base: &RenderTexture, output: &RenderTexture, )

Composition primitive — render base, dimmed everywhere outside shape (M-MASK / AUT-28 spotlight, AUT-29 dim outside). Inside the shape, pixels are preserved as-is.

dim_color is the overlay shade applied outside the shape; its alpha controls the dim strength (0 = no effect, 1 = fully replaces the surrounding content). For “spotlight a button” effects dim_color = Color::rgba(0.0, 0.0, 0.0, 0.65) is a good cinematic default.

Pipeline (mirrors solid redaction with an inverted clip):

  fill_rt    ← cleared to `dim_color`
                                  │
                                  ├─ ClipPipeline(shape, invert=true) ─►  masked_rt
                                  │
  base ─────────────────────────► output  (Blit::REPLACE)
                                  │
  masked_rt ────────────────────► output  (Blit::ALPHA_BLENDING — over)
Source

pub fn apply_spotlight_vector( &self, app: &Application, vector: &Vector, dim_color: Color, base: &RenderTexture, output: &RenderTexture, )

Vector-driven variant of Self::apply_spotlight (M-VEC.6 / AUT-58). Inverse-mask path: pixels OUTSIDE the shape are dimmed by dim_color. Accepts paths.

Source

pub fn apply_dim_outside_data( &self, app: &Application, dim: &DimOutside, base: &RenderTexture, output: &RenderTexture, )

Convenience wrapper over Self::apply_spotlight that consumes a DimOutside data value (M-MASK / AUT-29).

Editor inspector controls and persisted documents work with DimOutside directly; this method exists so the app side never needs to convert a DimStrength enum back to an alpha itself.

Source

pub fn apply_dim_outside_vector( &self, app: &Application, vector: &Vector, strength: DimStrength, base: &RenderTexture, output: &RenderTexture, )

Vector-driven variant of Self::apply_dim_outside_data (M-VEC.7 / AUT-59). Same composition as apply_spotlight_vector but the dim color is derived from a DimStrength preset (Light / Medium / Heavy / Custom(alpha)). Accepts paths.

Source

pub fn apply_privacy_blur_data( &self, app: &Application, blur: &PrivacyBlur, base: &RenderTexture, output: &RenderTexture, )

Convenience wrapper over Self::apply_privacy_blur that consumes a PrivacyBlur data value (M-MASK / AUT-22).

Editor inspector controls and persisted documents work with PrivacyBlur structs directly; this method exists so the app side never needs to convert a BlurStrength enum back to a raw f32 itself.

Source

fn render_stage_fast( &self, app: &Application, view: &TextureView, clear: Color, stage: &Stage, ) -> RenderStats

Fast path: one render pass, no offscreen indirection.

Source

fn render_stage_with_advanced_dispatch( &self, app: &Application, view: &TextureView, clear: Color, stage: &Stage, dispatched: &[NodeId], ) -> RenderStats

Slow path with auto-dispatch — see render_stage.

Source

fn draw_subtree_to_rt( &self, app: &Application, dest: &RenderTexture, clear: Color, stage: &Stage, start: NodeId, exclude: &HashSet<NodeId>, ) -> RenderStats

Draw a subtree of stage (rooted at start, skipping exclude) into dest. Used by both phases of the advanced-dispatch path.

Source

pub fn apply_filter( &self, app: &Application, filter: &dyn Filter, input: &RenderTexture, output: &RenderTexture, )

Apply filter to input, writing the final result to output.

Multi-pass filters allocate a scratch RenderTexture (same size + format as output) and ping-pong between it and output.

Source

fn with_clearing_pass( app: &Application, view: &TextureView, clear: Color, draw: impl FnOnce(&mut RenderPass<'_>), )

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> WasmNotSend for T
where T: Send,