Struct frenderer::SpriteRenderer
source · 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
impl SpriteRenderer
sourcepub fn add_sprite_group(
&mut self,
gpu: &WGPU,
tex: &Texture,
world_transforms: Vec<Transform>,
sheet_regions: Vec<SheetRegion>,
camera: Camera2D
) -> usize
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).
sourcepub fn sprite_group_count(&self) -> usize
pub fn sprite_group_count(&self) -> usize
Returns the number of sprite groups
sourcepub fn remove_sprite_group(&mut self, which: usize)
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.
sourcepub fn sprite_group_size(&self, which: usize) -> usize
pub fn sprite_group_size(&self, which: usize) -> usize
Reports the size of the given sprite group.
sourcepub fn resize_sprite_group(
&mut self,
gpu: &WGPU,
which: usize,
len: usize
) -> usize
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.
sourcepub fn set_camera_all(&mut self, gpu: &WGPU, camera: Camera2D)
pub fn set_camera_all(&mut self, gpu: &WGPU, camera: Camera2D)
Set the given camera transform on all sprite groups. Uploads to the GPU.
sourcepub fn set_camera(&mut self, gpu: &WGPU, which: usize, camera: Camera2D)
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.
sourcepub fn upload_sprites(&mut self, gpu: &WGPU, which: usize, range: Range<usize>)
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.
sourcepub fn upload_world_transforms(
&mut self,
gpu: &WGPU,
which: usize,
range: Range<usize>
)
pub fn upload_world_transforms( &mut self, gpu: &WGPU, which: usize, range: Range<usize> )
Upload only position changes to the GPU
sourcepub fn upload_sheet_regions(
&mut self,
gpu: &WGPU,
which: usize,
range: Range<usize>
)
pub fn upload_sheet_regions( &mut self, gpu: &WGPU, which: usize, range: Range<usize> )
Upload only visual changes to the GPU
sourcepub fn get_sprites(&self, which: usize) -> (&[Transform], &[SheetRegion])
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.
sourcepub fn get_sprites_mut(
&mut self,
which: usize
) -> (&mut [Transform], &mut [SheetRegion])
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.
sourcepub fn render<'s, 'pass>(
&'s self,
rpass: &mut RenderPass<'pass>,
which: impl RangeBounds<usize>
)where
's: 'pass,
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.