pub struct Texture {
pub texture: Arc<Texture>,
pub view: Arc<TextureView>,
pub sampler: Arc<Sampler>,
/* private fields */
}
Expand description
A texture living on the GPU.
Fields§
§texture: Arc<Texture>
§view: Arc<TextureView>
§sampler: Arc<Sampler>
Implementations§
Source§impl Texture
impl Texture
pub const DEPTH_FORMAT: TextureFormat = wgpu::TextureFormat::Depth32Float
pub const HDR_TEXTURE_FORMAT: TextureFormat = wgpu::TextureFormat::Rgba16Float
Sourcepub fn id(&self) -> usize
pub fn id(&self) -> usize
Returns the id of this texture.
The id is a monotonically increasing count of all textures created.
This can be used to determine if a texture has been
replaced by another, which can be used, for example, to invalidate
a [wgpu::BindGroup
].
pub fn width(&self) -> u32
pub fn height(&self) -> u32
pub fn size(&self) -> UVec2
Sourcepub fn new_cubemap_texture(
runtime: impl AsRef<WgpuRuntime>,
label: Option<impl AsRef<str>>,
texture_size: u32,
face_textures: &[Texture],
image_format: TextureFormat,
mip_levels: u32,
) -> Self
pub fn new_cubemap_texture( runtime: impl AsRef<WgpuRuntime>, label: Option<impl AsRef<str>>, texture_size: u32, face_textures: &[Texture], image_format: TextureFormat, mip_levels: u32, ) -> Self
Create a cubemap texture from 6 faces.
Sourcepub fn new_with(
runtime: impl AsRef<WgpuRuntime>,
label: Option<&str>,
usage: Option<TextureUsages>,
sampler: Option<Sampler>,
format: TextureFormat,
color_channels: u32,
color_channel_bytes: u32,
width: u32,
height: u32,
mip_level_count: u32,
data: &[u8],
) -> Self
pub fn new_with( runtime: impl AsRef<WgpuRuntime>, label: Option<&str>, usage: Option<TextureUsages>, sampler: Option<Sampler>, format: TextureFormat, color_channels: u32, color_channel_bytes: u32, width: u32, height: u32, mip_level_count: u32, data: &[u8], ) -> Self
Create a new texture.
Sourcepub fn new(
runtime: impl AsRef<WgpuRuntime>,
label: Option<&str>,
usage: Option<TextureUsages>,
color_channels: u32,
width: u32,
height: u32,
data: &[u8],
) -> Self
pub fn new( runtime: impl AsRef<WgpuRuntime>, label: Option<&str>, usage: Option<TextureUsages>, color_channels: u32, width: u32, height: u32, data: &[u8], ) -> Self
Create a new texture.
This defaults the format to Rgba8UnormSrgb
and assumes a pixel is 1
byte per channel.
pub fn from_image_bytes( runtime: impl AsRef<WgpuRuntime>, bytes: &[u8], label: &str, ) -> Result<Self, TextureError>
pub fn from_dynamic_image( runtime: impl AsRef<WgpuRuntime>, dyn_img: DynamicImage, label: Option<&str>, usage: Option<TextureUsages>, mip_level_count: u32, ) -> Self
pub fn from_image_buffer<P>( runtime: impl AsRef<WgpuRuntime>, img: &ImageBuffer<P, Vec<u8>>, label: Option<&str>, usage: Option<TextureUsages>, mip_level_count: Option<u32>, ) -> Result<Self, TextureError>
pub fn from_wgpu_tex( device: &Device, texture: impl Into<Arc<Texture>>, sampler: Option<SamplerDescriptor<'_>>, mip_level_count: Option<u32>, ) -> Self
pub fn create_depth_texture( device: &Device, width: u32, height: u32, multisample_count: u32, label: Option<&str>, ) -> Self
pub fn create_depth_texture_for_shadow_map( device: &Device, width: u32, height: u32, multisample_count: u32, label: Option<&str>, is_point_light: bool, ) -> Self
Sourcepub fn read(
runtime: impl AsRef<WgpuRuntime>,
texture: &Texture,
width: usize,
height: usize,
channels: usize,
subpixel_bytes: usize,
) -> CopiedTextureBuffer
pub fn read( runtime: impl AsRef<WgpuRuntime>, texture: &Texture, width: usize, height: usize, channels: usize, subpixel_bytes: usize, ) -> CopiedTextureBuffer
Read the texture from the GPU.
To read the texture you must provide the width, height, the number of color/alpha channels and the number of bytes in the underlying subpixel type (usually u8=1, u16=2 or f32=4).
pub async fn read_hdr_image( &self, runtime: impl AsRef<WgpuRuntime>, ) -> Result<Rgba32FImage, TextureError>
Sourcepub fn generate_mips(
&mut self,
runtime: impl AsRef<WgpuRuntime>,
_label: Option<&str>,
mip_levels: u32,
) -> Vec<Self>
pub fn generate_mips( &mut self, runtime: impl AsRef<WgpuRuntime>, _label: Option<&str>, mip_levels: u32, ) -> Vec<Self>
Generate mipmap_levels - 1
mipmaps for the given texture.
§Note
Ensure that self
only has one mip level. If not it will try to sample
from an empty mip.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Texture
impl !RefUnwindSafe for Texture
impl Send for Texture
impl Sync for Texture
impl Unpin for Texture
impl !UnwindSafe for Texture
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute
] value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
[Quirk
] value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition
] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);