pub struct Atlas { /* private fields */ }
Expand description
A texture atlas, used to store all the textures in a scene.
Clones of Atlas
all point to the same internal data.
Implementations§
Source§impl Atlas
impl Atlas
pub fn device(&self) -> &Device
Sourcepub fn new(
slab: &SlabAllocator<WgpuRuntime>,
size: Extent3d,
format: Option<TextureFormat>,
label: Option<&str>,
usage: Option<TextureUsages>,
) -> Self
pub fn new( slab: &SlabAllocator<WgpuRuntime>, size: Extent3d, format: Option<TextureFormat>, label: Option<&str>, usage: Option<TextureUsages>, ) -> Self
pub fn descriptor_id(&self) -> Id<AtlasDescriptor>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn get_texture(&self) -> impl Deref<Target = Texture> + '_
pub fn get_texture(&self) -> impl Deref<Target = Texture> + '_
Returns a reference to the current atlas texture array.
pub fn get_layers(&self) -> impl Deref<Target = Vec<Layer>> + '_
Sourcepub fn set_images(
&self,
images: &[AtlasImage],
) -> Result<Vec<AtlasTexture>, AtlasError>
pub fn set_images( &self, images: &[AtlasImage], ) -> Result<Vec<AtlasTexture>, AtlasError>
Reset this atlas with all new images.
Any existing Hybrid<AtlasTexture>
s will be invalidated.
pub fn get_size(&self) -> Extent3d
Sourcepub fn add_images<'a>(
&self,
images: impl IntoIterator<Item = &'a AtlasImage>,
) -> Result<Vec<AtlasTexture>, AtlasError>
pub fn add_images<'a>( &self, images: impl IntoIterator<Item = &'a AtlasImage>, ) -> Result<Vec<AtlasTexture>, AtlasError>
Add the given images
Sourcepub fn add_image(&self, image: &AtlasImage) -> Result<AtlasTexture, AtlasError>
pub fn add_image(&self, image: &AtlasImage) -> Result<AtlasTexture, AtlasError>
Add one image.
If you have more than one image, you should use Atlas::add_images
, as every
change in images causes a repacking, which might be expensive.
Sourcepub fn resize(
&self,
runtime: impl AsRef<WgpuRuntime>,
extent: Extent3d,
) -> Result<(), AtlasError>
pub fn resize( &self, runtime: impl AsRef<WgpuRuntime>, extent: Extent3d, ) -> Result<(), AtlasError>
Resize the atlas.
This also distributes the images by size among all layers in an effort to reduce the likelyhood that packing the atlas may fail.
§Errors
Errors if size
has a width or height that is not a power of two, or are unequal
Sourcepub fn upkeep(&self, runtime: impl AsRef<WgpuRuntime>) -> bool
pub fn upkeep(&self, runtime: impl AsRef<WgpuRuntime>) -> bool
Perform upkeep on the atlas.
This removes any TextureFrame
s that have no references and repacks the atlas
if any were removed.
Returns true
if the atlas texture was recreated.
Sourcepub fn atlas_img_buffer(
&self,
runtime: impl AsRef<WgpuRuntime>,
layer: u32,
) -> CopiedTextureBuffer
pub fn atlas_img_buffer( &self, runtime: impl AsRef<WgpuRuntime>, layer: u32, ) -> CopiedTextureBuffer
Read the atlas image from the GPU into a CopiedTextureBuffer
.
This is primarily for testing.
§Panics
Panics if the pixels read from the GPU cannot be read.
Sourcepub async fn atlas_img(
&self,
runtime: impl AsRef<WgpuRuntime>,
layer: u32,
) -> RgbaImage
pub async fn atlas_img( &self, runtime: impl AsRef<WgpuRuntime>, layer: u32, ) -> RgbaImage
Read the atlas image from the GPU.
This is primarily for testing.
The resulting image will be in a linear color space.
§Panics
Panics if the pixels read from the GPU cannot be converted into an
RgbaImage
.
pub async fn read_images( &self, runtime: impl AsRef<WgpuRuntime>, ) -> Vec<RgbaImage> ⓘ
Sourcepub fn update_texture(
&self,
atlas_texture: &AtlasTexture,
source_texture: &Texture,
) -> Result<SubmissionIndex, AtlasError>
pub fn update_texture( &self, atlas_texture: &AtlasTexture, source_texture: &Texture, ) -> Result<SubmissionIndex, AtlasError>
Update the given AtlasTexture
with a Texture
.
This will blit the Texture
into the frame of the Atlas
pointed to by the
AtlasTexture
.
Returns a submission index that can be polled with [wgpu::Device::poll
].
Sourcepub fn update_textures<'a>(
&self,
updates: impl IntoIterator<Item = (&'a AtlasTexture, &'a Texture)>,
) -> Result<SubmissionIndex, AtlasError>
pub fn update_textures<'a>( &self, updates: impl IntoIterator<Item = (&'a AtlasTexture, &'a Texture)>, ) -> Result<SubmissionIndex, AtlasError>
Update the given AtlasTexture
s with Texture
s.
This will blit the Texture
into the frame of the Atlas
pointed to by the
AtlasTexture
.
Returns a submission index that can be polled with [wgpu::Device::poll
].
Sourcepub fn update_images<'a>(
&self,
updates: impl IntoIterator<Item = (&'a AtlasTexture, impl Into<AtlasImage>)>,
) -> Result<SubmissionIndex, AtlasError>
pub fn update_images<'a>( &self, updates: impl IntoIterator<Item = (&'a AtlasTexture, impl Into<AtlasImage>)>, ) -> Result<SubmissionIndex, AtlasError>
Update the given AtlasTexture
s with new data.
This will blit the image data into the frame of the Atlas
pointed to by the
AtlasTexture
.
Returns a submission index that can be polled with [wgpu::Device::poll
].
Sourcepub fn update_image(
&self,
atlas_texture: &AtlasTexture,
source_image: impl Into<AtlasImage>,
) -> Result<SubmissionIndex, AtlasError>
pub fn update_image( &self, atlas_texture: &AtlasTexture, source_image: impl Into<AtlasImage>, ) -> Result<SubmissionIndex, AtlasError>
Update the given AtlasTexture
s with new data.
This will blit the image data into the frame of the Atlas
pointed to by the
AtlasTexture
.
Returns a submission index that can be polled with [wgpu::Device::poll
].
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Atlas
impl !RefUnwindSafe for Atlas
impl Send for Atlas
impl Sync for Atlas
impl Unpin for Atlas
impl !UnwindSafe for Atlas
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute
] value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
[Quirk
] value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition
] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);