Struct Texture

Source
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>

Source

pub fn new<S>(source: S) -> Result<Self, KtxError>
where S: TextureSource<'a>,

Attempts to create a new texture, consuming the given TextureSource.

Source

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.

Source

pub fn handle(&self) -> *mut ktxTexture

Returns the pointer to the (C-allocated) underlying sys::ktxTexture.

SAFETY: Pointers are harmless. Dereferencing them is not!

Source

pub fn data_size(&self) -> usize

Returns the total size of image data, in bytes.

Source

pub fn data(&self) -> &[u8]

Returns a read-only view on the image data.

Source

pub fn data_mut(&mut self) -> &mut [u8]

Returns a read-write view on the image data.

Source

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.

Source

pub fn element_size(&self) -> usize

Returns the size (in bytes) of an element of the image.

Source

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.

Source

pub fn get_data_size_uncompressed(&self) -> Result<usize, KtxError>

Attempts to return the size (in bytes) of the uncompressed image data.

Source

pub fn get_image_size(&self, level: u32) -> Result<usize, KtxError>

Attempts to return the size (in bytes) of a certain mip level.

Source

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.

Source

pub fn iterate_levels<F>(&self, callback: F) -> Result<(), KtxError>
where F: FnMut(i32, i32, i32, i32, i32, &[u8]) -> 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()).

Source

pub fn iterate_levels_mut<F>(&mut self, callback: F) -> Result<(), KtxError>
where F: FnMut(i32, i32, i32, i32, i32, &mut [u8]) -> 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()).

Source

pub fn ktx1<'b>(&'b mut self) -> Option<Ktx1<'b, 'a>>

If this Texture really is a KTX1, returns KTX1-specific functionalities for it.

Source

pub fn ktx2<'b>(&'b mut self) -> Option<Ktx2<'b, 'a>>

If this Texture really is a KTX2, returns KTX2-specific functionalities for it.

Trait Implementations§

Source§

impl<'a> Drop for Texture<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Texture<'a>

§

impl<'a> !RefUnwindSafe for Texture<'a>

§

impl<'a> !Send for Texture<'a>

§

impl<'a> !Sync for Texture<'a>

§

impl<'a> Unpin for Texture<'a>

§

impl<'a> !UnwindSafe for Texture<'a>

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.