Struct nannou_wgpu::TextureBuilder
source · pub struct TextureBuilder { /* private fields */ }
Expand description
A type aimed at simplifying the construction of a Texture.
The builder assumes a set of defaults describing a 128x128, non-multisampled, single-layer, non-linear sRGBA-8 texture. A suite of builder methods may be used to specify the exact properties desired.
Implementations§
source§impl TextureBuilder
impl TextureBuilder
sourcepub const REQUIRED_IMAGE_TEXTURE_USAGE: TextureUsages = wgpu::TextureUsages::COPY_DST
pub const REQUIRED_IMAGE_TEXTURE_USAGE: TextureUsages = wgpu::TextureUsages::COPY_DST
The minimum required texture usage when loading from an image.
sourcepub fn from_image_view<T>(image_view: &T) -> Selfwhere
T: GenericImageView,
T::Pixel: Pixel,
pub fn from_image_view<T>(image_view: &T) -> Selfwhere
T: GenericImageView,
T::Pixel: Pixel,
Produce a texture descriptor from an image.
Specifically, this supports any image type implementing image::GenericImageView
whose
Pixel
type implements Pixel
.
By default, the produced builder will have the wgpu::TextureUsages
returned by
wgpu::TextureBuilder::default_image_texture_usage()
. This is a general-purpose usage that
should allow for copying to and from the texture, sampling the texture and rendering to the
texture. Specifying only the texture usage required may result in better performance. It
may be necessary to manually specify the the usage if STORAGE
is required.
sourcepub fn default_image_texture_usage() -> TextureUsages
pub fn default_image_texture_usage() -> TextureUsages
The default texture usage for the case where a user has loaded a texture from an image.
source§impl Builder
impl Builder
pub const DEFAULT_SIDE: u32 = 128u32
pub const DEFAULT_DEPTH: u32 = 1u32
pub const DEFAULT_SIZE: Extent3d = _
pub const DEFAULT_ARRAY_LAYER_COUNT: u32 = 1u32
pub const DEFAULT_MIP_LEVEL_COUNT: u32 = 1u32
pub const DEFAULT_SAMPLE_COUNT: u32 = 1u32
pub const DEFAULT_DIMENSION: TextureDimension = wgpu::TextureDimension::D2
pub const DEFAULT_FORMAT: TextureFormat = wgpu::TextureFormat::Rgba8Unorm
pub const DEFAULT_USAGE: TextureUsages = _
pub const DEFAULT_DESCRIPTOR: TextureDescriptor<'static> = _
sourcepub fn size(self, [width, height]: [u32; 2]) -> Self
pub fn size(self, [width, height]: [u32; 2]) -> Self
Specify the width and height of the texture.
Note: On calls to size
, depth
and extent
the Builder
will attempt to infer the
wgpu::TextureDimension
of its inner wgpu::TextureDescriptor
by examining its size
field. Use TextureBuilder::dimension()
to override this behavior.
sourcepub fn depth(self, depth: u32) -> Self
pub fn depth(self, depth: u32) -> Self
Specify the depth of the texture.
Note: On calls to size
, depth
and extent
the Builder
will attempt to infer the
wgpu::TextureDimension
of its inner wgpu::TextureDescriptor
by examining its size
field. Use TextureBuilder::dimension()
to override this behavior.
sourcepub fn extent(self, extent: Extent3d) -> Self
pub fn extent(self, extent: Extent3d) -> Self
Specify the width, height and depth of the texture.
Note: On calls to size
, depth
and extent
the Builder
will attempt to infer the
wgpu::TextureDimension
of its inner wgpu::TextureDescriptor
by examining its size
field. Use TextureBuilder::dimension()
to override this behavior.
sourcepub fn dimension(self, dimension: TextureDimension) -> Self
pub fn dimension(self, dimension: TextureDimension) -> Self
Specify the dimension of the texture, overriding inferred dimension.
Mainly useful for creating 2d texture arrays – override dimension with
wgpu::TextureDimension::D2
on a texture with extent.depth > 1
in order to create a
texture array (/ cubemap / cubemap array) instead of a 3d texture.
sourcepub fn mip_level_count(self, count: u32) -> Self
pub fn mip_level_count(self, count: u32) -> Self
Specify the number of mip levels of the texture.
sourcepub fn sample_count(self, count: u32) -> Self
pub fn sample_count(self, count: u32) -> Self
Specify the number of samples per pixel in the case that the texture is multisampled.
sourcepub fn format(self, format: TextureFormat) -> Self
pub fn format(self, format: TextureFormat) -> Self
Specify the texture format.
sourcepub fn usage(self, usage: TextureUsages) -> Self
pub fn usage(self, usage: TextureUsages) -> Self
Describes to the implementation how the texture is to be used.
It is important that the set of usage bits reflects the
sourcepub fn build(self, device: &Device) -> Texture
pub fn build(self, device: &Device) -> Texture
Build the texture resulting from the specified parameters with the given device.
sourcepub fn into_descriptor(self) -> TextureDescriptor<'static>
pub fn into_descriptor(self) -> TextureDescriptor<'static>
Consumes the builder and returns the resulting wgpu::TextureDescriptor
.