ssplayer_wgpu/frame.rs
1//! A borrowed view of one frame's rendering input.
2//!
3//! The runtime owns the FrameData and SoA buffers; this only references them.
4//! The slices are valid immediately after the runtime produces the frame and
5//! may be invalidated by the next frame fetch, so do not hold them across
6//! frames.
7
8/// Floats between one part's shape vertices and the next in
9/// [`FrameView::shape_vertices`] and [`FrameView::shape_vertex_box_coords`].
10///
11/// The runtime lays both out at a fixed stride rather than packing them, so a
12/// part's live vertex count (`shape_vertex_counts`) says how much of its slot is
13/// real. Shared because two readers derive offsets from it, and a stride that
14/// disagreed between them would read another part's shape.
15pub(crate) const SHAPE_VERTICES_STRIDE: usize = 24;
16
17/// Everything [`crate::SSScene`] needs to draw one frame, as borrows into
18/// runtime-owned data.
19#[derive(Clone, Copy, Default)]
20pub struct FrameView<'a> {
21 /// FlatBuffers-encoded `FrameData` (draw_order / draw_batches / parts / parts_color).
22 pub frame_data: &'a [u8],
23 /// `part_index * 16`, column-major 4x4 world matrix per part.
24 pub world_matrices: &'a [f32],
25 /// `part_index * 10` = `[lt, rt, lb, rb, center]` * xy (pivot/flip/deform/coordinate-flip applied).
26 pub local_vertices: &'a [f32],
27 /// `part_index * 10` (same layout as vertices; UVs in texture pixel space).
28 pub local_uvs: &'a [f32],
29 /// Skinned mesh vertex X, flat (sliced by `mesh_vertex_offsets`).
30 pub mesh_vertices_x: &'a [f32],
31 /// Skinned mesh vertex Y.
32 pub mesh_vertices_y: &'a [f32],
33 /// Prefix-sum of length parts+1; part `i` spans `[offsets[i], offsets[i+1])`.
34 pub mesh_vertex_offsets: &'a [u32],
35 /// Mesh UVs (vertex index * 2, texture pixel space).
36 pub mesh_uvs: &'a [f32],
37 /// Mesh indices (part-relative; rebased with `base_vert_idx + rel_idx`).
38 pub mesh_indices: &'a [i32],
39 /// Prefix-sum of length parts+1 for mesh index ranges.
40 pub mesh_index_offsets: &'a [u32],
41 /// Shape vertices (local xy), `part_index * SHAPE_VERTICES_STRIDE` (=24);
42 /// each part's live vertex count is in `shape_vertex_counts`.
43 pub shape_vertices: &'a [f32],
44 /// Per-part shape vertex box coordinates (fx, fy in 0..1), same stride as
45 /// `shape_vertices`. Used to bilinearly interpolate the shape's fill color.
46 pub shape_vertex_box_coords: &'a [f32],
47 /// Per-part shape vertex count (0 when the part is not a shape).
48 pub shape_vertex_counts: &'a [i32],
49}