librashader_runtime_wgpu/
framebuffer.rs

1use crate::handle::Handle;
2use crate::texture::OwnedImage;
3use librashader_common::Size;
4use wgpu::TextureViewDescriptor;
5
6/// A wgpu `TextureView` with size and texture information to output.
7pub struct WgpuOutputView<'a> {
8    pub(crate) size: Size<u32>,
9    pub(crate) view: Handle<'a, wgpu::TextureView>,
10    pub(crate) format: wgpu::TextureFormat,
11}
12
13impl<'a> WgpuOutputView<'a> {
14    /// Create an output view from an existing texture view, size, and format.
15    pub fn new_from_raw(
16        view: &'a wgpu::TextureView,
17        size: Size<u32>,
18        format: wgpu::TextureFormat,
19    ) -> Self {
20        Self {
21            size,
22            view: Handle::Borrowed(&view),
23            format,
24        }
25    }
26}
27
28#[doc(hidden)]
29impl<'a> From<&'a OwnedImage> for WgpuOutputView<'a> {
30    fn from(image: &'a OwnedImage) -> Self {
31        Self {
32            size: image.size,
33            view: Handle::Borrowed(&image.view),
34            format: image.image.format(),
35        }
36    }
37}
38
39impl From<&wgpu::Texture> for WgpuOutputView<'static> {
40    fn from(image: &wgpu::Texture) -> Self {
41        Self {
42            size: image.size().into(),
43            view: Handle::Owned(image.create_view(&TextureViewDescriptor::default())),
44            format: image.format(),
45        }
46    }
47}