pub struct Texture {
pub label: String,
pub texture: Texture,
pub format: TextureFormat,
pub view: TextureView,
pub sampler: Sampler,
pub size: (u32, u32),
pub sample_count: u32,
pub layer_count: u32,
pub mip_level_count: u32,
}Expand description
Texture wrapper with a ready-to-use view and sampler.
§Examples
Create a render target and clear it:
use wde_wgpu::{texture::{Texture, TextureFormat, TextureUsages}, instance::RenderInstanceData};
let color = Texture::new(
instance,
"color-target",
(1280, 720),
TextureFormat::Rgba8Unorm,
TextureUsages::RENDER_ATTACHMENT | TextureUsages::COPY_SRC,
);Upload raw pixel data (RGBA8):
use wde_wgpu::{texture::{Texture, TextureFormat, TextureUsages}, instance::RenderInstanceData};
let texture = Texture::new(
instance,
"albedo",
(512, 512),
TextureFormat::Rgba8Unorm,
TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST,
);
texture.copy_from_buffer(instance, TextureFormat::Rgba8Unorm, pixels);
// Or
texture.copy_from_buffer_layered(instance, TextureFormat::Rgba8Unorm, 0, pixels); // For texture arraysCopy one GPU texture into another:
let dst = Texture::new(
instance,
"blit-target",
(1024, 1024),
TextureFormat::Rgba8Unorm,
TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING,
);
dst.copy_from_texture(instance, src, (1024, 1024));Fields§
§label: String§texture: Texture§format: TextureFormat§view: TextureView§sampler: Sampler§size: (u32, u32)§sample_count: u32§layer_count: u32§mip_level_count: u32Implementations§
Source§impl Texture
impl Texture
Sourcepub fn new(
instance: &RenderInstanceData<'_>,
label: &str,
size: (u32, u32),
format: TextureFormat,
usage: TextureUsages,
sample_count: u32,
layer_count: u32,
mip_level_count: u32,
) -> Self
pub fn new( instance: &RenderInstanceData<'_>, label: &str, size: (u32, u32), format: TextureFormat, usage: TextureUsages, sample_count: u32, layer_count: u32, mip_level_count: u32, ) -> Self
Create a new texture.
§Arguments
instance- Game instance.label- Label of the texture. This is only for debugging purposes.size- Size of the texture (width, height).format- Format of the texture (e.g. Rgba8Unorm, Depth32Float, etc.).usage- Usage of the texture (e.g. RENDER_ATTACHMENT, COPY_SRC, COPY_DST, etc.).sample_count- Sample count of the texture (e.g. 1 for no MSAA, 4 for 4x MSAA, etc.).layer_count- Number of layers in the texture array. Default is 1 (for non-array textures).mip_level_count- Number of mip levels. Default is 1 (no mipmaps). If set to 0, it will be auto-calculated based on the texture size.
Sourcepub fn copy_from_buffer(
&self,
instance: &RenderInstanceData<'_>,
texture_format: TextureFormat,
buffer: &[u8],
)
pub fn copy_from_buffer( &self, instance: &RenderInstanceData<'_>, texture_format: TextureFormat, buffer: &[u8], )
Copy buffer to texture. It is assumed that the buffer is the same size as the texture. It will be copied on the next queue submit. Note that the buffer must have the COPY_DST usage.
§Arguments
instance- Game instance.texture_format- The wgpu texture format.buffer- Image buffer.
Sourcepub fn copy_from_buffer_layered(
&self,
instance: &RenderInstanceData<'_>,
texture_format: TextureFormat,
array_layer: u32,
buffer: &[u8],
)
pub fn copy_from_buffer_layered( &self, instance: &RenderInstanceData<'_>, texture_format: TextureFormat, array_layer: u32, buffer: &[u8], )
Copy texture to buffer at a given array layer. It is assumed that the buffer is the same size as the texture. It will be copied on the next queue submit. Note that the buffer must have the COPY_DST usage.
§Arguments
instance- Game instance.texture_format- The wgpu texture format.array_layer- The array layer to copy from (for texture arrays). Default is 0 for non-array textures.buffer- Image buffer.
Sourcepub fn copy_from_texture(
&self,
instance: &RenderInstanceData<'_>,
texture: &Texture,
size: (u32, u32),
)
pub fn copy_from_texture( &self, instance: &RenderInstanceData<'_>, texture: &Texture, size: (u32, u32), )
Copy texture to texture. It is assumed that the texture is the same size as the source texture. Note that the input texture must have the COPY_SRC usage, and the output texture must have the COPY_DST usage.
§Arguments
instance- Game instance.texture- Texture to copy from.size- Size of the texture.
Sourcepub fn copy_from_surface_texture(
&self,
instance: &RenderInstanceData<'_>,
surface_texture: &SurfaceTexture,
size: (u32, u32),
)
pub fn copy_from_surface_texture( &self, instance: &RenderInstanceData<'_>, surface_texture: &SurfaceTexture, size: (u32, u32), )
Copy texture from a surface texture (e.g. swapchain frame). It is assumed that the texture is the same size as the source texture. Note that the input texture must have the COPY_SRC usage, and the output texture must have the COPY_DST usage.
§Arguments
instance- Game instance.surface_texture- Surface texture to copy from.size- Size of the texture.
Sourcepub fn copy_from_texture_layered(
&self,
instance: &RenderInstanceData<'_>,
texture: &Texture,
array_layer: usize,
size: (u32, u32),
)
pub fn copy_from_texture_layered( &self, instance: &RenderInstanceData<'_>, texture: &Texture, array_layer: usize, size: (u32, u32), )
Copy texture to texture at a given array layer. It is assumed that the texture is the same size as the source texture. Note that the input texture must have the COPY_SRC usage, and the output texture must have the COPY_DST usage.
§Arguments
instance- Game instance.texture- Texture to copy from.array_layer- The array layer to copy to (for texture arrays). Default is 0 for non-array textures.size- Size of the texture.
Sourcepub fn generate_mipmaps(&self, instance: &RenderInstanceData<'_>)
pub fn generate_mipmaps(&self, instance: &RenderInstanceData<'_>)
Generate mipmaps for this texture. The texture must have been created with TEXTURE_BINDING | RENDER_ATTACHMENT | COPY_SRC usage. This method uses a simple blit approach to downsample each mip level from the previous one.
§Arguments
instance- Game instance.
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§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>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§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.§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.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§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