2024-02-06 17:45:31 +11:00
|
|
|
use crate::handle::Handle;
|
2024-02-02 16:51:17 +11:00
|
|
|
use crate::texture::OwnedImage;
|
2024-02-06 16:29:45 +11:00
|
|
|
use librashader_common::Size;
|
2024-02-06 17:45:31 +11:00
|
|
|
use wgpu::TextureViewDescriptor;
|
2023-12-16 22:28:41 +11:00
|
|
|
|
2024-02-07 10:42:32 +11:00
|
|
|
/// A wgpu `TextureView` with size and texture information to output.
|
2024-02-07 10:47:05 +11:00
|
|
|
pub struct WgpuOutputView<'a> {
|
2024-02-06 17:45:31 +11:00
|
|
|
pub(crate) size: Size<u32>,
|
|
|
|
pub(crate) view: Handle<'a, wgpu::TextureView>,
|
|
|
|
pub(crate) format: wgpu::TextureFormat,
|
2024-02-02 16:51:17 +11:00
|
|
|
}
|
|
|
|
|
2024-02-07 10:47:05 +11:00
|
|
|
impl<'a> WgpuOutputView<'a> {
|
|
|
|
/// Create an output view from an existing texture view, size, and format.
|
2024-02-06 17:45:31 +11:00
|
|
|
pub fn new_from_raw(
|
|
|
|
view: &'a wgpu::TextureView,
|
|
|
|
size: Size<u32>,
|
|
|
|
format: wgpu::TextureFormat,
|
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
size,
|
|
|
|
view: Handle::Borrowed(&view),
|
|
|
|
format,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-07 10:47:05 +11:00
|
|
|
#[doc(hidden)]
|
|
|
|
impl<'a> From<&'a OwnedImage> for WgpuOutputView<'a> {
|
2024-02-06 17:45:31 +11:00
|
|
|
fn from(image: &'a OwnedImage) -> Self {
|
2024-02-02 16:51:17 +11:00
|
|
|
Self {
|
|
|
|
size: image.size,
|
2024-02-06 17:45:31 +11:00
|
|
|
view: Handle::Borrowed(&image.view),
|
2024-02-06 16:29:45 +11:00
|
|
|
format: image.image.format(),
|
2024-02-02 16:51:17 +11:00
|
|
|
}
|
|
|
|
}
|
2024-02-06 16:29:45 +11:00
|
|
|
}
|
2024-02-06 17:45:31 +11:00
|
|
|
|
2024-02-07 10:47:05 +11:00
|
|
|
impl From<&wgpu::Texture> for WgpuOutputView<'static> {
|
2024-02-06 17:45:31 +11:00
|
|
|
fn from(image: &wgpu::Texture) -> Self {
|
|
|
|
Self {
|
|
|
|
size: image.size().into(),
|
|
|
|
view: Handle::Owned(image.create_view(&TextureViewDescriptor::default())),
|
|
|
|
format: image.format(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|