Skip to main content

combs_mesh/render/
mod.rs

1//! Sprite rendering.
2//!
3//! [`Renderer`] is the seam: frame extraction + alpha compositing onto an
4//! RGBA8 canvas. v1 ships only [`CpuRenderer`] (zero-dep byte math); a
5//! wgpu renderer can slot in behind the same trait later (deliberately
6//! deferred — the mesh core carries no GPU dependency).
7
8mod cpu;
9#[cfg(feature = "gpu")]
10pub mod gpu;
11
12pub use cpu::CpuRenderer;
13#[cfg(feature = "gpu")]
14pub use gpu::WgpuRenderer;
15
16use crate::blocks::SpriteAtlas;
17use crate::error::Result;
18
19/// A sprite renderer.
20pub trait Renderer {
21    /// Extracts frame `frame_index` as `frame_width * frame_height * 4`
22    /// RGBA8 bytes.
23    fn render_frame(&self, atlas: &SpriteAtlas, frame_index: u32) -> Result<Vec<u8>>;
24
25    /// Composites `layers` — `(atlas, frame_index, x, y)` — onto a
26    /// transparent `width`×`height` canvas (src-over alpha blending),
27    /// returning `width * height * 4` RGBA8 bytes. Layers are painted in
28    /// order (later = on top); out-of-canvas pixels are clipped.
29    fn compose(
30        &self,
31        layers: &[(&SpriteAtlas, u32, i32, i32)],
32        width: u32,
33        height: u32,
34    ) -> Result<Vec<u8>>;
35}