Expand description
2D sprite viewport: snapshot in, pixels out.
The UI builds a FrameInput per frame (plain data, rebuilt
during composition) and mounts Viewport2d as a Repose view, which
draws the snapshot through a dp-space contain-fit and reports pointer
picks back in world coords. Unit discipline lives here, once:
games work in world/dp units and do not touch physical px.
Camera state lives in Repose signals, not in the renderer.
Re-exports§
pub use batch::AtlasUpload;pub use batch::BatchDesc;pub use batch::SpriteBatch;pub use batch::TextureFilter;pub use batch::draw_batch;pub use batch::draw_batch_with_id;pub use batch::frame_uv;pub use batch::instance_rows;pub use batch::screen_camera;pub use batch::sprite_aabb;pub use fullscreen::FullscreenDesc;pub use fullscreen::FullscreenPass;pub use fullscreen::FullscreenTexture;
Modules§
- batch
- GPU sprite batch: instanced textured quads as a
WgpuCallback. Owns the atlas texture array and instance buffer. Feeds fromAtlasUploads, draws through a caller-supplied camera matrix. - fullscreen
- Fullscreen procedural passes: game-specific WGSL over a generated triangle, with engine-owned pipeline/uniform/texture management.
- post
- Post-process composite for the GPU viewport: scene renders into an
offscreen texture, then a fullscreen pass grades it back to the
screen. (Bevy
post_processanalog: NT’sscreen_effects.wgslsampled the view target; in-pass callbacks cannot, so the viewport owns the intermediate.)
Structs§
- Camera2d
- 2D orthographic camera. Owned by the UI (signals), copied into the
snapshot per frame.
effective_centeriscenter + offset. Canvas, GPU batch, and picks derive from these fields together. - Cursor
Frame - One decoded + magnified hardware-cursor frame.
- Frame
Geom - One painted frame’s geometry, shared between viewports (writers)
and world-anchored siblings such as
ActorFrame(readers). Maps either direction so board sprites, picks, and actor surfaces track together, including under camera shake. - Frame
Input - Everything the viewport draws this frame. Plain snapshot data.
- Geom
Handle - Shared paint-time geometry. Canvas views use this on the UI thread;
GPU callbacks hold it behind a mutex (
Send + Sync). - Sprite
Instance - One batched sprite.
uvis in atlas texels normalized to 0..1. - World
Text - World-anchored text floater (damage numbers,
+25).
Enums§
- Pick
Event - UI-facing pointer events from the viewport.
Clickfires on pointer up when the press started inside and the pointer stayed within slop.Pressis the down-edge. - Sprite
Blend - Blend mode per sprite. Additive uses
SrcAlpha + One. Sorted into ranges (alpha, then multiply, then additive): push order across blend modes is NOT preserved, see the batch module docs.
Constants§
- CLICK_
SLOP_ DP - Press slop in dp: pointer-up farther than this from pointer-down
cancels the
Click(drag-off-cancel). Density-independent: compared after dividing physical-px deltas by the painted density, so a tap cancels identically on density 1 and density 3. - CLICK_
SLOP_ PX - Legacy physical-px slop value. Kept so old call sites keep compiling;
new code uses
CLICK_SLOP_DPviaclick_within_slop_dp.
Functions§
- Actor
Frame - World-anchored surface:
childis boxed to asizerect centered on a worldcenter, positioned throughFrameGeom.mirror_xflips about the surface center (rozvp horde case: centered content). Offsets trail the board by one frame under camera motion; steady state matches. For origin-bearing art (NT sprites with off-centerxorigin/yorigin), preferActorFrameWithOriginor the sprite batch’s anchor flips, which mirror about the anchor instead. - Actor
Frame With Origin - Origin-aware
ActorFrame:mirror_xflips about the normalizedorigin([0, 1], e.g. an NTxorigin / w) instead of the surface center. Setoriginfrom the catalog’sAnimDef::anchorwhen the surface content carries an off-center sprite origin. - Viewport2d
- 2D viewport view. Gesture handling and camera state live in the
FrameInputsnapshot. Fills its parent; drawsbackground, then sprites, then world texts, then the fullscreen tint. Each paint publishesFrameGeomtogeom_outfor dp-space siblings. - Viewport2d
Gpu - GPU twin of
Viewport2d: same snapshot in, same picks out, with sprites as textured atlas quads throughSpriteBatch. Fills its parent.backgroundpaints first andoverlay_colorlast, matching canvas except world texts, which stay canvas-side as sibling views. - Viewport2d
GpuWith Hud - Stack GPU sprites under canvas texts/tint from one
FrameInput. MountsViewport2dGpuplus a transparent canvas pass fortexts/overlay_color, so GPU games keep damage numbers and tints. - Viewport2d
GpuWith Id - GPU viewport with explicit batch id so a second viewport or minimap can coexist (each id owns its pipeline and instances).
- aim_
world - Continuous-aim inverse: like
pick_worldbut through an unshaken camera (offsetand trauma roll zeroed). Picks must track the painted view; aim must not inherit shake jitter. Pass the sameworld_sizeand density the viewport painted with, plus the look point and roll of the camera without shake applied. - aim_
world_ unshaken aim_worldstraight from aCamera2d: uses the follow target (center, no shakeoffset) with zero roll so firing aim never sprays with the noise function. Paint the viewport with the shaken camera; read aim with this.- click_
within_ slop_ dp - Dp-space slop check: physical-px points divided by
density(falling back to 1.0) before comparing againstCLICK_SLOP_DP. - contain_
fit - Contain-fit of a
worldextent into a dp-space canvas: uniform scale plus centering offsets.world_to_dp/dp_to_worldinvert each other for any positive scale. - cursor_
frame - dp_
to_ world - Inverse of
world_to_dp. Degenerate scales return the look point. - dp_
to_ world_ with_ roll - Inverse of
world_to_dp_with_roll. - effective_
fit - Effective fit for one frame: base contain-fit scaled by
zoom / units_per_pixel, re-centered. Default camera matchescontain_fit; zoom 2 doubles on-screen size on both backends. - fit_
view_ proj - GPU camera for the shared framing contract: matrix form of
world_to_dpovercanvas_dp(dp = physical px / density). - fit_
view_ proj_ with_ roll fit_view_projplus camera roll about the look point.0.0matchesfit_view_proj.- pick_
world - Viewport-local physical-px press to world point through the painted
FrameGeom. Takes the region-local position, so HUD chrome or a non-fullscreen viewport does not shift picks. - surface_
dp - World-anchored surface rect in dp:
([off_x, off_y], [w, h]).ActorFrameis its view form. The center rotates with roll about the pivot; size stays axis-aligned. - unproject_
px - Unproject one window-physical px point through this frame’s camera.
- world_
to_ dp - World point to dp canvas point through the fit. At the default
center (
world / 2) this isoffset + world * scale. - world_
to_ dp_ with_ roll world_to_dpplus camera roll aroundcam_center.