pub struct Texture {
pub texture: Texture,
pub view: TextureView,
pub sampler: Option<Sampler>,
}Expand description
A GPU texture with a view and optional sampler.
Wraps WGPU texture objects along with associated views and samplers.
Textures are used for color maps, normal maps, depth, and other data
bound to shaders. Typically created via from_bytes or
via create_depth_texture.
Fields§
§texture: Texture§view: TextureView§sampler: Option<Sampler>Implementations§
Source§impl Texture
impl Texture
Sourcepub const DEPTH_FORMAT: TextureFormat = wgpu::TextureFormat::Depth32Float
pub const DEPTH_FORMAT: TextureFormat = wgpu::TextureFormat::Depth32Float
Standard depth buffer texture format (32-bit float).
Sourcepub fn create_msaa_texture(
device: &Device,
config: &SurfaceConfiguration,
sample_count: u32,
) -> TextureView
pub fn create_msaa_texture( device: &Device, config: &SurfaceConfiguration, sample_count: u32, ) -> TextureView
Create a depth texture for depth-testing during rendering.
Depth textures are required for proper depth-testing to determine which objects
are in front of others. The returned texture is suitable for use as a
RENDER_ATTACHMENT in render passes.
§Arguments
sizeis [width, height] of the texture in pixelslabelis used as a debug label for the GPU resource
pub fn create_depth_texture( device: &Device, size: [u32; 2], label: &str, sample_count: u32, ) -> Self
Sourcepub fn create_default_normal_map(
width: u32,
height: u32,
device: &Device,
queue: &Queue,
) -> Texture
pub fn create_default_normal_map( width: u32, height: u32, device: &Device, queue: &Queue, ) -> Texture
Create a default normal map (neutral blue, representing no deformation).
Returns a solid blue texture suitable as a default when no normal map is provided. This avoids the need to change shaders when normal maps are optional.
Sourcepub fn from_bytes(
device: &Device,
queue: &Queue,
bytes: &[u8],
label: &str,
format: Option<&str>,
is_normal_map: bool,
) -> Result<Self>
pub fn from_bytes( device: &Device, queue: &Queue, bytes: &[u8], label: &str, format: Option<&str>, is_normal_map: bool, ) -> Result<Self>
Load a texture from raw byte data (image file contents).
§Arguments
bytesrepresent raw image file data (PNG, JPEG, etc.)labelis used as a debug name for the GPU resourceformatis an optional file format hint (e.g., “png”). If None, auto-detect.is_normal_maptoggles between sRGB (false) and linear (true) color space
Sourcepub fn from_color(rgba: [u8; 4], device: &Device, queue: &Queue) -> Texture
pub fn from_color(rgba: [u8; 4], device: &Device, queue: &Queue) -> Texture
Create a 1×1 solid-colour texture from a raw RGBA byte array.
pub fn from_image( device: &Device, queue: &Queue, img: &DynamicImage, label: Option<&str>, is_normal_map: bool, ) -> Result<Self>
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 UnsafeUnpin 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,
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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