Struct epaint::textures::TextureManager

source ·
pub struct TextureManager {
    next_id: u64,
    metas: HashMap<TextureId, TextureMeta>,
    delta: TexturesDelta,
}
Expand description

Low-level manager for allocating textures.

Communicates with the painting subsystem using Self::take_delta.

Fields§

§next_id: u64

We allocate texture id:s linearly.

§metas: HashMap<TextureId, TextureMeta>

Information about currently allocated textures.

§delta: TexturesDelta

Implementations§

source§

impl TextureManager

source

pub fn alloc( &mut self, name: String, image: ImageData, options: TextureOptions, ) -> TextureId

Allocate a new texture.

The given name can be useful for later debugging.

The returned TextureId will be TextureId::Managed, with an index starting from zero and increasing with each call to Self::alloc.

The first texture you allocate will be TextureId::Managed(0) == TextureId::default() and MUST have a white pixel at (0,0) (crate::WHITE_UV).

The texture is given a retain-count of 1, requiring one call to Self::free to free it.

source

pub fn set(&mut self, id: TextureId, delta: ImageDelta)

Assign a new image to an existing texture, or update a region of it.

source

pub fn free(&mut self, id: TextureId)

Free an existing texture.

source

pub fn retain(&mut self, id: TextureId)

Increase the retain-count of the given texture.

For each time you call Self::retain you must call Self::free on additional time.

source

pub fn take_delta(&mut self) -> TexturesDelta

Take and reset changes since last frame.

These should be applied to the painting subsystem each frame.

source

pub fn meta(&self, id: TextureId) -> Option<&TextureMeta>

Get meta-data about a specific texture.

source

pub fn allocated( &self, ) -> impl ExactSizeIterator<Item = (&TextureId, &TextureMeta)>

Get meta-data about all allocated textures in some arbitrary order.

source

pub fn num_allocated(&self) -> usize

Total number of allocated textures.

Trait Implementations§

source§

impl Default for TextureManager

source§

fn default() -> TextureManager

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

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 T
where U: TryFrom<T>,

source§

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.