Skip to main content

gcrecomp_runtime/graphics/
framebuffer.rs

1// Frame buffer management
2use anyhow::Result;
3use wgpu::*;
4
5pub struct FrameBuffer {
6    texture: Texture,
7    view: TextureView,
8    width: u32,
9    height: u32,
10}
11
12impl FrameBuffer {
13    pub fn new(device: &Device, width: u32, height: u32, format: TextureFormat) -> Result<Self> {
14        let texture = device.create_texture(&TextureDescriptor {
15            label: Some("FrameBuffer"),
16            size: Extent3d {
17                width,
18                height,
19                depth_or_array_layers: 1,
20            },
21            mip_level_count: 1,
22            sample_count: 1,
23            dimension: TextureDimension::D2,
24            format,
25            usage: TextureUsages::RENDER_ATTACHMENT | TextureUsages::TEXTURE_BINDING,
26            view_formats: &[],
27        });
28
29        let view = texture.create_view(&TextureViewDescriptor::default());
30
31        Ok(Self {
32            texture,
33            view,
34            width,
35            height,
36        })
37    }
38
39    pub fn view(&self) -> &TextureView {
40        &self.view
41    }
42
43    pub fn texture(&self) -> &Texture {
44        &self.texture
45    }
46
47    pub fn width(&self) -> u32 {
48        self.width
49    }
50
51    pub fn height(&self) -> u32 {
52        self.height
53    }
54}