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
Transform
s and SheetRegion
s, and a Camera2D
to define
its transform. All groups render into the same depth
buffer, so their outputs are interleaved.
Implementations§
Source§impl SpriteRenderer
impl SpriteRenderer
Sourcepub fn new(
gpu: &WGPU,
color_target: ColorTargetState,
depth_format: TextureFormat,
) -> Self
pub fn new( gpu: &WGPU, color_target: ColorTargetState, depth_format: TextureFormat, ) -> Self
Create a new SpriteRenderer
meant to draw into the given color target and with the given depth texture format.
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 world_transforms
and
sheet_regions
, which should be the same length. Returns the
sprite group index corresponding to this group.
Sourcepub fn sprite_group_count(&self) -> usize
pub fn sprite_group_count(&self) -> usize
Returns the number of sprite groups (including placeholders for removed groups).
Sourcepub fn remove_sprite_group(&mut self, which: usize)
pub fn remove_sprite_group(&mut self, which: usize)
Deletes a sprite group, leaving an empty group slot behind (this might get recycled later).
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. Panics if the given sprite group is not populated.
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. If this happens, the buffer will
also be uploaded to prevent garbage data from being used in
the shader. To avoid redundant work, resize upwards as few
times as possible.
Panics if the given sprite group is not populated.
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. Panics if the given sprite group is not populated.
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. Panics if the given sprite group is not populated.
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. Panics if the given sprite group is not populated.
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. Panics if the given sprite group is not populated.
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. Panics if the given sprite group is not populated.
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. Panics if the given sprite group is not populated.
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.
Auto Trait Implementations§
impl Freeze for SpriteRenderer
impl !RefUnwindSafe for SpriteRenderer
impl Send for SpriteRenderer
impl Sync for SpriteRenderer
impl Unpin for SpriteRenderer
impl !UnwindSafe for SpriteRenderer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.