Module sprite_pipeline

Module sprite_pipeline 

Source
Expand description

Sprite (§5) GPU pipeline.

Renders one textured quad per active sprite into render_texture, between the custom-shape pass and the borders pass. Two pipelines cover the two blend modes the engine emits (SpriteBlendKind — alpha or additive). Each sprite draw owns its own bind group recreated per frame so we can bind a different texture per draw without an atlas (sprites in the wild are few, ~handful per frame, so per-draw bind groups are cheap).

The renderer drives this through SpritePipeline::record, which takes a slice of SpriteDrawCmd produced by [crate::sprite_pipeline::SpritePool::build_draw_commands]. The pool resolves the engine-side texture_index to a real [wgpu::TextureView], applies aspect ratio correction, and packs the per-sprite uniform.

Structs§

SpriteDrawCmd
One sprite ready to draw. The renderer assembles these from the engine’s SpriteFrame list + the sprite SpritePool.
SpriteFrame
One per-frame sprite the engine asks the renderer to draw. POD — no GPU resources, just numbers. The renderer resolves the texture_index through its SpritePool and builds the SpriteDrawCmd internally each frame.
SpritePipeline
Sprite GPU pipeline. Owns two RenderPipelines (alpha + additive) and a per-slot uniform buffer; the renderer constructs / drives it once per chain.
SpritePool
Sprite texture pool: one texture per sprite def, in load order. Engine-side SpriteRenderInstance::texture_index indexes into textures directly. Missing / undecodable files get a 1×1 transparent fallback so the bind group always populates.
SpriteTexture
One GPU-resident sprite texture.
SpriteUniform
Per-sprite uniform pushed to the GPU each draw. 48 bytes; the pipeline allocates MAX_ACTIVE_SPRITES * 256 B total uniform storage so each draw can dynamic-offset into its own slot.

Enums§

SpriteBlendKind
Which of the two GPU pipelines to use for a given sprite. Mirrors onedrop_engine::SpriteBlendMode; kept independent so the renderer compiles without an engine-side dep cycle.

Constants§

MAX_ACTIVE_SPRITES
Hard cap on simultaneously active sprites. The active list is pruned every tick so this only matters during a key-mash spawn burst; 64 is well above MD2’s practical limit (~5-10).

Functions§

build_sprite_uniform
Build a SpriteUniform from raw engine-side numbers + texture dimensions + render aspect ratio. Pulled out so the renderer’s update_sprites step can produce a single contiguous list of uniforms for upload + the matching draw-cmd list without recomputing aspect ratios per call.
default_sprite_dirs
Default search paths for sprite assets. The engine extends this with config-driven dirs.
load_sprite_file 🔒
make_fallback 🔒
pick_first_existing
Pick the first existing directory from a search-path list.
upload_sprite_rgba8 🔒