TextureResourceExtension

Trait TextureResourceExtension 

Source
pub trait TextureResourceExtension: Sized {
    // Required methods
    fn new_render_target(width: u32, height: u32) -> Self;
    fn load_from_memory(
        kind: ResourceKind,
        data: &[u8],
        import_options: TextureImportOptions,
    ) -> Result<Self, TextureError>;
    fn from_bytes(
        kind: TextureKind,
        pixel_kind: TexturePixelKind,
        bytes: Vec<u8>,
        resource_kind: ResourceKind,
    ) -> Option<Self>;
    fn deep_clone(&self) -> Self;
}
Expand description

Extension trait for texture resources.

Required Methods§

Source

fn new_render_target(width: u32, height: u32) -> Self

Creates new render target for a scene. This method automatically configures GPU texture to correct settings, after render target was created, it must not be modified, otherwise result is undefined.

Source

fn load_from_memory( kind: ResourceKind, data: &[u8], import_options: TextureImportOptions, ) -> Result<Self, TextureError>

Tries to load a texture from given data. Use this method if you want to load a texture from embedded data.

§On-demand compression

The data can be compressed if needed to improve performance on GPU side.

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

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

Source

fn from_bytes( kind: TextureKind, pixel_kind: TexturePixelKind, bytes: Vec<u8>, resource_kind: ResourceKind, ) -> Option<Self>

Tries to create new texture from given parameters, it may fail only if size of data passed in does not match with required.

Source

fn deep_clone(&self) -> Self

Creates a deep clone of the texture. Unlike TextureResource::clone, this method clones the actual texture data, which could be slow.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§