Skip to main content

Crate anyrender

Crate anyrender 

Source
Expand description

2D drawing abstraction that allows applications/frameworks to support many rendering backends through a unified API.

§Painting a scene

The core abstraction in AnyRender is the PaintScene trait.

PaintScene is a “sink” which accepts drawing commands:

  • Applications and libraries draw by pushing commands into a PaintScene
  • Backends execute those commands to produce an output

§Rendering to surface or buffer

In addition to PaintScene, there is:

  • The ImageRenderer trait which provides an abstraction for rendering to a Vec<u8> RGBA8 buffer.
  • The WindowRenderer trait which provides an abstraction for rendering to a surface/window

§SVG

The anyrender_svg crate allows SVGs to be rendered using AnyRender

§WASM support

Wgpu adapter/device/surface initialization is fundamentally async on the web. To avoid deadlocking the JS event loop, WindowRenderer::resume takes an on_ready callback: GPU backends spawn the init on wasm_bindgen_futures::spawn_local and invoke the callback once the surface is live. The embedder then calls WindowRenderer::complete_resume to transition the renderer to the active state. On native targets the same code path runs inline (pollster::block_on on the GPU backends), so callers see no behavioural difference.

§Backends

Currently existing backends are:

Re-exports§

pub use recording::Scene;
pub use wasm_send_sync::*;
pub use types::*;

Modules§

recording
types
Types that are used within the Anyrender traits
wasm_send_sync
Traits that imply Send/Sync only on non-wasm platforms. For interop with wgpu.

Structs§

NullImageRenderer
NullScenePainter
NullWindowRenderer
RegisterResourceError
ResourceId

Enums§

RegisterResourceErrorKind

Traits§

ImageRenderer
Abstraction for rendering a scene to an image buffer
PaintScene
Abstraction for drawing a 2D scene
RenderContext
WindowRenderer
Abstraction for rendering a scene to a window

Functions§

render_to_buffer
Draw a scene to a buffer using an ImageRenderer