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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::ops::Range;
#[repr(C)]
#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
pub struct ViewProjection {
pub projection: [[f32; 4]; 4],
pub view: [[f32; 4]; 4],
}
pub struct Camera<'a> {
pub bindgroup: &'a wgpu::BindGroup,
}
#[derive(Clone)]
pub enum ObjectDraw<'a> {
Indexed {
index_buffer: wgpu::BufferSlice<'a>,
index_format: wgpu::IndexFormat,
index_range: Range<u32>,
base_vertex: i32,
},
Default {
vertex_range: Range<u32>,
},
}
pub fn conduct_clear_pass(
device: &wgpu::Device,
queue: &wgpu::Queue,
label: Option<&str>,
frame_view: &wgpu::TextureView,
depth_view: Option<&wgpu::TextureView>,
clear_color: wgpu::Color,
) {
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("renderling clear pass"),
});
let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: frame_view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(clear_color),
store: true,
},
})],
depth_stencil_attachment: depth_view.map(|view| wgpu::RenderPassDepthStencilAttachment {
view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: true,
}),
stencil_ops: None,
}),
});
queue.submit(std::iter::once(encoder.finish()));
}
pub struct UniformBuffer {
pub buffer: wgpu::Buffer,
pub bindgroup: wgpu::BindGroup,
}
pub struct VertexBuffer {
pub buffer: wgpu::Buffer,
pub len: usize,
}