TextureData

Struct TextureData 

Source
pub struct TextureData { /* private fields */ }
Expand description

Actual texture data.

Implementations§

Source§

impl TextureData

Source

pub fn load_from_memory( data: &[u8], compression: CompressionOptions, gen_mip_maps: bool, ) -> Result<Self, TextureError>

Tries to load a texture from given data in one of the following formats: PNG, BMP, TGA, JPG, DDS, GIF. Use this method if you want to load a texture from embedded data.

§On-demand compression and mip-map generation

The data can be compressed if needed to improve performance on GPU side. Mip-maps can be generated as well. CAVEAT: Compression and mip-map generation won’t be taken into account in case of DDS textures, because DDS can already contain such data, you should generate mips and compress DDS textures manually using some offline tool like DirectXTexTool or similar.

§Important notes

Textures loaded with this method won’t be correctly serialized! It means that if you’ll made a scene with textures loaded with this method, and then save a scene, then the engine won’t be able to restore the textures if you’ll try to load the saved scene. This is essential limitation of this method, because the engine does not know where to get the data of the texture at loading. You should use ResourceManager::request_texture in majority of cases!

§Use cases

Main use cases for this method are: procedural textures, icons for GUI.

Source

pub fn from_bytes( kind: TextureKind, pixel_kind: TexturePixelKind, bytes: Vec<u8>, serialize_content: bool, ) -> Option<Self>

Creates new texture instance from given parameters.

§Limitations

Currently textures with only one mip level are supported!

Source

pub fn set_minification_filter(&mut self, filter: TextureMinificationFilter)

Sets new minification filter. It is used when texture becomes smaller.

Source

pub fn minification_filter(&self) -> TextureMinificationFilter

Returns current minification filter.

Source

pub fn set_magnification_filter(&mut self, filter: TextureMagnificationFilter)

Sets new magnification filter. It is used when texture is “stretching”.

Source

pub fn magnification_filter(&self) -> TextureMagnificationFilter

Returns current magnification filter.

Source

pub fn set_s_wrap_mode(&mut self, s_wrap_mode: TextureWrapMode)

Sets new S coordinate wrap mode.

Source

pub fn s_wrap_mode(&self) -> TextureWrapMode

Returns current S coordinate wrap mode.

Source

pub fn set_t_wrap_mode(&mut self, t_wrap_mode: TextureWrapMode)

Sets new T coordinate wrap mode.

Source

pub fn t_wrap_mode(&self) -> TextureWrapMode

Returns current T coordinate wrap mode.

Source

pub fn mip_count(&self) -> u32

Returns total mip count.

Source

pub fn kind(&self) -> TextureKind

Returns texture kind.

Source

pub fn data_hash(&self) -> u64

Returns current data hash. Hash is guaranteed to be in actual state.

Source

pub fn pixel_kind(&self) -> TexturePixelKind

Returns current pixel kind.

Source

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

Returns current data as immutable slice.

Source

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

Returns data of the first mip level.

Source

pub fn is_procedural(&self) -> bool

Returns true if the texture is procedural, false - otherwise.

§Notes

Content of procedural textures is saved during serialization and they never resolved on deserialization. Resolving here means a process of getting correct texture instance by its path.

Source

pub fn is_render_target(&self) -> bool

Returns true if the texture is used as render target.

Source

pub fn set_anisotropy_level(&mut self, anisotropy: f32)

Max samples for anisotropic filtering. Default value is 16.0 (max). However real value passed to GPU will be clamped to maximum supported by current GPU. To disable anisotropic filtering set this to 1.0. Typical values are 2.0, 4.0, 8.0, 16.0.

Source

pub fn anisotropy_level(&self) -> f32

Returns current anisotropy level.

Source

pub fn set_path<P: AsRef<Path>>(&mut self, path: P)

Sets new path to source file.

Source

pub fn save(&self) -> Result<(), TextureError>

Tries to save internal buffer into source file.

Source

pub fn modify(&mut self) -> TextureDataRefMut<'_>

Returns a special reference holder that provides mutable access to content of the texture and automatically calculates hash of the data in its destructor.

Trait Implementations§

Source§

impl Debug for TextureData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextureData

Source§

fn default() -> Self

It is very important to mention that defaults may be different for texture when you importing them through resource manager, see TextureImportOptions for more info.

Source§

impl ResourceData for TextureData

Source§

fn path(&self) -> Cow<'_, Path>

Returns path of resource data.
Source§

fn set_path(&mut self, path: PathBuf)

Sets new path to resource data.
Source§

impl Visit for TextureData

Source§

fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult

Auto Trait Implementations§

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PropertyValue for T
where T: Debug + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts self to a &dyn Any
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ResourceLoadError for T
where T: 'static + Debug + Send + Sync,