pub struct TextureManager { /* private fields */ }Expand description
A manager for textures providing granular control over texture handling.
This manager allows for:
- Loading textures from different threads while keeping usage safe in the rendering thread.
- Allocating textures and subsequently loading image data into them.
- Updating the data in an existing texture.
§Examples
Allocate a texture and then load data into it:
let texture_manager = renderer.texture_manager();
let texture_id = 42;
let texture_dimensions = (256, 256);
let data = vec![255u8; 256 * 256 * 4];
// Allocate texture and load data
texture_manager.allocate_texture_with_data(texture_id, texture_dimensions, &data);
// Update data in the texture
texture_manager.load_data_into_texture(texture_id, texture_dimensions, &data).unwrap();
// Check if the texture is loaded
assert!(texture_manager.is_texture_loaded(texture_id));
// Clone the texture manager to pass to another thread
let texture_manager_clone = texture_manager.clone();The texture manager internally uses an Arc<RwLock<_>> to manage its bind group layout and texture storage.
Implementations§
Source§impl TextureManager
impl TextureManager
Sourcepub fn allocate_texture(&self, texture_id: u64, texture_dimensions: (u32, u32))
pub fn allocate_texture(&self, texture_id: u64, texture_dimensions: (u32, u32))
Allocates a new RGBA8 texture with the given dimensions without providing any data.
If you want to allocate and load data into the texture at the same time, use
TextureManager::allocate_texture_with_data instead.
You can then load data into the texture later using TextureManager::load_data_into_texture.
§Parameters
texture_id: Unique identifier for the texture.texture_dimensions: A tuple(width, height)representing the dimensions of the texture.
Sourcepub fn allocate_texture_with_data(
&self,
texture_id: u64,
texture_dimensions: (u32, u32),
texture_data: &[u8],
)
pub fn allocate_texture_with_data( &self, texture_id: u64, texture_dimensions: (u32, u32), texture_data: &[u8], )
Allocates a texture and immediately loads image data into it.
This function will first allocate the texture, then attempt to load the provided data.
§Parameters
texture_id: Unique identifier for the texture.texture_dimensions: A tuple(width, height)representing the dimensions of the texture.texture_data: A byte slice containing the image data. The data length is expected to match the texture dimensions and pixel format (RGBA8).
Sourcepub fn load_data_into_texture(
&self,
texture_id: u64,
texture_dimensions: (u32, u32),
texture_data: &[u8],
) -> Result<(), TextureManagerError>
pub fn load_data_into_texture( &self, texture_id: u64, texture_dimensions: (u32, u32), texture_data: &[u8], ) -> Result<(), TextureManagerError>
Loads image data into an already allocated texture.
§Parameters
texture_id: Unique identifier for the texture.texture_dimensions: A tuple(width, height)representing the dimensions of the texture.texture_data: A byte slice containing the image data in an RGBA8 format.
§Returns
Ok(())if the operation succeeds.Err(TextureManagerError::TextureNotFound(texture_id))if the texture does not exist.
pub fn is_texture_loaded(&self, texture_id: u64) -> bool
Trait Implementations§
Source§impl Clone for TextureManager
impl Clone for TextureManager
Source§fn clone(&self) -> TextureManager
fn clone(&self) -> TextureManager
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TextureManager
impl !RefUnwindSafe for TextureManager
impl Send for TextureManager
impl Sync for TextureManager
impl Unpin for TextureManager
impl !UnwindSafe for TextureManager
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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