pub struct Texture {
pub texture: Texture,
pub view: TextureView,
pub sampler: Sampler,
pub tex_params: TexParams,
}
Fields§
§texture: Texture
§view: TextureView
§sampler: Sampler
§tex_params: TexParams
Implementations§
Source§impl Texture
impl Texture
pub fn new( device: &Device, width: u32, height: u32, format: TextureFormat, usage: TextureUsages, tex_params: TexParams, ) -> Self
Sourcepub fn from_bytes(
device: &Device,
queue: &Queue,
bytes: &[u8],
label: &str,
) -> Self
pub fn from_bytes( device: &Device, queue: &Queue, bytes: &[u8], label: &str, ) -> Self
§Panics
Will panic if bytes cannot be decoded into a image representation
pub fn from_image( device: &Device, queue: &Queue, img: &DynamicImage, label: Option<&str>, ) -> Self
Sourcepub fn from_path(
path: &str,
device: &Device,
queue: &Queue,
is_srgb: bool,
) -> Self
pub fn from_path( path: &str, device: &Device, queue: &Queue, is_srgb: bool, ) -> Self
reads image from format and into this texture
if is_srgb
is set then the reading will perform a conversion from
gamma space to linear space when sampling the texture in a shader
When writing to the texture, the opposite conversion takes place.
§Panics
Will panic if the path cannot be found
Sourcepub fn from_img(
img: &DynImage,
device: &Device,
queue: &Queue,
is_srgb: bool,
generate_mipmaps: bool,
mipmap_generation_cpu: bool,
staging_buffer: Option<&Buffer>,
mipmaper: Option<&RenderMipmapGenerator>,
) -> Self
pub fn from_img( img: &DynImage, device: &Device, queue: &Queue, is_srgb: bool, generate_mipmaps: bool, mipmap_generation_cpu: bool, staging_buffer: Option<&Buffer>, mipmaper: Option<&RenderMipmapGenerator>, ) -> Self
§Panics
Will panic if textures that have more than 1 byte per channel or more than 4 channels.
Sourcepub fn update_from_img(
&mut self,
img: &DynImage,
device: &Device,
queue: &Queue,
is_srgb: bool,
generate_mipmaps: bool,
mipmap_generation_cpu: bool,
staging_buffer: Option<&Buffer>,
mipmaper: Option<&RenderMipmapGenerator>,
)
pub fn update_from_img( &mut self, img: &DynImage, device: &Device, queue: &Queue, is_srgb: bool, generate_mipmaps: bool, mipmap_generation_cpu: bool, staging_buffer: Option<&Buffer>, mipmaper: Option<&RenderMipmapGenerator>, )
§Panics
Will panic if the image has more than 1 byte per channel
pub fn generate_mipmaps( img: &DynImage, texture: &Texture, device: &Device, queue: &Queue, desc: &TextureDescriptor<'_>, nr_mip_maps: u32, mipmap_generation_cpu: bool, staging_buffer: Option<&Buffer>, mipmaper: Option<&RenderMipmapGenerator>, )
pub fn extent_from_img(img: &DynImage) -> Extent3d
Sourcepub fn format_from_img(img: &DynImage, is_srgb: bool) -> TextureFormat
pub fn format_from_img(img: &DynImage, is_srgb: bool) -> TextureFormat
§Panics
Will panic if the image has more than 1 byte per channel
Sourcepub fn upload_single_mip(
texture: &Texture,
device: &Device,
queue: &Queue,
desc: &TextureDescriptor<'_>,
data: &[u8],
staging_buffer: Option<&Buffer>,
mip: u32,
)
pub fn upload_single_mip( texture: &Texture, device: &Device, queue: &Queue, desc: &TextureDescriptor<'_>, data: &[u8], staging_buffer: Option<&Buffer>, mip: u32, )
Basically the same as device.create_texture_with_data
but without the
creation part and the data is assumed to contain only one mip # Panics
Will panic if the data does not fit in the defined mipmaps described in
textureDescriptor
Sourcepub fn upload_all_mips(
texture: &Texture,
device: &Device,
queue: &Queue,
desc: &TextureDescriptor<'_>,
data: &[u8],
staging_buffer: Option<&Buffer>,
)
pub fn upload_all_mips( texture: &Texture, device: &Device, queue: &Queue, desc: &TextureDescriptor<'_>, data: &[u8], staging_buffer: Option<&Buffer>, )
Basically the same as device.create_texture_with_data
but without the
creation part Assumes the data contains info for all mips
§Panics
Will panic if the data does not fit in the defined mipmaps described in textureDescriptor
pub fn upload_from_cpu_with_staging_buffer( texture: &Texture, device: &Device, queue: &Queue, desc: &TextureDescriptor<'_>, data: &[u8], staging_buffer: &Buffer, mip_lvl: u32, )
Sourcepub async fn download_to_cpu(
&self,
device: &Device,
queue: &Queue,
aspect: TextureAspect,
) -> DynImage
pub async fn download_to_cpu( &self, device: &Device, queue: &Queue, aspect: TextureAspect, ) -> DynImage
This functions downloads the texture to the cpu and returns a DynImage
The aspect of the texture to download is specified by the aspect parameter
This is required since we use texture format Depth32FloatStencil8
which has both a depth and a stencil component
pub async fn download_pixel_to_cpu( &self, device: &Device, queue: &Queue, aspect: TextureAspect, x: u32, y: u32, ) -> DynImage
pub fn remove_padding( buffer: &[u8], bytes_per_row_unpadded: u32, bytes_per_row_padded: u32, nr_rows: u32, ) -> Cow<'_, [u8]>
pub fn create_bind_group_layout( device: &Device, binding_tex: u32, binding_sampler: u32, ) -> BindGroupLayout
pub fn depth_linearize( &self, device: &Device, queue: &Queue, near: f32, far: f32, ) -> DynImage
pub fn create_bind_group( &self, device: &Device, binding_tex: u32, binding_sampler: u32, ) -> BindGroup
pub fn resize(&mut self, device: &Device, width: u32, height: u32)
pub fn create_default_texture(device: &Device, queue: &Queue) -> Self
pub fn create_default_cubemap(device: &Device, queue: &Queue) -> Self
pub fn width(&self) -> u32
pub fn height(&self) -> u32
pub fn extent(&self) -> Extent3d
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> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
Source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
Source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
Source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
Source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
Source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
Source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
Source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
Source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
Source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
Source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
Source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
Source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
Source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
Source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
Source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
Source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
Source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset
. Read moreSource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset
. Read moreSource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset
. Read moreSource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset
. Read moreSource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
Source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
Source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.