pub struct Texture<'a> { /* private fields */ }
Expand description
A KTX (1 or 2) texture.
This wraps both a sys::ktxTexture
handle, and the TextureSource
it was created from.
Implementations§
Source§impl<'a> Texture<'a>
impl<'a> Texture<'a>
Sourcepub fn new<S>(source: S) -> Result<Self, KtxError>where
S: TextureSource<'a>,
pub fn new<S>(source: S) -> Result<Self, KtxError>where
S: TextureSource<'a>,
Attempts to create a new texture, consuming the given TextureSource
.
Sourcepub fn write_to<T: TextureSink>(&self, sink: &mut T) -> Result<(), KtxError>
pub fn write_to<T: TextureSink>(&self, sink: &mut T) -> Result<(), KtxError>
Attempts to write the texture (in its native format, either KTX1 or KTX2) to sink
.
Sourcepub fn handle(&self) -> *mut ktxTexture
pub fn handle(&self) -> *mut ktxTexture
Returns the pointer to the (C-allocated) underlying sys::ktxTexture
.
SAFETY: Pointers are harmless. Dereferencing them is not!
Sourcepub fn row_pitch(&self, level: u32) -> usize
pub fn row_pitch(&self, level: u32) -> usize
Returns the pitch (in bytes) of an image row at the specified image level.
This is rounded up to 1 if needed.
Sourcepub fn element_size(&self) -> usize
pub fn element_size(&self) -> usize
Returns the size (in bytes) of an element of the image.
Sourcepub fn get_image_offset(
&self,
level: u32,
layer: u32,
slice: u32,
) -> Result<usize, KtxError>
pub fn get_image_offset( &self, level: u32, layer: u32, slice: u32, ) -> Result<usize, KtxError>
Attempts to return the offset (in bytes) into Self::data
for the image
at the given mip level, array layer, and slice.
slice
is either a cubemap’s face or a 3D texture’s depth slice.
Sourcepub fn get_data_size_uncompressed(&self) -> Result<usize, KtxError>
pub fn get_data_size_uncompressed(&self) -> Result<usize, KtxError>
Attempts to return the size (in bytes) of the uncompressed image data.
Sourcepub fn get_image_size(&self, level: u32) -> Result<usize, KtxError>
pub fn get_image_size(&self, level: u32) -> Result<usize, KtxError>
Attempts to return the size (in bytes) of a certain mip level.
Sourcepub fn load_image_data(&self) -> Result<(), KtxError>
pub fn load_image_data(&self) -> Result<(), KtxError>
Attempts to [re]load this image’s data to its internal buffer.
Also see Self::data()
.
Creating the image with [enums::TextureCreateFlags::LOAD_IMAGE_DATA
] performs this step automatically on load.
Sourcepub fn iterate_levels<F>(&self, callback: F) -> Result<(), KtxError>
pub fn iterate_levels<F>(&self, callback: F) -> Result<(), KtxError>
Attempts to iterate all mip levels of the image, and all faces of cubemaps. This calls
callback(miplevel: i32, face: i32, width: i32, height: i32, depth: i32, pixel_data: &[u8]) -> Result<(), KtxError>
for each level/face. The image data passed to the callback is immutable.
Note that image data should already have been loaded (see Self::load_image_data()
).
Sourcepub fn iterate_levels_mut<F>(&mut self, callback: F) -> Result<(), KtxError>
pub fn iterate_levels_mut<F>(&mut self, callback: F) -> Result<(), KtxError>
Attempts to iterate all mip levels of the image, and all faces of cubemaps. This calls
callback(miplevel: i32, face: i32, width: i32, height: i32, depth: i32, pixel_data: &mut [u8]) -> Result<(), KtxError>
for each level/face. The image data passed to the callback is mutable.
Note that image data should already have been loaded (see Self::load_image_data()
).