wgpu/api/
texture_view.rs

1use crate::*;
2
3/// Handle to a texture view.
4///
5/// A `TextureView` object describes a texture and associated metadata needed by a
6/// [`RenderPipeline`] or [`BindGroup`].
7///
8/// Corresponds to [WebGPU `GPUTextureView`](https://gpuweb.github.io/gpuweb/#gputextureview).
9#[derive(Debug, Clone)]
10pub struct TextureView {
11    pub(crate) inner: dispatch::DispatchTextureView,
12}
13#[cfg(send_sync)]
14static_assertions::assert_impl_all!(TextureView: Send, Sync);
15
16crate::cmp::impl_eq_ord_hash_proxy!(TextureView => .inner);
17
18impl TextureView {
19    /// Returns the inner hal TextureView using a callback. The hal texture will be `None` if the
20    /// backend type argument does not match with this wgpu Texture
21    ///
22    /// # Safety
23    ///
24    /// - The raw handle obtained from the hal TextureView must not be manually destroyed
25    #[cfg(wgpu_core)]
26    pub unsafe fn as_hal<A: wgc::hal_api::HalApi, F: FnOnce(Option<&A::TextureView>) -> R, R>(
27        &self,
28        hal_texture_view_callback: F,
29    ) -> R {
30        if let Some(core_view) = self.inner.as_core_opt() {
31            unsafe {
32                core_view
33                    .context
34                    .texture_view_as_hal::<A, F, R>(core_view, hal_texture_view_callback)
35            }
36        } else {
37            hal_texture_view_callback(None)
38        }
39    }
40}
41
42/// Describes a [`TextureView`].
43///
44/// For use with [`Texture::create_view`].
45///
46/// Corresponds to [WebGPU `GPUTextureViewDescriptor`](
47/// https://gpuweb.github.io/gpuweb/#dictdef-gputextureviewdescriptor).
48pub type TextureViewDescriptor<'a> = wgt::TextureViewDescriptor<Label<'a>>;
49static_assertions::assert_impl_all!(TextureViewDescriptor<'_>: Send, Sync);