librashader/librashader-runtime-wgpu/src/framebuffer.rs

46 lines
1.1 KiB
Rust
Raw Normal View History

2024-02-06 17:45:31 +11:00
use crate::handle::Handle;
use crate::texture::OwnedImage;
use librashader_common::Size;
2024-02-06 17:45:31 +11:00
use wgpu::TextureViewDescriptor;
2024-02-07 10:42:32 +11:00
/// A wgpu `TextureView` with size and texture information to output.
pub struct OutputView<'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,
}
impl<'a> OutputView<'a> {
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,
}
}
}
impl<'a> From<&'a OwnedImage> for OutputView<'a> {
fn from(image: &'a OwnedImage) -> Self {
Self {
size: image.size,
2024-02-06 17:45:31 +11:00
view: Handle::Borrowed(&image.view),
format: image.image.format(),
}
}
}
2024-02-06 17:45:31 +11:00
impl From<&wgpu::Texture> for OutputView<'static> {
fn from(image: &wgpu::Texture) -> Self {
Self {
size: image.size().into(),
view: Handle::Owned(image.create_view(&TextureViewDescriptor::default())),
format: image.format(),
}
}
}