#[repr(C)]pub struct Tex(pub NonNull<_TexT>);
Expand description
This is the texture asset class! This encapsulates 2D images, texture arrays, cubemaps, and rendertargets! It can load any image format that stb_image can, (jpg, png, tga, bmp, psd, gif, hdr, pic, ktx2) plus more later on, and you can also create textures procedurally. https://stereokit.net/Pages/StereoKit/Tex.html
§Examples
use stereokit_rust::{maths::{Vec3, Matrix, Quat}, util::{named_colors,Color32},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let tex_left = Tex::from_file("textures/open_gltf.jpeg", true, None)
.expect("tex_left should be created");
let mut tex_right = Tex::gen_color(named_colors::RED, 1, 1, TexType::Image, TexFormat::RGBA32);
let mut tex_back = Tex::gen_particle(128, 128, 0.2, None);
let mut tex_floor = Tex::new(TexType::Image, TexFormat::RGBA32, None);
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let material_left = Material::pbr().tex_copy(tex_left);
let material_right = Material::pbr().tex_copy(tex_right);
let material_back = Material::unlit_clip().tex_copy(tex_back);
let material_floor = Material::pbr().tex_copy(tex_floor);
let transform_left = Matrix::t_r([-0.5, 0.0, 0.0], [0.0, 0.0, 90.0]);
let transform_right = Matrix::t_r([ 0.5, 0.0, 0.0], [0.0, 0.0,-90.0]);
let transform_back = Matrix::t_r([ 0.0, 0.0,-0.5], [90.0, 0.0, 0.0]);
let transform_floor = Matrix::t( [0.0, -0.5, 0.0]);
filename_scr = "screenshots/tex.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material_left, transform_left, None, None);
plane_mesh.draw(token, &material_right, transform_right, None, None);
plane_mesh.draw(token, &material_back, transform_back, None, None);
plane_mesh.draw(token, &material_floor, transform_floor, None, None);
);

Tuple Fields§
§0: NonNull<_TexT>
Implementations§
Source§impl Tex
impl Tex
Sourcepub fn new(texture_type: TexType, format: TexFormat, id: Option<&str>) -> Tex
pub fn new(texture_type: TexType, format: TexFormat, id: Option<&str>) -> Tex
Sets up an empty texture container! Fill it with data using SetColors next! Creates a default unique asset Id. https://stereokit.net/Pages/StereoKit/Tex/Tex.html
texture_type
- What type of texture is it? Just a 2D Image? A Cubemap? Should it have mip-maps?format
- What information is the texture composed of? 32 bit colors, 64 bit colors, etc.id
- A unique asset Id for this texture, this is used to find the texture later on, and to reference it. if
see also tex_create
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color32, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let mut color_dots = [named_colors::CYAN; 128 * 128];
let mut tex_left = Tex::new(TexType::Image, TexFormat::RGBA32, Some("tex_left_ID"));
tex_left.set_colors32(128, 128, &color_dots);
let mut color_dots = [Color128::new(0.5, 0.75, 0.25, 1.0); 128 * 128];
let mut tex_right = Tex::new(TexType::Image, TexFormat::RGBA128, None);
tex_right.set_colors128(128, 128, &color_dots);
let material_left = Material::pbr().tex_copy(tex_left);
let material_right = Material::pbr().tex_copy(tex_right);
let transform_left = Matrix::t_r([-0.5, 0.0, 0.0], [0.0,-45.0, 90.0]);
let transform_right = Matrix::t_r([ 0.5, 0.0, 0.0], [0.0, 45.0,-90.0]);
test_steps!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material_left, transform_left, None, None);
plane_mesh.draw(token, &material_right, transform_right, None, None);
);
Sourcepub fn from_memory(
data: &[u8],
srgb_data: bool,
priority: Option<i32>,
) -> Result<Tex, StereoKitError>
pub fn from_memory( data: &[u8], srgb_data: bool, priority: Option<i32>, ) -> Result<Tex, StereoKitError>
Loads an image file stored in memory directly into a texture! Supported formats are: jpg, png, tga, bmp, psd, gif, hdr, pic, ktx2. Asset Id will be the same as the filename. https://stereokit.net/Pages/StereoKit/Tex/FromMemory.html
data
- The binary data of an image file, this is NOT a raw RGB color array!srgb_data
- Is this image color data in sRGB format, or is it normal/metal/rough/data that’s not for direct display? sRGB colors get converted to linear color space on the graphics card, so getting this right can have a big impact on visuals.priority
- The priority sort order for this asset in the async loading system. Lower values mean loading sooner. If None will be set to 10
see also tex_create_mem
§Examples
use stereokit_rust::{maths::{Vec3, Matrix},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let left_data = std::include_bytes!("../assets/textures/open_gltf.jpeg");
let right_data = std::include_bytes!("../assets/textures/log_viewer.jpeg");
let tex_left = Tex::from_memory(left_data, true, None)
.expect("open_gltf.jpeg should be loaded");
let tex_right = Tex::from_memory(right_data, true, None)
.expect("open_gltf.jpeg should be loaded");
let material_left = Material::pbr().tex_copy(tex_left);
let material_right = Material::pbr().tex_copy(tex_right);
let transform_left = Matrix::t_r([-0.5, 0.0, 0.0], [0.0,-45.0, 90.0]);
let transform_right = Matrix::t_r([ 0.5, 0.0, 0.0], [0.0, 45.0,-90.0]);
test_steps!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material_left, transform_left, None, None);
plane_mesh.draw(token, &material_right, transform_right, None, None);
);
Sourcepub fn from_file(
file_utf8: impl AsRef<Path>,
srgb_data: bool,
priority: Option<i32>,
) -> Result<Tex, StereoKitError>
pub fn from_file( file_utf8: impl AsRef<Path>, srgb_data: bool, priority: Option<i32>, ) -> Result<Tex, StereoKitError>
Loads an image file directly into a texture! Supported formats are: jpg, png, tga, bmp, psd, gif, hdr, pic, ktx2. Asset Id will be the same as the filename. https://stereokit.net/Pages/StereoKit/Tex/FromFile.html
file_utf8
- An absolute filename, or a filename relative to the assets folder. Supports jpg, png, tga, bmp, psd, gif, hdr, pic, ktx2.srgb_data
- Is this image color data in sRGB format, or is it normal/metal/rough/data that’s not for direct display? sRGB colors get converted to linear color space on the graphics card, so getting this right can have a big impact on visuals.priority
- The priority sort order for this asset in the async loading system. Lower values mean loading sooner. If None will be set to 10
see also tex_create_file
Tex::get_asset_state
crate::material::Material::tex_file_copy
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, system::AssetState,
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let tex_left = Tex::from_file("textures/open_gltf.jpeg", true, Some(9999))
.expect("tex_left should be created");
let tex_right = Tex::from_file("textures/log_viewer.jpeg", true, Some(9999))
.expect("tex_right should be created");
let tex_floor = Tex::from_file("not a file so we'll have error tex", true, Some(9999))
.expect("tex_error should be loaded");
let material_left = Material::pbr().tex_copy(&tex_left);
let material_right = Material::pbr().tex_copy(&tex_right);
let material_floor = Material::pbr().tex_copy(&tex_floor);
let transform_left = Matrix::t_r([-0.5, 0.0, 0.0], [0.0,-45.0, 90.0]);
let transform_right = Matrix::t_r([ 0.5, 0.0, 0.0], [0.0, 45.0,-90.0]);
let transform_floor = Matrix::t( [0.0, -0.5, 0.0]);
filename_scr = "screenshots/tex_from_file.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
// We ensure to have the Tex loaded for the screenshot.
if tex_left.get_asset_state() != AssetState::Loaded
|| tex_right.get_asset_state() != AssetState::Loaded { iter -= 1; }
plane_mesh.draw(token, &material_left, transform_left, None, None);
plane_mesh.draw(token, &material_right, transform_right, None, None);
plane_mesh.draw(token, &material_floor, transform_floor, None, None);
);
assert_eq!(tex_left.get_asset_state(), AssetState::Loaded);
assert_eq!(tex_right.get_asset_state(), AssetState::Loaded);
assert_eq!(tex_floor.get_asset_state(), AssetState::NotFound);

Sourcepub fn from_files<P: AsRef<Path>>(
files_utf8: &[P],
srgb_data: bool,
priority: Option<i32>,
) -> Result<Tex, StereoKitError>
pub fn from_files<P: AsRef<Path>>( files_utf8: &[P], srgb_data: bool, priority: Option<i32>, ) -> Result<Tex, StereoKitError>
Loads an array of image files directly into a single array texture! Array textures are often useful for shader effects, layering, material merging, weird stuff, and will generally need a specific shader to support it. Supported formats are: jpg, png, tga, bmp, psd, gif, hdr, pic, ktx2. Asset Id will be the hash of all the filenames merged consecutively. https://stereokit.net/Pages/StereoKit/Tex/FromFiles.html
files_utf8
- An absolute filenames, or filenames relative to the assets folder. Supports jpg, png, tga, bmp, psd, gif, hdr, pic, ktx2.srgb_data
- Is this image color data in sRGB format, or is it normal/metal/rough/data that’s not for direct display? sRGB colors get converted to linear color space on the graphics card, so getting this right can have a big impact on visuals.priority
- The priority sort order for this asset in the async loading system. Lower values mean loading sooner. If None will be set to 10
see also tex_create_file
§Examples
use stereokit_rust::{maths::{Vec3, Matrix},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let tex = Tex::from_files(&["textures/open_gltf.jpeg",
"textures/log_viewer.jpeg"], true, Some(100))
.expect("tex should be created");
let material = Material::pbr().tex_copy(tex);
let transform = Matrix::t_r([-0.5, 0.0, 0.0], [0.0, -45.0, 90.0]);
test_steps!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material, transform, None, None);
);
Sourcepub fn from_color32(
colors: &[Color32],
width: usize,
height: usize,
srgb_data: bool,
) -> Result<Tex, StereoKitError>
pub fn from_color32( colors: &[Color32], width: usize, height: usize, srgb_data: bool, ) -> Result<Tex, StereoKitError>
Creates a texture and sets the texture’s pixels using a color array! This will be an image of type TexType.Image, and a format of TexFormat.Rgba32 or TexFormat.Rgba32Linear depending on the value of the sRGBData parameter. https://stereokit.net/Pages/StereoKit/Tex/FromColors.html
colors
- An array of 32 bit colors, should be a length of width*height.width
- Width in pixels of the texture. Powers of two are generally best!height
- Height in pixels of the texture. Powers of two are generally best!srgb_data
- s this image color data in sRGB format, or is it normal/metal/rough/data that’s not for direct display? sRGB colors get converted to linear color space on the graphics card, so getting this right can have a big impact on visuals.
see also tex_create_color32
Tex::gen_color
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color32},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let color_dots = [named_colors::RED; 128 * 128];
let tex = Tex::from_color32(&color_dots, 128, 128, true)
.expect("Tex should be created");
let material = Material::pbr().tex_copy(tex);
let transform = Matrix::t_r([-0.5, 0.0, 0.0], [0.0, -45.0, 90.0]);
test_steps!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material, transform, None, None);
);
Sourcepub fn from_color128(
colors: &[Color128],
width: usize,
height: usize,
srgb_data: bool,
) -> Result<Tex, StereoKitError>
pub fn from_color128( colors: &[Color128], width: usize, height: usize, srgb_data: bool, ) -> Result<Tex, StereoKitError>
Creates a texture and sets the texture’s pixels using a color array! Color values are converted to 32 bit colors, so this means a memory allocation and conversion. Prefer the Color32 overload for performance, or create an empty Texture and use SetColors for more flexibility. This will be an image of type TexType.Image, and a format of TexFormat. Rgba32 or TexFormat.Rgba32Linear depending on the value of the sRGBData parameter. https://stereokit.net/Pages/StereoKit/Tex/FromColors.html
colors
- An array of 128 bit colors, should be a length of width*height.width
- Width in pixels of the texture. Powers of two are generally best!height
- Height in pixels of the texture. Powers of two are generally best!srgb_data
- s this image color data in sRGB format, or is it normal/metal/rough/data that’s not for direct display? sRGB colors get converted to linear color space on the graphics card, so getting this right can have a big impact on visuals.
Important: The color conversion from 128 to 32 may crash if the data do not contains color128.
see also tex_create_color128
Tex::gen_color()
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let color_dots = [Color128::new(0.1, 0.2, 0.5, 1.0); 128 * 128];
let tex = Tex::from_color128(&color_dots, 128, 128, true)
.expect("Tex should be created");
let material = Material::pbr().tex_copy(tex);
let transform = Matrix::t_r([-0.5, 0.0, 0.0], [0.0, -45.0, 90.0]);
test_steps!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material, transform, None, None);
);
Sourcepub fn render_target(
width: usize,
height: usize,
multisample: Option<i32>,
color_format: Option<TexFormat>,
depth_format: Option<TexFormat>,
) -> Result<Tex, StereoKitError>
pub fn render_target( width: usize, height: usize, multisample: Option<i32>, color_format: Option<TexFormat>, depth_format: Option<TexFormat>, ) -> Result<Tex, StereoKitError>
This will assemble a texture ready for rendering to! It creates a render target texture with no mip maps and a depth buffer attached. https://stereokit.net/Pages/StereoKit/Tex/RenderTarget.html
width
- in pixelsheight
- in pixelsmultisample
- Multisample level, or MSAA. This should be 1, 2, 4, 8, or 16. The results will have moother edges with higher values, but will cost more RAM and time to render. Note that GL platforms cannot trivially draw a multisample > 1 texture in a shader. If this is None, the default is 1.color_format
- The format of the color surface. If this is None, the default is RGBA32.depth_format
- The format of the depth buffer. If this is TexFormat::None, no depth buffer will be attached to this. If this is None, the default is Depth16. rendertarget.
see also tex_create_rendertarget
see also tex_get_data
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color32},
system::Renderer,
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let tex = Tex::render_target(128, 128, Some(2), Some(TexFormat::RGBA32), None)
.expect("Tex should be created");
let material = Material::pbr().tex_copy(&tex);
let transform = Matrix::t_r([-0.5, 0.0, 0.0], [0.0, -45.0, 90.0]);
Renderer::blit(&tex, &material);
Sourcepub fn gen_color(
color: impl Into<Color128>,
width: i32,
height: i32,
tex_type: TexType,
format: TexFormat,
) -> Tex
pub fn gen_color( color: impl Into<Color128>, width: i32, height: i32, tex_type: TexType, format: TexFormat, ) -> Tex
This generates a solid color texture of the given dimensions. Can be quite nice for creating placeholder textures! Make sure to match linear/gamma colors with the correct format. https://stereokit.net/Pages/StereoKit/Tex/GenColor.html
color
- The color to use for the texture. This is interpreted slightly differently based on what TexFormat gets used.width
- Width of the final texture, in pixels.height
- Height of the final texture, in pixels.tex_type
- Not all types here are applicable, but TexType.Image or TexType::ImageNomips are good options here.format
- Not all formats are supported, but this does support a decent range. The provided color is interpreted slightly different depending on this format.
see also tex_gen_color
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let tex_err = Tex::gen_color(named_colors::RED, 128, 128, TexType::Image, TexFormat::RGBA32);
Tex::set_error_fallback(&tex_err);
let tex = Tex::gen_color(Color128::new(0.1, 0.2, 0.5, 1.0), 128, 128, TexType::Image, TexFormat::RGBA128);
let material = Material::pbr().tex_copy(tex);
let transform = Matrix::t_r([-0.5, 0.0, 0.0], [0.0, -45.0, 90.0]);
test_steps!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material, transform, None, None);
);
Sourcepub fn gen_particle(
width: i32,
height: i32,
roundness: f32,
gradient_linear: Option<Gradient>,
) -> Tex
pub fn gen_particle( width: i32, height: i32, roundness: f32, gradient_linear: Option<Gradient>, ) -> Tex
Generates a ‘radial’ gradient that works well for particles, blob shadows, glows, or various other things. The roundness can be used to change the shape from round, ‘1’, to star-like, ‘0’. Default color is transparent white to opaque white, but this can be configured by providing a Gradient of your own. https://stereokit.net/Pages/StereoKit/Tex/GenParticle.html
width
- Width of the final texture, in pixels.height
- Height of the final texture, in pixels.gradient_linear
: A color gradient that starts with the background/outside at 0, and progresses to the center at 1. If None, will use a white gradient.
see also tex_gen_particle
§Examples
use stereokit_rust::{maths::{Vec3, Matrix, Quat},
util::{named_colors, Gradient, GradientKey, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut keys = [
GradientKey::new(Color128::BLACK_TRANSPARENT, 0.0),
GradientKey::new(named_colors::RED, 0.1),
GradientKey::new(named_colors::CYAN, 0.4),
GradientKey::new(named_colors::YELLOW, 0.5),
GradientKey::new(Color128::BLACK, 0.7)];
let tex_back = Tex::gen_particle(128, 128, 0.15, Some(Gradient::new(Some(&keys))));
let tex_floor = Tex::gen_particle(128, 128, 0.3, Some(Gradient::new(Some(&keys))));
let tex_right = Tex::gen_particle(128, 128, 0.6, Some(Gradient::new(Some(&keys))));
let tex_left = Tex::gen_particle(128, 128, 0.9, Some(Gradient::new(Some(&keys))));
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let material_left = Material::unlit_clip().tex_copy(tex_left);
let material_right = Material::unlit_clip().tex_copy(tex_right);
let material_back = Material::unlit_clip().tex_copy(tex_back);
let material_floor = Material::unlit_clip().tex_copy(tex_floor);
let transform_left = Matrix::t_r([-0.5, 0.0, 0.0], [0.0, 0.0, 90.0]);
let transform_right = Matrix::t_r([ 0.5, 0.0, 0.0], [0.0, 0.0, -90.0]);
let transform_back = Matrix::t_r([ 0.0, 0.0,-0.5], [90.0, 0.0, 0.0]);
let transform_floor = Matrix::t( [0.0, -0.5, 0.0]);
filename_scr = "screenshots/tex_gen_particle.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material_left, transform_left, None, None);
plane_mesh.draw(token, &material_right, transform_right, None, None);
plane_mesh.draw(token, &material_back, transform_back, None, None);
plane_mesh.draw(token, &material_floor, transform_floor, None, None);
);

Sourcepub fn set_loading_fallback<T: AsRef<Tex>>(fallback: T)
pub fn set_loading_fallback<T: AsRef<Tex>>(fallback: T)
This is the texture that all Tex objects will fall back to by default if they are still loading. Assigning a texture here that isn’t fully loaded will cause the app to block until it is loaded. https://stereokit.net/Pages/StereoKit/Tex/SetLoadingFallback.html
see also tex_set_loading_fallback
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let tex_loading = Tex::gen_color(named_colors::GREEN, 128, 128, TexType::Image, TexFormat::RGBA32);
Tex::set_loading_fallback(&tex_loading);
let tex = Tex::new(TexType::Image, TexFormat::RGBA32, None);
let material = Material::pbr().tex_copy(tex);
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let transform_floor = Matrix::t( [0.0, -0.5, 0.0]);
test_steps!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material, transform_floor, None, None);
);
Sourcepub fn set_error_fallback<T: AsRef<Tex>>(fallback: T)
pub fn set_error_fallback<T: AsRef<Tex>>(fallback: T)
This is the texture that all Tex objects with errors will fall back to. Assigning a texture here that isn’t fully loaded will cause the app to block until it is loaded. https://stereokit.net/Pages/StereoKit/Tex/SetErrorFallback.html
see also tex_set_error_fallback
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let tex_err = Tex::gen_color(named_colors::RED, 128, 128, TexType::Image, TexFormat::RGBA32);
Tex::set_error_fallback(&tex_err);
let tex = Tex::from_file("file that doesn't exist", true, None)
.expect("tex should be created");
let material = Material::pbr().tex_copy(tex);
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let transform_floor = Matrix::t( [0.0, -0.5, 0.0]);
test_steps!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material, transform_floor, None, None);
);
Sourcepub fn find<S: AsRef<str>>(id: S) -> Result<Tex, StereoKitError>
pub fn find<S: AsRef<str>>(id: S) -> Result<Tex, StereoKitError>
Looks for a Material asset that’s already loaded, matching the given id! https://stereokit.net/Pages/StereoKit/Tex/Find.html
id
- The id of the texture to find.
see also tex_find
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut tex_blue = Tex::gen_color(named_colors::BLUE, 1, 1, TexType::Image, TexFormat::RGBA32);
assert!(tex_blue.get_id().starts_with("auto/tex_"));
tex_blue.id("my_tex_blue");
let same_tex_blue = Tex::find("my_tex_blue").expect("my_tex_blue should be found");
assert_eq!(tex_blue, same_tex_blue);
let tex = Tex::from_file("textures/open_gltf.jpeg", true, None)
.expect("tex should be created");
assert_eq!(tex.get_id(), "textures/open_gltf.jpeg");
let same_tex = Tex::find("textures/open_gltf.jpeg")
.expect("same_tex should be found");
assert_eq!(tex, same_tex);
Sourcepub fn copy(
&self,
tex_type: Option<TexType>,
tex_format: Option<TexFormat>,
) -> Result<Tex, StereoKitError>
pub fn copy( &self, tex_type: Option<TexType>, tex_format: Option<TexFormat>, ) -> Result<Tex, StereoKitError>
Get a copy of the texture https://stereokit.net/Pages/StereoKit/Tex.html
tex_type
- Type of the copy. If None has default value of TexType::Image.tex_format
- Format of the copy - If None has default value of TexFormat::None.
see also tex_copy
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{Color32, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let tex_blue = Tex::gen_color(Color32::new(64, 32, 255, 255), 1, 1,
TexType::Image, TexFormat::RGBA32Linear);
let tex_copy = tex_blue.copy(None, Some(TexFormat::RGBA32))
.expect("copy should be done");
let mut color_data = [Color32::WHITE; 1];
assert!(tex_copy.get_color_data::<Color32>(&mut color_data, 0));
//TODO: windows assert_eq!(color_data[0], Color32 { r: 64, g: 32, b: 255, a: 255 });
//TODO: linux assert_eq!(color_data[0], Color32 { r: 137, g: 99, b: 255, a: 255 });
let tex_copy = tex_blue.copy(Some(TexType::Image), Some(TexFormat::RGBA128))
.expect("copy should be done");
let mut color_data = [Color128::WHITE; 1];
assert!(tex_copy.get_color_data::<Color128>(&mut color_data, 0));
//TODO: windows assert_eq!(color_data[0], Color128 { r: 0.0, g: 0.0, b: 0.0, a: 0.0 });
//TODO: linux assert_eq!(color_data[0], Color128 { r: 0.2509804, g: 0.1254902, b: 1.0, a:1.0 });
Sourcepub fn clone_ref(&self) -> Tex
pub fn clone_ref(&self) -> Tex
Creates a clone of the same reference. Basically, the new variable is the same asset. This is what you get by calling find() method. https://stereokit.net/Pages/StereoKit/Tex/Find.html
see also tex_find()
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut tex_blue = Tex::gen_color(named_colors::BLUE, 1, 1, TexType::Image, TexFormat::RGBA32);
assert!(tex_blue.get_id().starts_with("auto/tex_"));
let same_tex_blue = tex_blue.clone_ref();
assert_eq!(tex_blue, same_tex_blue);
let tex = Tex::from_file("textures/open_gltf.jpeg", true, None)
.expect("tex should be created");
assert_eq!(tex.get_id(), "textures/open_gltf.jpeg");
let same_tex = tex.clone_ref();
assert_eq!(tex, same_tex);
Sourcepub fn id<S: AsRef<str>>(&mut self, id: S) -> &mut Self
pub fn id<S: AsRef<str>>(&mut self, id: S) -> &mut Self
Set a new id to the texture. https://stereokit.net/Pages/StereoKit/Tex/Id.html
see also tex_set_id
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut tex_blue = Tex::gen_color(named_colors::BLUE, 1, 1, TexType::Image, TexFormat::RGBA32);
assert!(tex_blue.get_id().starts_with("auto/tex_"));
tex_blue.id("my_tex_blue");
assert_eq!(tex_blue.get_id(), "my_tex_blue");
let mut tex = Tex::from_file("textures/open_gltf.jpeg", true, None)
.expect("tex should be created");
assert_eq!(tex.get_id(), "textures/open_gltf.jpeg");
tex_blue.id("my_tex_image");
assert_eq!(tex_blue.get_id(), "my_tex_image");
Sourcepub fn add_zbuffer(&mut self, depth_format: TexFormat) -> &mut Self
pub fn add_zbuffer(&mut self, depth_format: TexFormat) -> &mut Self
Only applicable if this texture is a rendertarget! This creates and attaches a zbuffer surface to the texture for use when rendering to it. https://stereokit.net/Pages/StereoKit/Tex/AddZBuffer.html
depth_format
- The format of the depth texture, must be a depth format type!
see also tex_add_zbuffer
Tex::set_zbuffer
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color32},
system::Renderer,
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut tex = Tex::render_target(128, 128, Some(2), Some(TexFormat::RGBA32),
Some(TexFormat::None))
.expect("Tex should be created");
assert_eq!(tex.get_zbuffer(), None);
tex.add_zbuffer(TexFormat::Depth16);
assert_ne!(tex.get_zbuffer(), None);
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let material = Material::pbr().tex_copy(&tex);
let transform = Matrix::t_r([-0.5, 0.0, 0.0], [0.0, -45.0, 90.0]);
Renderer::blit(&tex, &material);
Sourcepub fn set_memory(
&mut self,
data: &[u8],
srgb_data: bool,
blocking: bool,
priority: Option<i32>,
) -> &mut Self
pub fn set_memory( &mut self, data: &[u8], srgb_data: bool, blocking: bool, priority: Option<i32>, ) -> &mut Self
Loads an image file stored in memory directly into the created texture! Supported formats are: jpg, png, tga, bmp, psd, gif, hdr, pic, ktx2. This method introduces a blocking boolean parameter, which allows you to specify whether this method blocks until the image fully loads! The default case is to have it as part of the asynchronous asset pipeline, in which the Asset Id will be the same as the filename. https://stereokit.net/Pages/StereoKit/Tex/SetMemory.html
data
- The binary data of an image file, this is NOT a raw RGB color array!srgb_data
- Is this image color data in sRGB format, or is it normal/metal/rough/data that’s not for direct display? sRGB colors get converted to linear color space on the graphics card, so getting this right can have a big impact on visuals.blocking
- Will this method wait for the image to load. By default, we try to load it asynchronously.priority
- The priority sort order for this asset in the async loading system. Lower values mean loading sooner. If None will be set to 10
see also tex_set_mem
Tex::from_memory
§Examples
use stereokit_rust::{maths::{Vec3, Matrix},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let image_data = std::include_bytes!("../assets/textures/open_gltf.jpeg");
let mut tex = Tex::new(TexType::Image, TexFormat::RGBA32, None);
tex.set_memory(image_data, true, false, Some(0));
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let material = Material::pbr().tex_copy(tex);
let transform_floor = Matrix::t([0.0, -0.5, 0.0]);
test_steps!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material, transform_floor, None, None);
);
Sourcepub unsafe fn set_colors(
&mut self,
width: usize,
height: usize,
data: *mut c_void,
) -> &mut Self
pub unsafe fn set_colors( &mut self, width: usize, height: usize, data: *mut c_void, ) -> &mut Self
Set the texture’s pixels using a pointer to a chunk of memory! This is great if you’re pulling in some color data from native code, and don’t want to pay the cost of trying to marshal that data around. The data should contains widthheight(TextureFormat size) bytes. Warning: The check widthheight(TextureFormat size) upon the size of the data values must be done before calling this function. Warning: The color data type must be compliant with the format of the texture. https://stereokit.net/Pages/StereoKit/Tex/SetColors.html
width
- Width in pixels of the texture. Powers of two are generally best!height
- Height in pixels of the texture. Powers of two are generally best!data
- A pointer to a chunk of memory containing color data! Should be widthheightsize_of_texture_format bytes large. Color data should definitely match the format provided when constructing the texture!
§Safety
The data pointer must be a valid array for the size of the texture.
see also tex_set_colors
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color32},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut color_dots = [named_colors::CYAN; 16 * 16];
let mut tex = Tex::new(TexType::Image, TexFormat::RGBA32, None);
unsafe { tex.set_colors(16, 16, color_dots.as_mut_ptr() as *mut std::os::raw::c_void); }
let check_dots = [Color32::WHITE; 16 * 16];
assert!(tex.get_color_data::<Color32>(&check_dots, 0));
assert_eq!(check_dots, color_dots);
Sourcepub fn set_colors32(
&mut self,
width: usize,
height: usize,
data: &[Color32],
) -> &mut Self
pub fn set_colors32( &mut self, width: usize, height: usize, data: &[Color32], ) -> &mut Self
Set the texture’s pixels using a color array! This function should only be called on textures with a format of Rgba32 or Rgba32Linear. You can call this as many times as you’d like, even with different widths and heights. Calling this multiple times will mark it as dynamic on the graphics card. Calling this function can also result in building mip-maps, which has a non-zero cost: use TexType.ImageNomips when creating the Tex to avoid this. https://stereokit.net/Pages/StereoKit/Tex/SetColors.html
width
- Width in pixels of the texture. Powers of two are generally best!height
- Height in pixels of the texture. Powers of two are generally best!data
- An array of 32 bit colors, should be a length of width*height.
Warning, instead of Tex::set_colors
, this call may not be done if the asset is not loaded
(see Tex::get_asset_state
) or the size is inconsistent or the format is incompatible.
see also tex_set_colors
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color32},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut color_dots = [named_colors::CYAN; 16 * 16];
let mut tex = Tex::new(TexType::Image, TexFormat::RGBA32, None);
tex.set_colors32(16, 16, &color_dots);
let check_dots = [Color32::WHITE; 16 * 16];
assert!(tex.get_color_data::<Color32>(&check_dots, 0));
assert_eq!(check_dots, color_dots);
Sourcepub fn set_colors128(
&mut self,
width: usize,
height: usize,
data: &[Color128],
) -> &mut Self
pub fn set_colors128( &mut self, width: usize, height: usize, data: &[Color128], ) -> &mut Self
Set the texture’s pixels using a color array! This function should only be called on textures with a format of Rgba128. You can call this as many times as you’d like, even with different widths and heights. Calling this multiple times will mark it as dynamic on the graphics card. Calling this function can also result in building mip-maps, which has a non-zero cost: use TexType.ImageNomips when creating the Tex to avoid this. https://stereokit.net/Pages/StereoKit/Tex/SetColors.html
width
- Width in pixels of the texture. Powers of two are generally best!height
- Height in pixels of the texture. Powers of two are generally best!data
- An array of 128 bit colors, should be a length of width*height.
Warning, instead of Tex::set_colors
, this call may not be done if the asset is not loaded
(see Tex::get_asset_state
) or the size is inconsistent or the format is incompatible.
see also tex_set_colors
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut color_dots = [Color128{r: 0.25, g: 0.125, b: 1.0, a: 1.0}; 16 * 16];
let mut tex = Tex::new(TexType::Image, TexFormat::RGBA128, None);
tex.set_colors128(16, 16, &color_dots);
let check_dots = [Color128::BLACK; 16 * 16];
assert!(tex.get_color_data::<Color128>(&check_dots, 0));
assert_eq!(check_dots, color_dots);
Sourcepub fn set_colors_r8(
&mut self,
width: usize,
height: usize,
data: &[u8],
) -> &mut Self
pub fn set_colors_r8( &mut self, width: usize, height: usize, data: &[u8], ) -> &mut Self
Set the texture’s pixels using a scalar array for channel R ! This function should only be called on textures with a format of R8. You can call this as many times as you’d like, even with different widths and heights. Calling this multiple times will mark it as dynamic on the graphics card. Calling this function can also result in building mip-maps, which has a non-zero cost: use TexType.ImageNomips when creating the Tex to avoid this. https://stereokit.net/Pages/StereoKit/Tex/SetColors.html
width
- Width in pixels of the texture. Powers of two are generally best!height
- Height in pixels of the texture. Powers of two are generally best!data
- An array of 8 bit values, should be a length of width*height.
Warning, instead of Tex::set_colors
, this call may not be done if the asset is not loaded
(see Tex::get_asset_state
) or the size is inconsistent or the format is incompatible.
see also tex_set_colors
§Examples
use stereokit_rust::{maths::{Vec3, Matrix},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut color_dots = [125u8; 16 * 16];
let mut tex = Tex::new(TexType::Image, TexFormat::R8, None);
tex.set_colors_r8(16, 16, &color_dots);
let check_dots = [0u8; 16 * 16];
assert!(tex.get_color_data::<u8>(&check_dots, 0));
assert_eq!(check_dots, color_dots);
Sourcepub fn set_colors_u8(
&mut self,
width: usize,
height: usize,
data: &[u8],
color_size: usize,
) -> &mut Self
pub fn set_colors_u8( &mut self, width: usize, height: usize, data: &[u8], color_size: usize, ) -> &mut Self
Non canonical function !! Set the texture’s pixels using an u8 array ! This function should only be called for all textures format with a format of R8. You can call this as many times as you’d like, even with different widths and heights. Calling this multiple times will mark it as dynamic on the graphics card. Calling this function can also result in building mip-maps, which has a non-zero cost: use TexType.ImageNomips when creating the Tex to avoid this. https://stereokit.net/Pages/StereoKit/Tex/SetColors.html
width
- Width in pixels of the texture. Powers of two are generally best!height
- Height in pixels of the texture. Powers of two are generally best!data
- An array of 8 bit values, should be a length of width*height.color_size
- number of byte for a pixel used by the format of this texture
Warning, instead of Tex::set_colors
, this call may not be done if the asset is not loaded
(see Tex::get_asset_state
) or the size is inconsistent or the format is incompatible.
see also tex_set_colors
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color32},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut color_dots = [127u8; 16 * 16 * 4];
let mut tex = Tex::new(TexType::Image, TexFormat::RGBA32, None);
tex.set_colors_u8(16, 16, &color_dots, 4);
let check_dots = [Color32::BLACK; 16 * 16];
assert!(tex.get_color_data::<Color32>(&check_dots, 0));
assert_eq!(check_dots[0],Color32{r:127,g:127,b:127,a:127});
Sourcepub fn set_colors_r16(
&mut self,
width: usize,
height: usize,
data: &[u16],
) -> &mut Self
pub fn set_colors_r16( &mut self, width: usize, height: usize, data: &[u16], ) -> &mut Self
Set the texture’s pixels using a scalar array for channel R ! This function should only be called on textures with a format of R16u. You can call this as many times as you’d like, even with different widths and heights. Calling this multiple times will mark it as dynamic on the graphics card. Calling this function can also result in building mip-maps, which has a non-zero cost: use TexType.ImageNomips when creating the Tex to avoid this. https://stereokit.net/Pages/StereoKit/Tex/SetColors.html
width
- Width in pixels of the texture. Powers of two are generally best!height
- Height in pixels of the texture. Powers of two are generally best!data
- An array of 16 bit values, should be a length of width*height.
Warning, instead of Tex::set_colors
, this call may not be done if the asset is not loaded
(see Tex::get_asset_state
) or the size is inconsistent or the format is incompatible.
see also tex_set_colors
§Examples
use stereokit_rust::{maths::{Vec3, Matrix},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut color_dots = [256u16; 16 * 16];
let mut tex = Tex::new(TexType::Image, TexFormat::R16u, None);
tex.set_colors_r16(16, 16, &color_dots);
let check_dots = [0u16; 16 * 16];
assert!(tex.get_color_data::<u16>(&check_dots, 0));
assert_eq!(check_dots, color_dots);
Sourcepub fn set_colors_r32(
&mut self,
width: usize,
height: usize,
data: &[f32],
) -> &mut Self
pub fn set_colors_r32( &mut self, width: usize, height: usize, data: &[f32], ) -> &mut Self
Set the texture’s pixels using a scalar array! This function should only be called on textures with a format of R32. You can call this as many times as you’d like, even with different widths and heights. Calling this multiple times will mark it as dynamic on the graphics card. Calling this function can also result in building mip-maps, which has a non-zero cost: use TexType.ImageNomips when creating the Tex to avoid this. https://stereokit.net/Pages/StereoKit/Tex/SetColors.html
width
- Width in pixels of the texture. Powers of two are generally best!height
- Height in pixels of the texture. Powers of two are generally best!data
- An array of 32 bit values, should be a length of width*height.
Warning, instead of Tex::set_colors
, this call may not be done if the asset is not loaded
(see Tex::get_asset_state
) or the size is inconsistent or the format is incompatible.
see also tex_set_colors
§Examples
use stereokit_rust::{maths::{Vec3, Matrix},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut color_dots = [0.13f32; 16 * 16];
let mut tex = Tex::new(TexType::Image, TexFormat::R32, None);
tex.set_colors_r32(16, 16, &color_dots);
let check_dots = [0.0f32; 16 * 16];
assert!(tex.get_color_data::<f32>(&check_dots, 0));
assert_eq!(check_dots, color_dots);
Sourcepub fn set_zbuffer(&mut self, tex: Option<Tex>) -> &mut Self
pub fn set_zbuffer(&mut self, tex: Option<Tex>) -> &mut Self
This allows you to attach a z/depth buffer from a rendertarget texture. This texture must be a rendertarget to set this, and the zbuffer texture must be a depth format (or null). For no-rendertarget textures, this will always be None. https://stereokit.net/Pages/StereoKit/Tex/SetZBuffer.html
tex
- TODO: None may crash the program
see also tex_set_zbuffer
Tex::add_zbuffer
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color32},
system::Renderer,
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut tex = Tex::render_target(128, 128, Some(2), Some(TexFormat::RGBA32),
Some(TexFormat::Depth16))
.expect("Tex should be created");
let zbuffer = tex.get_zbuffer().expect("Tex should have a zbuffer");
let mut tex2 = Tex::render_target(128, 128, Some(2), Some(TexFormat::RGBA32),
Some(TexFormat::None))
.expect("Tex2 should be created");
tex2.set_zbuffer(Some(zbuffer));
assert_ne!(tex2.get_zbuffer(), None);
//tex2.set_zbuffer(None);
//assert_eq!(tex2.get_zbuffer(), None);
Sourcepub unsafe fn set_native_surface(
&mut self,
native_surface: *mut c_void,
tex_type: TexType,
native_fmt: i64,
width: i32,
height: i32,
surface_count: i32,
owned: bool,
) -> &mut Self
pub unsafe fn set_native_surface( &mut self, native_surface: *mut c_void, tex_type: TexType, native_fmt: i64, width: i32, height: i32, surface_count: i32, owned: bool, ) -> &mut Self
This function is dependent on the graphics backend! It will take a texture resource for the current graphics backend (D3D or GL) and wrap it in a StereoKit texture for use within StereoKit. This is a bit of an advanced feature.
§Safety
native_surface must be a valid pointer to a texture resource for the current graphics backend. https://stereokit.net/Pages/StereoKit/Tex/SetNativeSurface.html
native_surface
- For D3D, this should be an ID3D11Texture2D*, and for GL, this should be a uint32_t from a glGenTexture call, coerced into the IntPtr.tex_type
- The image flags that tell SK how to treat the texture, this should match up with the settings the texture was originally created with. If SK can figure the appropriate settings, it may override the value provided here.native_fmt
- The texture’s format using the graphics backend’s value, not SK’s. This should match up with the settings the texture was originally created with. If SK can figure the appropriate settings, it may override the value provided here. 0 is a valide default value.width
- Width of the texture. This should match up with the settings the texture was originally created with. If SK can figure the appropriate settings, it may override the value provided here. 0 is a valide default value.height
- Height of the texture. This should match up with the settings the texture was originally created with. If SK can figure the appropriate settings, it may override the value provided here. 0 is a valide default value.surface_count
- Texture array surface count. This should match up with the settings the texture was originally created with. If SK can figure the appropriate settings, it may override the value provided here. 1 is a valide default value.owned
- Should ownership of this texture resource be passed on to StereoKit? If so, StereoKit may delete it when it’s finished with it. True is a valide default value, if this is not desired, pass in false.
see also tex_set_surface
§Examples
let mut tex = Tex::new(TexType::Image, TexFormat::RGBA32, None);
let native_surface = tex.get_native_surface();
unsafe { tex.set_native_surface(native_surface, TexType::Image, 0, 1, 1, 1, false); }
Sourcepub fn set_size(&mut self, width: usize, height: usize) -> &mut Self
pub fn set_size(&mut self, width: usize, height: usize) -> &mut Self
Set the texture’s size without providing any color data. In most cases, you should probably just call SetColors instead, but this can be useful if you’re adding color data some other way, such as when blitting or rendering to it. https://stereokit.net/Pages/StereoKit/Tex/SetSize.html
see also tex_set_colors
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color32},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let mut tex = Tex::new(TexType::Image, TexFormat::RGBA32, None);
assert_eq!(tex.get_width(), Some(0));
assert_eq!(tex.get_height(), Some(0));
tex.set_size(16, 16);
assert_eq!(tex.get_width(), Some(16));
assert_eq!(tex.get_height(), Some(16));
let check_dots = [Color32::BLACK; 16 * 16];
assert!(tex.get_color_data::<Color32>(&check_dots, 0));
Sourcepub fn fallback_override<T: AsRef<Tex>>(&mut self, fallback: T) -> &mut Self
pub fn fallback_override<T: AsRef<Tex>>(&mut self, fallback: T) -> &mut Self
This will override the default fallback texture that gets used before the Tex has finished loading. This is useful for textures with a specific purpose where the normal fallback texture would appear strange, such as a metal/rough map. https://stereokit.net/Pages/StereoKit/Tex/FallbackOverride.html
see also tex_set_fallback
Tex::set_loading_fallback
§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors, Color128},
tex::{Tex, TexFormat, TexType}, mesh::Mesh, material::Material};
let tex_fallback = Tex::gen_color(named_colors::VIOLET, 128, 128, TexType::Image, TexFormat::RGBA32);
let mut tex = Tex::new(TexType::Image, TexFormat::RGBA32, None);
tex.fallback_override(&tex_fallback);
let tex = Tex::new(TexType::Image, TexFormat::RGBA32, Some("tex_left_ID"));
let tex_metal = Tex::from_file("textures/parquet2/parquet2metal.ktx2", true, Some(9999))
.expect("Metal tex should be created");
let mut material = Material::pbr().tex_copy(tex);
material.metal_tex(&tex_metal);
let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let transform_floor = Matrix::t( [0.0, -0.5, 0.0]);
test_steps!( // !!!! Get a proper main loop !!!!
plane_mesh.draw(token, &material, transform_floor, None, None);
);
Sourcepub fn sample_mode(&mut self, sample: TexSample) -> &mut Self
pub fn sample_mode(&mut self, sample: TexSample) -> &mut Self
When sampling a texture that’s stretched, or shrunk beyond its screen size, how do we handle figuring out which color to grab from the texture? Default is Linear. https://stereokit.net/Pages/StereoKit/Tex/SampleMode.html
see also tex_set_sample
§Examples
use stereokit_rust::{util::named_colors,
tex::{Tex, TexFormat, TexType, TexSample}};
let mut tex = Tex::gen_color(named_colors::VIOLET, 128, 128, TexType::Image, TexFormat::RGBA32);
assert_eq!(tex.get_sample_mode(), TexSample::Linear);
tex.sample_mode(TexSample::Anisotropic);
assert_eq!(tex.get_sample_mode(), TexSample::Anisotropic);
Sourcepub fn address_mode(&mut self, address_mode: TexAddress) -> &mut Self
pub fn address_mode(&mut self, address_mode: TexAddress) -> &mut Self
Do we Wrap to the other side? Clamp it between 0-1, or just keep Mirroring back and forth? Wrap is the default. https://stereokit.net/Pages/StereoKit/Tex/AddressMode.html
see also tex_set_address
§Examples
use stereokit_rust::{util::named_colors,
tex::{Tex, TexFormat, TexType, TexAddress}};
let mut tex = Tex::gen_color(named_colors::VIOLET, 128, 128, TexType::Image, TexFormat::RGBA32);
assert_eq!(tex.get_address_mode(), TexAddress::Wrap);
tex.address_mode(TexAddress::Mirror);
assert_eq!(tex.get_address_mode(), TexAddress::Mirror);
Sourcepub fn anisotropy(&mut self, anisotropy_level: i32) -> &mut Self
pub fn anisotropy(&mut self, anisotropy_level: i32) -> &mut Self
When SampleMode is set to Anisotropic, this is the number of samples the GPU takes to figure out the correct color. Default is 4, and 16 is pretty high. https://stereokit.net/Pages/StereoKit/Tex/Anisoptropy.html https://stereokit.net/Pages/StereoKit/Tex/Anisotropy.html
see also tex_set_anisotropy
§Examples
use stereokit_rust::{util::named_colors,
tex::{Tex, TexFormat, TexType, TexSample}};
let mut tex = Tex::gen_color(named_colors::VIOLET, 128, 128, TexType::Image, TexFormat::RGBA32);
assert_eq!(tex.get_sample_mode(), TexSample::Linear);
assert_eq!(tex.get_anisotropy(), 4);
tex.sample_mode(TexSample::Anisotropic).anisotropy(10);
assert_eq!(tex.get_anisotropy(), 10);
Sourcepub fn get_id(&self) -> &str
pub fn get_id(&self) -> &str
Gets the unique identifier of this asset resource! This can be helpful for debugging, managing your assets, or finding them later on! https://stereokit.net/Pages/StereoKit/Tex/Id.html
see also tex_get_id
see example in Tex::id
Sourcepub fn get_asset_state(&self) -> AssetState
pub fn get_asset_state(&self) -> AssetState
Textures are loaded asyncronously, so this tells you the current state of this texture! This also can tell if an error occured, and what type of error it may have been. https://stereokit.net/Pages/StereoKit/Tex/AssetState.html
see also tex_asset_state
§Examples
use stereokit_rust::{util::named_colors, system::AssetState,
tex::{Tex, TexFormat, TexType}};
let tex = Tex::gen_color(named_colors::VIOLET, 128, 128,
TexType::Image, TexFormat::RGBA32);
assert_eq!(tex.get_asset_state(), AssetState::Loaded);
let tex_icon = Tex::from_file("icons/checked.png", true, None)
.expect("Tex_icon should be created");
assert_ne!(tex_icon.get_asset_state(), AssetState::NotFound);
let tex_not_icon = Tex::from_file("icccons/checddked.png", true, None)
.expect("Tex_not_icon should be created");
assert_ne!(tex_not_icon.get_asset_state(), AssetState::Loaded);
test_steps!( // !!!! Get a proper main loop !!!!
// We ensure to have the Tex loaded.
if tex_icon.get_asset_state() != AssetState::Loaded
|| tex_not_icon.get_asset_state() == AssetState::Loading { iter -= 1; }
);
assert_eq!(tex_icon.get_asset_state(), AssetState::Loaded);
assert_eq!(tex_not_icon.get_asset_state(), AssetState::NotFound);
assert_eq!(tex_not_icon.get_width(), None);
assert_eq!(tex_not_icon.get_height(), None);
Sourcepub fn get_format(&self) -> Option<TexFormat>
pub fn get_format(&self) -> Option<TexFormat>
The StereoKit format this texture was initialized with. This will be a blocking call if AssetState is less than LoadedMeta so None will be return instead https://stereokit.net/Pages/StereoKit/Tex/Format.html
see also tex_get_format
§Examples
use stereokit_rust::{util::named_colors, system::AssetState,
tex::{Tex, TexFormat, TexType}};
let tex = Tex::gen_color(named_colors::VIOLET, 128, 128,
TexType::Image, TexFormat::RGBA128);
assert_eq!(tex.get_format(), Some(TexFormat::RGBA128));
let tex_icon = Tex::from_file("icons/checked.png", true, None)
.expect("Tex_icon should be created");
let tex_not_icon = Tex::from_file("icccons/checddked.png", true, None)
.expect("Tex_not_icon should be created");
test_steps!( // !!!! Get a proper main loop !!!!
// We ensure to have the Tex loaded.
if tex_icon.get_asset_state() != AssetState::Loaded
|| tex_not_icon.get_asset_state() == AssetState::Loading { iter -= 1; }
);
assert_eq!(tex_icon.get_format(), Some(TexFormat::RGBA32));
assert_eq!(tex_not_icon.get_format(), None);
Sourcepub fn get_zbuffer(&self) -> Option<Tex>
pub fn get_zbuffer(&self) -> Option<Tex>
This allows you to retreive a z/depth buffer from a rendertarget texture. This texture must be a rendertarget to set this, and the zbuffer texture must be a depth format (or null). For no-rendertarget textures, this will always be null. https://stereokit.net/Pages/StereoKit/Tex/GetZBuffer.html
see also tex_get_zbuffer
see example in Tex::set_zbuffer
Sourcepub fn get_native_surface(&self) -> *mut c_void
pub fn get_native_surface(&self) -> *mut c_void
This will return the texture’s native resource for use with external libraries. For D3D, this will be an ID3D11Texture2D*, and for GL, this will be a uint32_t from a glGenTexture call, coerced into the IntPtr. This call will block execution until the texture is loaded, if it is not already. https://stereokit.net/Pages/StereoKit/Tex/GetNativeSurface.html
see also tex_get_surface
see example in Tex::set_native_surface
Sourcepub fn get_width(&self) -> Option<usize>
pub fn get_width(&self) -> Option<usize>
The width of the texture, in pixels. This will be a blocking call if AssetState is less than LoadedMeta so None will be return instead https://stereokit.net/Pages/StereoKit/Tex/Width.html
see also tex_get_width
see example in Tex::set_size
Tex::get_asset_state
Sourcepub fn get_height(&self) -> Option<usize>
pub fn get_height(&self) -> Option<usize>
The height of the texture, in pixels. This will be a blocking call if AssetState is less than LoadedMeta so None will be return instead https://stereokit.net/Pages/StereoKit/Tex/Height.html
see also tex_get_height
see example in Tex::set_size
Tex::get_asset_state
Sourcepub fn get_data_infos(&self, mip: i8) -> Option<(usize, usize, usize)>
pub fn get_data_infos(&self, mip: i8) -> Option<(usize, usize, usize)>
Non-canon function which returns a tuple made of (width, heigh, size) of the corresponding texture.
use mip
< 0 for textures using TexType::ImageNomips
use mip
>=0 to retrieve the info about one MIP of the texture
the size corresponding to the mip texture and the width and height of this mip texture This will be a blocking call if AssetState is less than LoadedMeta so None will be return instead
§Examples
use stereokit_rust::{util::{named_colors, Color32}, system::AssetState,
tex::{Tex, TexFormat, TexType}};
let mut color_dots = [named_colors::CYAN; 16 * 16];
let mut tex = Tex::new(TexType::Image, TexFormat::RGBA32, None);
tex.set_colors32(16, 16, &color_dots);
let check_dots = [Color32::WHITE; 16 * 16];
assert!(tex.get_color_data::<Color32>(&check_dots, 0));
assert_eq!(check_dots, color_dots);
let (width, height, size) = tex.get_data_infos(0).expect("tex should be loaded");
assert_eq!(width, 16);
assert_eq!(height, 16);
assert_eq!(size, 256);
let (width, height, size) = tex.get_data_infos(1).expect("tex should be loaded");
assert_eq!(width, 8);
assert_eq!(height, 8);
assert_eq!(size, 64);
let tex_icon = Tex::from_file("icons/checked.png", true, None)
.expect("Tex_icon should be created");
test_steps!( // !!!! Get a proper main loop !!!!
// We ensure to have the Tex loaded.
if tex_icon.get_asset_state() != AssetState::Loaded { iter -= 1; }
);
assert_eq!(tex_icon.get_data_infos(0), Some((128, 128, 16384)));
Sourcepub fn get_color_data<T>(&self, color_data: &[T], mip_level: i8) -> bool
pub fn get_color_data<T>(&self, color_data: &[T], mip_level: i8) -> bool
Retrieve the color data of the texture from the GPU. This can be a very slow operation, so use it cautiously. The out_data pointer must correspond to an array with the correct size. https://stereokit.net/Pages/StereoKit/Tex/GetColorData.html
- mip_level - Retrieves the color data for a specific mip-mapping level. This function will log a fail and return a black array if an invalid mip-level is provided.
The function Tex::get_data_infos
may help you to shape the right receiver.
see also tex_get_data
§Examples
use stereokit_rust::{util::{named_colors, Color32, Color128},
tex::{Tex, TexFormat, TexType}};
let mut tex = Tex::gen_color(named_colors::CYAN, 8 , 8, TexType::Image, TexFormat::RGBA32);
let check_dots = [Color32::WHITE; 8 * 8];
assert!(tex.get_color_data::<Color32>(&check_dots, 0));
assert_eq!(check_dots[5], named_colors::CYAN);
let mut tex = Tex::gen_color(named_colors::MAGENTA, 8 , 8, TexType::Image, TexFormat::RGBA128);
let check_dots = [Color128::WHITE; 8 * 8];
assert!(tex.get_color_data::<Color128>(&check_dots, 0));
assert_eq!(check_dots[5], named_colors::MAGENTA.into());
Sourcepub fn get_color_data_u8(
&self,
color_data: &[u8],
color_size: usize,
mip_level: i8,
) -> bool
pub fn get_color_data_u8( &self, color_data: &[u8], color_size: usize, mip_level: i8, ) -> bool
Non canonical function! Retrieve the color data of the texture from the GPU. This can be a very slow operation, so use it cautiously. The out_data pointer must correspond to an u8 array with the correct size. https://stereokit.net/Pages/StereoKit/Tex/GetColorData.html
color_size
: number of bytes of the color (Color32: 4, Color128: 16 …)mip_level
- Retrieves the color data for a specific mip-mapping level. This function will log a fail and return a black array if an invalid mip-level is provided.
The function Tex::get_data_infos
may help you to shape the right receiver.
see also tex_get_data
§Examples
use stereokit_rust::{util::{named_colors, Color32},
tex::{Tex, TexFormat, TexType}};
let mut tex = Tex::gen_color(named_colors::CYAN, 8 , 8, TexType::Image, TexFormat::RGBA32);
let mut check_dots = [0u8; 8 * 8 * 4];
assert!(tex.get_color_data_u8(&mut check_dots, 4, 0));
assert_eq!(check_dots[5*4], named_colors::CYAN.r);
assert_eq!(check_dots[5*4+1], named_colors::CYAN.g);
assert_eq!(check_dots[5*4+2], named_colors::CYAN.b);
assert_eq!(check_dots[5*4+3], named_colors::CYAN.a);
Sourcepub fn get_sample_mode(&self) -> TexSample
pub fn get_sample_mode(&self) -> TexSample
When sampling a texture that’s stretched, or shrunk beyond its screen size, how do we handle figuring out which color to grab from the texture? Default is Linear. https://stereokit.net/Pages/StereoKit/Tex/SampleMode.html
see also tex_get_sample
see example in Tex::sample_mode
Sourcepub fn get_address_mode(&self) -> TexAddress
pub fn get_address_mode(&self) -> TexAddress
When looking at a UV texture coordinate on this texture, how do we handle values larger than 1, or less than zero? Do we Wrap to the other side? Clamp it between 0-1, or just keep Mirroring back and forth? Wrap is the default. https://stereokit.net/Pages/StereoKit/Tex/AddressMode.html
see also tex_get_address
see example in Tex::address_mode
Sourcepub fn get_anisotropy(&self) -> i32
pub fn get_anisotropy(&self) -> i32
When SampleMode is set to Anisotropic, this is the number of samples the GPU takes to figure out the correct color. Default is 4, and 16 is pretty high. https://stereokit.net/Pages/StereoKit/Tex/Anisoptropy.html https://stereokit.net/Pages/StereoKit/Tex/Anisotropy.html
see also tex_get_anisotropy
see example in Tex::anisotropy
Sourcepub fn get_mips(&self) -> Option<i32>
pub fn get_mips(&self) -> Option<i32>
The number of mip-map levels this texture has. This will be 1 if the texture doesn’t have mip mapping enabled. This will be a blocking call if AssetState is less than LoadedMeta so None will be return instead. https://stereokit.net/Pages/StereoKit/Tex/Mips.html
see also tex_get_mips
§Examples
use stereokit_rust::{util::named_colors, system::AssetState,
tex::{Tex, TexFormat, TexType}};
let tex_nomips = Tex::gen_color(named_colors::VIOLET, 128, 128,
TexType::ImageNomips, TexFormat::RGBA32);
let tex = Tex::gen_color(named_colors::VIOLET, 128, 128,
TexType::Image, TexFormat::RGBA32);
let tex_icon = Tex::from_file("icons/checked.png", true, None)
.expect("Tex_icon should be created");
// TODO: assert_eq!(tex_icon.get_mips(), None);
let tex_not_icon = Tex::from_file("Not an icon file", true, None)
.expect("Tex_not_icon should be created");
assert_eq!(tex_not_icon.get_mips(), None);
test_steps!( // !!!! Get a proper main loop !!!!
// We ensure to have the Tex loaded.
if tex_icon.get_asset_state() != AssetState::Loaded
|| tex_not_icon.get_asset_state() == AssetState::Loading { iter -= 1; }
);
assert_eq!(tex_nomips.get_mips(), Some(1));
// TODO: assert_eq!(tex.get_mips(), Some(8));
// TODO: assert_eq!(tex_icon.get_mips(), Some(8));
assert_eq!(tex_not_icon.get_mips(), None);
Sourcepub fn get_cubemap_lighting(&self) -> SHCubemap
pub fn get_cubemap_lighting(&self) -> SHCubemap
ONLY valid for cubemap textures! This will calculate a spherical harmonics representation of the cubemap for use with StereoKit’s lighting. First call may take a frame or two of time, but subsequent calls will pull from a cached value. https://stereokit.net/Pages/StereoKit/Tex/CubemapLighting.html
see also tex_get_cubemap_lighting
use instead SHCubemap
§Examples
use stereokit_rust::{util::named_colors, maths::Vec3,
tex::{Tex, TexFormat, TexType}};
let tex = Tex::gen_color(named_colors::VIOLET, 128, 128,
TexType::Cubemap, TexFormat::RGBA32);
// Cubemap must be created with SHCubemap static methods.
let sh_cubemap = tex.get_cubemap_lighting();
assert_eq!(sh_cubemap.sh.coefficients[2], Vec3::ZERO);
assert_eq!(sh_cubemap.sh.coefficients[5], Vec3::ZERO);
Sourcepub fn black() -> Self
pub fn black() -> Self
Default 2x2 black opaque texture, this is the texture referred to as ‘black’ in the shader texture defaults. https://stereokit.net/Pages/StereoKit/Tex/Black.html
§Examples
use stereokit_rust::tex::Tex;
let tex= Tex::black();
assert_eq!(tex.get_id(), "default/tex_black");
Sourcepub fn dev_tex() -> Self
pub fn dev_tex() -> Self
This is a white checkered grid texture used to easily add visual features to materials. By default, this is used for the loading fallback texture for all Tex objects. https://stereokit.net/Pages/StereoKit/Tex/DevTex.html
§Examples
use stereokit_rust::tex::Tex;
let tex = Tex::dev_tex();
assert_eq!(tex.get_id(), "default/tex_devtex");
Sourcepub fn error() -> Self
pub fn error() -> Self
This is a red checkered grid texture used to indicate some sort of error has occurred. By default, this is used for the error fallback texture for all Tex objects. https://stereokit.net/Pages/StereoKit/Tex/Error.html
§Examples
use stereokit_rust::tex::Tex;
let tex = Tex::error();
assert_eq!(tex.get_id(), "default/tex_error");
Sourcepub fn flat() -> Self
pub fn flat() -> Self
Default 2x2 flat normal texture, this is a normal that faces out from the, face, and has a color value of (0.5,0.5,1). This is the texture referred to as ‘flat’ in the shader texture defaults. https://stereokit.net/Pages/StereoKit/Tex/Flat.html
§Examples
use stereokit_rust::tex::Tex;
let tex = Tex::flat();
assert_eq!(tex.get_id(), "default/tex_flat");
Sourcepub fn gray() -> Self
pub fn gray() -> Self
Default 2x2 middle gray (0.5,0.5,0.5) opaque texture, this is the texture referred to as ‘gray’ in the shader texture defaults. https://stereokit.net/Pages/StereoKit/Tex/Gray.html
§Examples
use stereokit_rust::tex::Tex;
let tex = Tex::gray();
assert_eq!(tex.get_id(), "default/tex_gray");
Sourcepub fn rough() -> Self
pub fn rough() -> Self
Default 2x2 roughness color (1,1,0,1) texture, this is the texture referred to as ‘rough’ in the shader texture defaults. https://stereokit.net/Pages/StereoKit/Tex/Rough.html
§Examples
use stereokit_rust::tex::Tex;
let tex = Tex::rough();
assert_eq!(tex.get_id(), "default/tex_rough");
Sourcepub fn white() -> Self
pub fn white() -> Self
Default 2x2 white opaque texture, this is the texture referred to as ‘white’ in the shader texture defaults. https://stereokit.net/Pages/StereoKit/Tex/White.html
§Examples
use stereokit_rust::tex::Tex;
let tex = Tex::white();
assert_eq!(tex.get_id(), "default/tex");
Trait Implementations§
Source§impl Default for Tex
impl Default for Tex
Source§fn default() -> Self
fn default() -> Self
A Default texture may be asked when a Tex creation or find returned an error. Tex::error()
is a good default
value.
Source§impl IAsset for Tex
impl IAsset for Tex
Source§fn get_id(&self) -> &str
fn get_id(&self) -> &str
impl Send for Tex
impl StructuralPartialEq for Tex
impl Sync for Tex
Auto Trait Implementations§
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.