pub struct DepthTexture { /* private fields */ }Expand description
A depth texture with Arc-wrapped view for cheap, lifetime-free sharing.
The depth view is wrapped in an Arc to eliminate lifetime coupling when
passing depth textures to render passes. This is safe because wgpu::TextureView
is internally just an ID, so the Arc overhead is minimal.
§Example
let mut depth = DepthTexture::new(device, 800, 600, DEFAULT_DEPTH_FORMAT);
// Cheap clone of the Arc
let depth_view = depth.view();
// Later, if window resizes:
if depth.needs_resize(new_width, new_height) {
depth.resize(device, new_width, new_height);
}Implementations§
Source§impl DepthTexture
impl DepthTexture
Sourcepub fn new(
device: &Device,
width: u32,
height: u32,
format: TextureFormat,
) -> Self
pub fn new( device: &Device, width: u32, height: u32, format: TextureFormat, ) -> Self
Create a new depth texture with the given dimensions and format.
Sourcepub fn with_label(
device: &Device,
width: u32,
height: u32,
format: TextureFormat,
label: &str,
) -> Self
pub fn with_label( device: &Device, width: u32, height: u32, format: TextureFormat, label: &str, ) -> Self
Create a new depth texture with a debug label.
Sourcepub fn resize(&mut self, device: &Device, width: u32, height: u32)
pub fn resize(&mut self, device: &Device, width: u32, height: u32)
Resize the depth texture if dimensions have changed.
This recreates the texture and view. The old Arc<TextureView> remains
valid until all references are dropped, but any render passes using it
should be completed before resize.
Sourcepub fn view(&self) -> Arc<TextureView>
pub fn view(&self) -> Arc<TextureView>
Get a cheap clone of the depth view.
The Arc wrapper allows the view to be shared without lifetime constraints, making it easy to pass to closures and render passes.
Sourcepub fn view_ref(&self) -> &TextureView
pub fn view_ref(&self) -> &TextureView
Get a reference to the depth view (for cases where Arc is not needed).
Sourcepub fn needs_resize(&self, width: u32, height: u32) -> bool
pub fn needs_resize(&self, width: u32, height: u32) -> bool
Check if the depth texture needs to be resized for the given dimensions.
Sourcepub fn format(&self) -> TextureFormat
pub fn format(&self) -> TextureFormat
Get the depth format.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DepthTexture
impl !RefUnwindSafe for DepthTexture
impl Send for DepthTexture
impl Sync for DepthTexture
impl Unpin for DepthTexture
impl UnsafeUnpin for DepthTexture
impl !UnwindSafe for DepthTexture
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> 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