simple_wgpu/
render_texture.rs

1/// A texture that can be used as a render pass attachment
2#[derive(Clone, Debug)]
3pub struct RenderTexture {
4    pub(crate) view: wgpu::TextureView,
5    pub(crate) format: wgpu::TextureFormat,
6}
7
8impl RenderTexture {
9    /// Create a render texture from a [wgpu::SurfaceTexture]
10    ///
11    /// This is primarily used to associate the swapchain image with a render pass
12    pub fn from_surface_texture(surface_texture: &wgpu::SurfaceTexture) -> Self {
13        Self {
14            view: surface_texture
15                .texture
16                .create_view(&wgpu::TextureViewDescriptor::default()),
17
18            format: surface_texture.texture.format(),
19        }
20    }
21
22    /// Create a render texture from a [wgpu::TextureView]
23    pub fn from_texture_view(
24        texture_view: &wgpu::TextureView,
25        format: &wgpu::TextureFormat,
26    ) -> Self {
27        Self {
28            view: texture_view.clone(),
29            format: *format,
30        }
31    }
32}