-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathframebuffer.rs
More file actions
59 lines (53 loc) · 1.74 KB
/
framebuffer.rs
File metadata and controls
59 lines (53 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Provides a wgpu implementation of a backing buffer.
use wgpu::{Device, Sampler, Texture, TextureFormat, TextureView};
pub struct Framebuffer {
pub texture: Texture,
view: TextureView,
sampler: Sampler,
}
impl Framebuffer {
pub fn new(device: &Device, format: TextureFormat, width: u32, height: u32) -> Self {
let size = wgpu::Extent3d {
width,
height,
depth_or_array_layers: 1,
};
let texture = device.create_texture(&wgpu::TextureDescriptor {
label: None,
size,
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format,
usage: wgpu::TextureUsages::TEXTURE_BINDING
| wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::COPY_SRC,
});
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
address_mode_u: wgpu::AddressMode::Repeat,
address_mode_v: wgpu::AddressMode::Repeat,
address_mode_w: wgpu::AddressMode::Repeat,
mag_filter: wgpu::FilterMode::Nearest,
min_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Nearest,
lod_min_clamp: -100.0,
lod_max_clamp: 100.0,
compare: None,
label: None,
anisotropy_clamp: None,
..Default::default()
});
Self {
view,
sampler,
texture,
}
}
pub fn view(&self) -> &TextureView {
&self.view
}
pub fn sampler(&self) -> &Sampler {
&self.sampler
}
}