pub struct SpriteRenderSystem<B: RenderBackend> { /* private fields */ }Expand description
System for rendering 2D sprites using batched rendering.
This system:
- Queries all entities with Sprite + Transform2D components
- Batches sprites by texture to minimize draw calls
- Sorts by Z-layer for correct rendering order
- Submits draw calls to the GPU backend
§Performance
Target: <100 draw calls for 10,000 sprites (100:1 batch ratio)
Implementations§
Source§impl<B: RenderBackend> SpriteRenderSystem<B>
impl<B: RenderBackend> SpriteRenderSystem<B>
Sourcepub fn new(backend: B) -> GoudResult<Self>
pub fn new(backend: B) -> GoudResult<Self>
Creates a new sprite render system with the given backend.
Sourcepub fn with_config(backend: B, config: SpriteBatchConfig) -> GoudResult<Self>
pub fn with_config(backend: B, config: SpriteBatchConfig) -> GoudResult<Self>
Creates a new sprite render system with custom configuration.
Sourcepub fn run(
&mut self,
world: &World,
asset_server: &AssetServer,
) -> GoudResult<()>
pub fn run( &mut self, world: &World, asset_server: &AssetServer, ) -> GoudResult<()>
Runs the sprite rendering system.
This should be called once per frame, after all game logic has been updated.
§Arguments
world- The ECS world containing sprite entitiesasset_server- Asset server for loading textures
§Errors
Returns an error if:
- Shader compilation fails
- Buffer allocation fails
- GPU operations fail
Sourcepub fn stats(&self) -> (usize, usize, f32)
pub fn stats(&self) -> (usize, usize, f32)
Gets rendering statistics from the last frame.
Returns (sprite_count, batch_count, batch_ratio) tuple.
Sourcepub fn sprite_batch(&self) -> &SpriteBatch<B>
pub fn sprite_batch(&self) -> &SpriteBatch<B>
Gets a reference to the underlying sprite batch.
Sourcepub fn sprite_batch_mut(&mut self) -> &mut SpriteBatch<B>
pub fn sprite_batch_mut(&mut self) -> &mut SpriteBatch<B>
Gets a mutable reference to the underlying sprite batch.
Trait Implementations§
Auto Trait Implementations§
impl<B> Freeze for SpriteRenderSystem<B>where
B: Freeze,
impl<B> RefUnwindSafe for SpriteRenderSystem<B>where
B: RefUnwindSafe,
impl<B> Send for SpriteRenderSystem<B>
impl<B> Sync for SpriteRenderSystem<B>
impl<B> Unpin for SpriteRenderSystem<B>where
B: Unpin,
impl<B> UnsafeUnpin for SpriteRenderSystem<B>where
B: UnsafeUnpin,
impl<B> UnwindSafe for SpriteRenderSystem<B>where
B: UnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more