Expand description
emblema: a 2D vector renderer that tessellates paths on the CPU and needs no compute shaders.

Draw into a Canvas with a Paint, finish it into a Recording,
and hand that to a Context, which owns the device and the backend it
picked. The showcase example draws the frame above; the repository’s
README has the rest.
| Feature | Default | What it adds |
|---|---|---|
vulkan | yes | The Vulkan 1.1 backend. |
present-wsi | yes | Presenting into a Vulkan swapchain. Implies vulkan. |
gles | The GLES 3.0 backend. | |
present-egl | Presenting into an EGL window surface. Implies gles. | |
drm | Direct scanout to a KMS plane. Vulkan draws into it today; GLES does not yet. | |
gbm | Scanout from buffers GBM allocates on the display’s side, for a display that cannot take what the renderer allocates. Implies drm; needs Rust 1.94.1. |
The whole of it, from a device to pixels in memory:
use emblema::{BackendPreference, Canvas, Color, Context, Extent2D, Paint, PixelFormat, Rect};
// The backend is chosen at run time, so one binary serves a board with a
// working Vulkan driver and one where only GLES is usable.
let mut ctx = Context::new(BackendPreference::Auto)?;
let size = Extent2D::new(256, 256);
let mut surface = ctx.create_surface(size, PixelFormat::Rgba8Unorm)?;
let mut canvas = Canvas::new(size);
canvas.clear(Color::WHITE);
canvas.draw_rect(
Rect::new(32.0, 32.0, 224.0, 224.0),
&Paint::fill(Color::rgba8(0, 120, 220, 255)),
)?;
// Recording is separate from submitting, so a whole frame is described
// before any of it reaches the GPU and every shape shares one pass.
ctx.draw(&mut surface, &canvas.finish())?;
let pixels = ctx.read(&mut surface)?;
// Destroyed explicitly, because nothing here frees a GPU object on drop. A
// surface still alive when its context goes is a child outliving its device,
// which the validation layer reports as an error rather than a leak.
ctx.destroy_surface(surface);Which backend runs is decided when the context is created, not when the binary is built, so one image can boot on a board with a working Vulkan driver and on one where only GLES is usable.
Code above the backend branches on Context::capabilities rather than on
which backend it got. A device that cannot export a fence is the same
problem whichever API it speaks, and asking which backend it is gets both
cases wrong.
Re-exports§
pub use backend::Backend;pub use backend::BackendPreference;pub use context::Context;pub use context::Image;pub use context::Surface;pub use emblema_present_drm as drm;drmpub use emblema_hal_vulkan as vulkan;vulkanpub use emblema_hal_gles as gles;glespub use emblema_present_vk as wsi;present-wsipub use emblema_present_egl as egl;present-eglpub use emblema_present as present;
Modules§
- backend
- Choosing a rendering backend at runtime.
- context
- A rendering context, over whichever backend is available.
- execute
- Draw a recording into a texture this crate did not create.
Structs§
- Affine2
- Two-dimensional vector and affine types, from
glam. A 2D affine transform, which can represent translation, rotation, scaling and shear. - Atlas
- A square atlas of glyph coverage, and where each glyph landed.
- Atlas
Rect - Where a glyph sits in the atlas, in texels.
- Canvas
- Records drawing commands for one frame.
- Capabilities
- Everything the layers above the HAL are allowed to branch on.
- Color
- A linear, straight-alpha color.
- Coverage
- A rasterized glyph, as a caller supplies it.
- Dash
- A dash pattern: alternating drawn and skipped lengths, and where to start.
- DmaBuf
Plane Unix - One plane of a dma-buf image.
- Extent2D
- A 2D extent in pixels.
- External
Image Desc Unix - An image that already exists, to be imported rather than allocated.
- Float32
Support - What a device can do with one of the 32-bit float formats, past sampling it texel by texel, which every device here can.
- Fourcc
- What
Context::import_imagetakes: a dma-buf’s planes, its DRM format and its layout. A DRM fourcc format code. - Glyph
Key - What identifies a glyph in the atlas.
- Gradient
Stop - A color stop in a gradient.
- Layer
- How a layer is composited back onto what was underneath it.
- Memory
Blocks - The sizes of the blocks a backend takes device memory in, in bytes.
- Memory
Use - Memory allocated from a backend’s blocks, in bytes, by the two kinds
MemoryBlockshas: what only the device reads, and what the host writes or reads through. - Modifier
- What
Context::import_imagetakes: a dma-buf’s planes, its DRM format and its layout. A DRM format modifier describing the memory layout of a buffer. - Morphology
- Spreading or shrinking a finished layer, one axis at a time.
- Paint
- Everything about how a shape is painted.
- Path
- A path: a verb stream plus the points those verbs consume.
- Path
Builder - Accumulates verbs and points into a
Path. - Positioned
Glyph - One glyph, placed.
- Recording
- A finished recording, ready to submit.
- Rect
- A rectangle in user coordinates.
- Runtime
Program - A caller’s fragment program, in the forms each backend can take one.
- Shader
Variant - The parts of the built-in shader one draw needs: its material’s arm, and
whether it filters its color and blends its tint by a mode other than
Modulate. - Source
Rect - A rectangle in texels, as a sprite’s source.
- Sprite
- One piece of a sprite sheet, and where it goes.
- Stroke
Style - A stroke’s geometric parameters.
- Texture
Descriptor - What to allocate, or what to import.
- Texture
Usage - How a texture will be used, which backends need up front to choose a layout.
- Transform2D
- A transform of the plane that may carry perspective.
- Vec2
- Two-dimensional vector and affine types, from
glam. A 2-dimensional vector. - Vertices
- A mesh of triangles in user space, with optional texture coordinates.
Enums§
- Atlas
Error - Why a glyph could not be added.
- Blend
Factor - A factor a blend equation multiplies one side by.
- Blend
Mode - How a draw combines with what a target already holds.
- Color
Filter - A function applied to a material’s color, after the material and before the blend.
- Color
Form - What space a color filter’s matrix expects its input in.
- Color
Space - The primaries a color’s components are stated against.
- Error
- Fill
Rule - How overlapping subpaths combine when filling.
- Gamma
- Which way through the sRGB transfer function a
ColorFilter::Gammagoes. - Image
Filter - A function applied to what a paint drew, rather than to the color it computed.
- LineCap
- How a stroke terminates at an open end.
- Line
Join - How a stroke turns a corner.
- Mask
Blur Style - Which part of a blurred shape survives.
- Material
Variant - Which arm of the built-in shader a material is drawn by.
- Pixel
Format - Pixel formats the renderer can target.
- Point
Mode - How a run of points is joined up.
- Sampling
- How a texture is read between its texels.
- Shader
- What fills a shape.
- Style
- Fill the shape, or trace its outline.
- Tile
Mode - What happens outside an image’s own bounds.
- Vertex
Mode - How positions are grouped into triangles.
Constants§
- EFFECT_
BYTES - Bytes of the effect block a draw binds:
RUNTIME_FLOATSof them. - MAX_
STOPS - The most stops a gradient carries in the material itself.
- MORPHOLOGY_
TAPS - How far one morphology pass reaches, in texels each way.
- RUNTIME_
FLOATS - How many floats a runtime effect may take: 6,208 bytes, the most
Flutter’s shader compiler (
impellerc) lets a fragment program declare.
Traits§
- Hal
- A rendering backend, as a family of associated types.
Functions§
- execute
- Draw a recording into a texture this crate did not create.
- execute_
deferred - Draw a recording into a texture this crate did not create.
- execute_
layers - Draw a recording into a texture this crate did not create.
- mip_
levels_ for - How many mip levels an image of this size has, counting the image itself.
- render_
offscreen - Draw a recording into a texture this crate did not create.
Type Aliases§
- Result
- Result alias used throughout the HAL.
- Rounding
Radii - A rounded rectangle’s four corners, each with an x and a y radius.