Skip to main content

SpriteBatcher

Struct SpriteBatcher 

Source
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>

Source

pub fn new() -> Self

A batcher that has built nothing yet.

Source

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.

Source

pub fn instances(&self) -> &[f32]

The instances of the sprites and glyphs drawn, in draw order: SPRITE_INSTANCE_FLOATS floats each.

Source

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.

Trait Implementations§

Source§

impl<K: Debug> Debug for SpriteBatcher<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: Copy + Eq> Default for SpriteBatcher<K>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K> Forget for SpriteBatcher<K>

§

impl<K> Freeze for SpriteBatcher<K>
where Plan<(K, Pipe)>: Freeze,

§

impl<K> Move for SpriteBatcher<K>

§

impl<K> RefUnwindSafe for SpriteBatcher<K>
where Plan<(K, Pipe)>: RefUnwindSafe,

§

impl<K> Send for SpriteBatcher<K>
where Plan<(K, Pipe)>: Send,

§

impl<K> Sync for SpriteBatcher<K>
where Plan<(K, Pipe)>: Sync,

§

impl<K> Unpin for SpriteBatcher<K>
where Plan<(K, Pipe)>: Unpin,

§

impl<K> UnsafeUnpin for SpriteBatcher<K>
where Plan<(K, Pipe)>: UnsafeUnpin,

§

impl<K> UnwindSafe for SpriteBatcher<K>
where Plan<(K, Pipe)>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.