pub struct TextureAtlas {
pub config: AtlasConfig,
pub pixels: Vec<u8>,
/* private fields */
}Expand description
Texture atlas packer.
Allocates rectangular regions inside a fixed-size backing texture using a
shelf-packing strategy. The CPU-side pixel data is stored in pixels so
the atlas can be uploaded to the GPU at any time.
Fields§
§config: AtlasConfigConfiguration.
pixels: Vec<u8>CPU-side RGBA pixel data for the backing texture.
Size = config.width * config.height * 4 bytes.
Implementations§
Source§impl TextureAtlas
impl TextureAtlas
Sourcepub fn new(config: AtlasConfig) -> Self
pub fn new(config: AtlasConfig) -> Self
Create a new, empty atlas.
Sourcepub fn insert(&mut self, w: u32, h: u32) -> Result<u32>
pub fn insert(&mut self, w: u32, h: u32) -> Result<u32>
Insert a sub-texture of w × h texels.
Returns an opaque allocation ID on success.
§Errors
Returns GpuError::Internal if the atlas has no space left or if the
requested dimensions exceed the atlas size.
Sourcepub fn upload_pixels(&mut self, id: u32, data: &[u8]) -> Result<()>
pub fn upload_pixels(&mut self, id: u32, data: &[u8]) -> Result<()>
Upload RGBA pixel data for the sub-texture identified by id.
data must be exactly w * h * 4 bytes.
§Errors
Returns an error if id is invalid or data has wrong length.
Sourcepub fn rect(&self, id: u32) -> Option<AtlasRect>
pub fn rect(&self, id: u32) -> Option<AtlasRect>
Return the allocated AtlasRect for id, or None if unknown.
Sourcepub fn utilisation(&self) -> f32
pub fn utilisation(&self) -> f32
Utilisation as a fraction in [0, 1] (pixels used / total pixels).
Auto Trait Implementations§
impl Freeze for TextureAtlas
impl RefUnwindSafe for TextureAtlas
impl Send for TextureAtlas
impl Sync for TextureAtlas
impl Unpin for TextureAtlas
impl UnsafeUnpin for TextureAtlas
impl UnwindSafe for TextureAtlas
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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