pub struct TextureData { /* private fields */ }Expand description
Actual texture data.
Implementations§
Source§impl TextureData
impl TextureData
Sourcepub fn load_from_memory(
data: &[u8],
compression: CompressionOptions,
gen_mip_maps: bool,
) -> Result<Self, TextureError>
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.
Sourcepub fn from_bytes(
kind: TextureKind,
pixel_kind: TexturePixelKind,
bytes: Vec<u8>,
serialize_content: bool,
) -> Option<Self>
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!
Sourcepub fn set_minification_filter(&mut self, filter: TextureMinificationFilter)
pub fn set_minification_filter(&mut self, filter: TextureMinificationFilter)
Sets new minification filter. It is used when texture becomes smaller.
Sourcepub fn minification_filter(&self) -> TextureMinificationFilter
pub fn minification_filter(&self) -> TextureMinificationFilter
Returns current minification filter.
Sourcepub fn set_magnification_filter(&mut self, filter: TextureMagnificationFilter)
pub fn set_magnification_filter(&mut self, filter: TextureMagnificationFilter)
Sets new magnification filter. It is used when texture is “stretching”.
Sourcepub fn magnification_filter(&self) -> TextureMagnificationFilter
pub fn magnification_filter(&self) -> TextureMagnificationFilter
Returns current magnification filter.
Sourcepub fn set_s_wrap_mode(&mut self, s_wrap_mode: TextureWrapMode)
pub fn set_s_wrap_mode(&mut self, s_wrap_mode: TextureWrapMode)
Sets new S coordinate wrap mode.
Sourcepub fn s_wrap_mode(&self) -> TextureWrapMode
pub fn s_wrap_mode(&self) -> TextureWrapMode
Returns current S coordinate wrap mode.
Sourcepub fn set_t_wrap_mode(&mut self, t_wrap_mode: TextureWrapMode)
pub fn set_t_wrap_mode(&mut self, t_wrap_mode: TextureWrapMode)
Sets new T coordinate wrap mode.
Sourcepub fn t_wrap_mode(&self) -> TextureWrapMode
pub fn t_wrap_mode(&self) -> TextureWrapMode
Returns current T coordinate wrap mode.
Sourcepub fn kind(&self) -> TextureKind
pub fn kind(&self) -> TextureKind
Returns texture kind.
Sourcepub fn data_hash(&self) -> u64
pub fn data_hash(&self) -> u64
Returns current data hash. Hash is guaranteed to be in actual state.
Sourcepub fn pixel_kind(&self) -> TexturePixelKind
pub fn pixel_kind(&self) -> TexturePixelKind
Returns current pixel kind.
Sourcepub fn first_mip_level_data(&self) -> &[u8] ⓘ
pub fn first_mip_level_data(&self) -> &[u8] ⓘ
Returns data of the first mip level.
Sourcepub fn is_procedural(&self) -> bool
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.
Sourcepub fn is_render_target(&self) -> bool
pub fn is_render_target(&self) -> bool
Returns true if the texture is used as render target.
Sourcepub fn set_anisotropy_level(&mut self, anisotropy: f32)
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.
Sourcepub fn anisotropy_level(&self) -> f32
pub fn anisotropy_level(&self) -> f32
Returns current anisotropy level.
Sourcepub fn save(&self) -> Result<(), TextureError>
pub fn save(&self) -> Result<(), TextureError>
Tries to save internal buffer into source file.
Sourcepub fn modify(&mut self) -> TextureDataRefMut<'_>
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
impl Debug for TextureData
Source§impl Default for TextureData
impl Default for TextureData
Source§fn default() -> Self
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
impl ResourceData for TextureData
Source§impl Visit for TextureData
impl Visit for TextureData
Auto Trait Implementations§
impl Freeze for TextureData
impl RefUnwindSafe for TextureData
impl Send for TextureData
impl Sync for TextureData
impl Unpin for TextureData
impl UnwindSafe for TextureData
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PropertyValue for Twhere
T: Debug + 'static,
impl<T> PropertyValue for Twhere
T: Debug + 'static,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.