Skip to main content

GpuTextureTrait

Trait GpuTextureTrait 

Source
pub trait GpuTextureTrait: GpuTextureAsAny {
    // Required methods
    fn set_data(
        &self,
        kind: GpuTextureKind,
        pixel_kind: PixelKind,
        mip_count: usize,
        data: Option<&[u8]>,
    ) -> Result<usize, FrameworkError>;
    fn kind(&self) -> GpuTextureKind;
    fn pixel_kind(&self) -> PixelKind;
}
Expand description

Texture is an image that used to fill faces to add details to them. It could also be used as a generic and mostly unlimited capacity storage for arbitrary data.

In most cases textures are just 2D images, however there are some exclusions to that - for example cube maps, that may be used for environment mapping. Fyrox supports 1D, 2D, 3D and Cube textures.

§Example

use fyrox_graphics::{
    error::FrameworkError,
    gpu_texture::{
        GpuTexture, GpuTextureDescriptor, GpuTextureKind, PixelKind,
    },
    server::GraphicsServer,
};
use std::{cell::RefCell, rc::Rc};

fn create_texture(
    server: &dyn GraphicsServer,
) -> Result<GpuTexture, FrameworkError> {
    server.create_texture(GpuTextureDescriptor {
        kind: GpuTextureKind::Rectangle {
            width: 1,
            height: 1,
        },
        pixel_kind: PixelKind::RGBA8,
        mip_count: 1,
        // Opaque red pixel.
        data: Some(&[255, 0, 0, 255]),
        // Take the defaults for the rest of parameters.
        ..Default::default()
    })
}

Required Methods§

Source

fn set_data( &self, kind: GpuTextureKind, pixel_kind: PixelKind, mip_count: usize, data: Option<&[u8]>, ) -> Result<usize, FrameworkError>

Sets the new data of the texture. This method is also able to change the kind of the texture and its pixel kind. Returns the number of bytes occupied by the texture in the video memory. If there’s no data specified, the texture will still take the space defined by its metrics.

Source

fn kind(&self) -> GpuTextureKind

Returns kind of the texture.

Source

fn pixel_kind(&self) -> PixelKind

Returns pixel kind of the texture.

Implementors§