nvgx_wgpu/
fb.rs

1use nvgx::{Extent, FrameBufferDevice, ImageId, RenderFrameBufferDevice};
2
3use super::{texture::StencilTexture, Renderer};
4
5pub struct FrameBuffer {
6    stencil: StencilTexture,
7    image: ImageId,
8    width: u32,
9    height: u32,
10}
11
12impl FrameBufferDevice for FrameBuffer {
13    fn image(&self) -> ImageId {
14        return self.image;
15    }
16
17    fn size(&self) -> Extent {
18        Extent {
19            width: self.width as f32,
20            height: self.height as f32,
21        }
22    }
23}
24
25impl RenderFrameBufferDevice for Renderer {
26    type FB = FrameBuffer;
27
28    fn fb_format(&self) -> nvgx::TextureType {
29        return self.resources.config.format;
30    }
31
32    fn create_fb(&mut self, width: u32, height: u32, image: ImageId) -> anyhow::Result<Self::FB> {
33        let stencil = StencilTexture::new(&self.device, width, height);
34        Ok(FrameBuffer {
35            stencil,
36            image,
37            width,
38            height,
39        })
40    }
41
42    fn delete_fb(&mut self, _fb: Self::FB) -> anyhow::Result<()> {
43        Ok(())
44    }
45
46    fn bind(&mut self, fb: &Self::FB) -> anyhow::Result<()> {
47        self.target_fb = Some((fb.image(), fb.stencil.view.clone()));
48        Ok(())
49    }
50
51    fn unbind(&mut self) -> anyhow::Result<()> {
52        self.target_fb = None;
53        Ok(())
54    }
55}