pub struct TextureFile {
pub bytes: Vec<u8>,
pub size: Size2D,
pub fmt: ImgFormat,
pub filter: ImgFilter,
pub wrap: ImgWrap,
}Expand description
A texture loaded from disk (or cache) with metadata.
§Loading
ⓘ
use optic_render::asset::TextureFile;
let tex = TextureFile::from_disk("textures/wood.png")?;
let gpu_tex = tex.ship(); // uploads to GPU§Caching
In debug builds, from_disk loads the source image and writes a binary
cache (.otxtr). In release builds, it reads the cache directly for
faster startup.
Fields§
§bytes: Vec<u8>§size: Size2D§fmt: ImgFormat§filter: ImgFilter§wrap: ImgWrapImplementations§
Source§impl TextureFile
impl TextureFile
Sourcepub fn pixel_count(&self) -> usize
pub fn pixel_count(&self) -> usize
Returns the total pixel count (width × height).
Sourcepub fn set_filter(&mut self, filter: ImgFilter)
pub fn set_filter(&mut self, filter: ImgFilter)
Overrides the filter mode (used before ship).
Sourcepub fn ship(&self) -> Texture2D
pub fn ship(&self) -> Texture2D
Uploads this texture to the GPU and returns a Texture2D handle.
Sourcepub fn fallback() -> OpticResult<Self>
pub fn fallback() -> OpticResult<Self>
Loads the fallback texture from optic/assets/txtr/fallback.png.
Source§impl TextureFile
impl TextureFile
Sourcepub fn from_disk(path: &str) -> OpticResult<Self>
pub fn from_disk(path: &str) -> OpticResult<Self>
Loads a texture from disk, caching it for release builds.
Source§impl TextureFile
impl TextureFile
Sourcepub fn save_cached(&self, path: &str) -> OpticResult<()>
pub fn save_cached(&self, path: &str) -> OpticResult<()>
Saves this texture to a binary cache file.
Auto Trait Implementations§
impl Freeze for TextureFile
impl RefUnwindSafe for TextureFile
impl Send for TextureFile
impl Sync for TextureFile
impl Unpin for TextureFile
impl UnsafeUnpin for TextureFile
impl UnwindSafe for TextureFile
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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