pub trait GpuTexture: Downcast {
Show 24 methods
// Required methods
fn set_anisotropy(&mut self, anisotropy: f32);
fn anisotropy(&self) -> f32;
fn set_minification_filter(&mut self, min_filter: MinificationFilter);
fn minification_filter(&self) -> MinificationFilter;
fn set_magnification_filter(&mut self, mag_filter: MagnificationFilter);
fn magnification_filter(&self) -> MagnificationFilter;
fn set_wrap(&mut self, coordinate: Coordinate, wrap: WrapMode);
fn wrap_mode(&self, coordinate: Coordinate) -> WrapMode;
fn set_border_color(&mut self, color: Color);
fn set_data(
&mut self,
kind: GpuTextureKind,
pixel_kind: PixelKind,
mip_count: usize,
data: Option<&[u8]>,
) -> Result<(), FrameworkError>;
fn get_image(&self, level: usize) -> Vec<u8> ⓘ;
fn read_pixels(&self) -> Vec<u8> ⓘ;
fn kind(&self) -> GpuTextureKind;
fn pixel_kind(&self) -> PixelKind;
fn set_base_level(&mut self, level: usize);
fn base_level(&self) -> usize;
fn set_max_level(&mut self, level: usize);
fn max_level(&self) -> usize;
fn set_min_lod(&mut self, min_lod: f32);
fn min_lod(&self) -> f32;
fn set_max_lod(&mut self, max_lod: f32);
fn max_lod(&self) -> f32;
fn set_lod_bias(&mut self, bias: f32);
fn lod_bias(&self) -> f32;
}
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, MagnificationFilter,
MinificationFilter, PixelKind, WrapMode,
},
server::GraphicsServer,
};
use std::{cell::RefCell, rc::Rc};
fn create_texture(
server: &dyn GraphicsServer,
) -> Result<Rc<RefCell<dyn GpuTexture>>, FrameworkError> {
server.create_texture(GpuTextureDescriptor {
kind: GpuTextureKind::Rectangle {
width: 1,
height: 1,
},
pixel_kind: PixelKind::RGBA8,
min_filter: MinificationFilter::Nearest,
mag_filter: MagnificationFilter::Nearest,
mip_count: 1,
s_wrap_mode: WrapMode::Repeat,
t_wrap_mode: WrapMode::Repeat,
r_wrap_mode: WrapMode::Repeat,
anisotropy: 1.0,
// Opaque red pixel.
data: Some(&[255, 0, 0, 255]),
// Take the defaults for the rest of parameters.
..Default::default()
})
}
Required Methods§
Sourcefn set_anisotropy(&mut self, anisotropy: f32)
fn set_anisotropy(&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.
Sourcefn anisotropy(&self) -> f32
fn anisotropy(&self) -> f32
Returns current anisotropy level.
Sourcefn set_minification_filter(&mut self, min_filter: MinificationFilter)
fn set_minification_filter(&mut self, min_filter: MinificationFilter)
Sets new minification filter. It is used when texture becomes smaller. See MinificationFilter
docs for more info.
Sourcefn minification_filter(&self) -> MinificationFilter
fn minification_filter(&self) -> MinificationFilter
Returns current minification filter.
Sourcefn set_magnification_filter(&mut self, mag_filter: MagnificationFilter)
fn set_magnification_filter(&mut self, mag_filter: MagnificationFilter)
Sets new magnification filter. It is used when texture is “stretching”. See MagnificationFilter
docs for more info.
Sourcefn magnification_filter(&self) -> MagnificationFilter
fn magnification_filter(&self) -> MagnificationFilter
Returns current magnification filter.
Sourcefn set_wrap(&mut self, coordinate: Coordinate, wrap: WrapMode)
fn set_wrap(&mut self, coordinate: Coordinate, wrap: WrapMode)
Sets new wrap mode for the given coordinate. See WrapMode
for more info.
Sourcefn wrap_mode(&self, coordinate: Coordinate) -> WrapMode
fn wrap_mode(&self, coordinate: Coordinate) -> WrapMode
Returns current wrap mode for the given coordinate.
Sourcefn set_border_color(&mut self, color: Color)
fn set_border_color(&mut self, color: Color)
Sets border color of the texture. Works together with WrapMode::ClampToBorder
and
essentially forces the GPU to use the given color when it tries to read outside the texture
bounds.
Sourcefn set_data(
&mut self,
kind: GpuTextureKind,
pixel_kind: PixelKind,
mip_count: usize,
data: Option<&[u8]>,
) -> Result<(), FrameworkError>
fn set_data( &mut self, kind: GpuTextureKind, pixel_kind: PixelKind, mip_count: usize, data: Option<&[u8]>, ) -> Result<(), FrameworkError>
Sets the new data of the texture. This method is also able to change the kind of the texture and its pixel kind.
Sourcefn get_image(&self, level: usize) -> Vec<u8> ⓘ
fn get_image(&self, level: usize) -> Vec<u8> ⓘ
Reads the texture data at the given mip level. This method could block current thread until the data comes from GPU to CPU side.
Sourcefn read_pixels(&self) -> Vec<u8> ⓘ
fn read_pixels(&self) -> Vec<u8> ⓘ
Reads texture pixels.
Sourcefn kind(&self) -> GpuTextureKind
fn kind(&self) -> GpuTextureKind
Returns kind of the texture.
Sourcefn pixel_kind(&self) -> PixelKind
fn pixel_kind(&self) -> PixelKind
Returns pixel kind of the texture.
Sourcefn set_base_level(&mut self, level: usize)
fn set_base_level(&mut self, level: usize)
Specifies the index of the lowest defined mipmap level. Keep in mind, that the texture data should provide the actual mip map level defined by the provided value, otherwise the rendering will be incorrect (probably just black on majority of implementations) and glitchy.
Sourcefn base_level(&self) -> usize
fn base_level(&self) -> usize
Returns the index of the lowest defined mipmap level.
Sourcefn set_max_level(&mut self, level: usize)
fn set_max_level(&mut self, level: usize)
Sets the index of the highest defined mipmap level. Keep in mind, that the texture data should provide the actual mip map level defined by the provided value, otherwise the rendering will be incorrect (probably just black on majority of implementations) and glitchy.
Sourcefn set_min_lod(&mut self, min_lod: f32)
fn set_min_lod(&mut self, min_lod: f32)
Sets the minimum level-of-detail parameter. This floating-point value limits the selection of highest resolution mipmap (lowest mipmap level). The initial value is -1000.0.
Sourcefn min_lod(&self) -> f32
fn min_lod(&self) -> f32
Returns the minimum level-of-detail parameter. See Self::set_min_lod
for more info.
Sourcefn set_max_lod(&mut self, max_lod: f32)
fn set_max_lod(&mut self, max_lod: f32)
Sets the maximum level-of-detail parameter. This floating-point value limits the selection of the lowest resolution mipmap (highest mipmap level). The initial value is 1000.
Sourcefn max_lod(&self) -> f32
fn max_lod(&self) -> f32
Returns the maximum level-of-detail parameter. See Self::set_max_lod
for more info.
Sourcefn set_lod_bias(&mut self, bias: f32)
fn set_lod_bias(&mut self, bias: f32)
Specifies a fixed bias value that is to be added to the level-of-detail parameter for the
texture before texture sampling. The specified value is added to the shader-supplied bias
value (if any) and subsequently clamped into the implementation-defined range
−bias_max..bias_max
, where bias_max
is the value that can be fetched from the current
graphics server. The initial value is 0.0.
Sourcefn lod_bias(&self) -> f32
fn lod_bias(&self) -> f32
Returns a fixed bias value that is to be added to the level-of-detail parameter for the
texture before texture sampling. See Self::set_lod_bias
for more info.
Implementations§
Source§impl dyn GpuTexture
impl dyn GpuTexture
Sourcepub fn get_image_of_type<T>(&self, level: usize) -> Vec<T>where
T: Pod,
pub fn get_image_of_type<T>(&self, level: usize) -> Vec<T>where
T: Pod,
Reads the pixels at the given mip level and reinterprets them using the given type.
Sourcepub fn read_pixels_of_type<T>(&self) -> Vec<T>where
T: Pod,
pub fn read_pixels_of_type<T>(&self) -> Vec<T>where
T: Pod,
Reads the pixels and reinterprets them using the given type.