pub struct SpriteRenderer { /* private fields */ }
Expand description

SpriteRenderer hosts a number of sprite groups. Each group has a specified spritesheet texture array, parallel vectors of Transforms and SheetRegions, and a Camera2D to define its transform. Currently, all groups render into the same depth buffer so their outputs are interleaved.

Implementations§

source§

impl SpriteRenderer

source

pub fn add_sprite_group( &mut self, gpu: &WGPU, tex: &Texture, world_transforms: Vec<Transform>, sheet_regions: Vec<SheetRegion>, camera: Camera2D ) -> usize

Create a new sprite group sized to fit sprites. Returns a sprite group identifier (for now, a usize).

source

pub fn sprite_group_count(&self) -> usize

Returns the number of sprite groups

source

pub fn remove_sprite_group(&mut self, which: usize)

Deletes a sprite group. Note that this currently invalidates all the old handles, which is not great. Only use it on the last sprite group if that matters to you.

source

pub fn sprite_group_size(&self, which: usize) -> usize

Reports the size of the given sprite group.

source

pub fn resize_sprite_group( &mut self, gpu: &WGPU, which: usize, len: usize ) -> usize

Resizes a sprite group. If the new size is smaller, this is very cheap; if it’s larger than it’s ever been before, it might involve reallocating the Vec<Transform>, Vec<SheetRegion>, or the GPU buffer used to draw sprites, so it could be expensive.

source

pub fn set_camera_all(&mut self, gpu: &WGPU, camera: Camera2D)

Set the given camera transform on all sprite groups. Uploads to the GPU.

source

pub fn set_camera(&mut self, gpu: &WGPU, which: usize, camera: Camera2D)

Set the given camera transform on a specific sprite group. Uploads to the GPU.

source

pub fn upload_sprites(&mut self, gpu: &WGPU, which: usize, range: Range<usize>)

Send a range of stored sprite data for a particular group to the GPU. You must call this yourself after modifying sprite data.

source

pub fn upload_world_transforms( &mut self, gpu: &WGPU, which: usize, range: Range<usize> )

Upload only position changes to the GPU

source

pub fn upload_sheet_regions( &mut self, gpu: &WGPU, which: usize, range: Range<usize> )

Upload only visual changes to the GPU

source

pub fn get_sprites(&self, which: usize) -> (&[Transform], &[SheetRegion])

Get a read-only slice of a specified sprite group’s world transforms and texture regions.

source

pub fn get_sprites_mut( &mut self, which: usize ) -> (&mut [Transform], &mut [SheetRegion])

Get a mutable slice of a specified sprite group’s world transforms and texture regions.

source

pub fn render<'s, 'pass>( &'s self, rpass: &mut RenderPass<'pass>, which: impl RangeBounds<usize> )where 's: 'pass,

Render the given range of sprite groups into the given pass.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for Twhere T: Send,

§

impl<T> WasmNotSync for Twhere T: Sync,