pub struct SpriteBatcher<K> { /* private fields */ }Expand description
Sorts a frame’s sprites, groups them into batches by texture, and packs
the instance of each one drawn: what the Renderer
does on the CPU before it uploads the instances and draws. It is public
so that this work can be measured without a GPU. The renderer gives it
the frame’s texts’ glyphs too, laid out, which it plans with the
sprites.
It is generic over the texture K: the renderer’s is its GPU texture,
and a benchmark can use any number. Its lists are reused from one build
to the next, so a steady frame allocates nothing.
Implementations§
Source§impl<K: Copy + Eq> SpriteBatcher<K>
impl<K: Copy + Eq> SpriteBatcher<K>
Sourcepub fn build(
&mut self,
sprites: &[SpriteDraw],
camera: &Camera2D,
texture: impl FnMut(&SpriteDraw) -> Option<(K, bool)>,
)
pub fn build( &mut self, sprites: &[SpriteDraw], camera: &Camera2D, texture: impl FnMut(&SpriteDraw) -> Option<(K, bool)>, )
Sorts, batches and packs sprites as camera shows them, in
pixel-perfect mode.
texture gives each sprite’s texture: None while it is not ready,
and the sprite is not drawn. Otherwise it gives the texture, and
whether the sprite shows that texture’s placeholder, all of it
whatever its uv, as a sprite whose texture failed to load does.
Sourcepub fn instances(&self) -> &[f32]
pub fn instances(&self) -> &[f32]
The instances of the sprites and glyphs drawn, in draw order:
SPRITE_INSTANCE_FLOATS floats
each.
Sourcepub fn stats(&self) -> FrameStats
pub fn stats(&self) -> FrameStats
What the last build drew. It knows nothing of tile layers, of texts
or of the UI: tiles, chunks, texts, skipped_texts and the
ui_ counts are 0, and batches counts the batches before a tile
layer drawn among the sprites splits one in two.