-
Notifications
You must be signed in to change notification settings - Fork 47
/
14_command_buffers.rs.diff
81 lines (72 loc) · 2.54 KB
/
14_command_buffers.rs.diff
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
81
--- a/13_framebuffers.rs
+++ b/14_command_buffers.rs
@@ -34,6 +34,7 @@ use vulkano::sync::SharingMode;
use vulkano::pipeline::{
GraphicsPipeline,
vertex::BufferlessDefinition,
+ vertex::BufferlessVertices,
viewport::Viewport,
};
use vulkano::framebuffer::{
@@ -43,6 +44,11 @@ use vulkano::framebuffer::{
Framebuffer,
};
use vulkano::descriptor::PipelineLayoutAbstract;
+use vulkano::command_buffer::{
+ AutoCommandBuffer,
+ AutoCommandBufferBuilder,
+ DynamicState,
+};
const WIDTH: u32 = 800;
const HEIGHT: u32 = 600;
@@ -105,6 +111,8 @@ struct HelloTriangleApplication {
graphics_pipeline: Arc<ConcreteGraphicsPipeline>,
swap_chain_framebuffers: Vec<Arc<FramebufferAbstract + Send + Sync>>,
+
+ command_buffers: Vec<Arc<AutoCommandBuffer>>,
}
impl HelloTriangleApplication {
@@ -125,7 +133,7 @@ impl HelloTriangleApplication {
let swap_chain_framebuffers = Self::create_framebuffers(&swap_chain_images, &render_pass);
- Self {
+ let mut app = Self {
instance,
debug_callback,
@@ -145,7 +153,12 @@ impl HelloTriangleApplication {
graphics_pipeline,
swap_chain_framebuffers,
- }
+
+ command_buffers: vec![],
+ };
+
+ app.create_command_buffers();
+ app
}
fn create_instance() -> Arc<Instance> {
@@ -405,6 +418,26 @@ impl HelloTriangleApplication {
).collect::<Vec<_>>()
}
+ fn create_command_buffers(&mut self) {
+ let queue_family = self.graphics_queue.family();
+ self.command_buffers = self.swap_chain_framebuffers.iter()
+ .map(|framebuffer| {
+ let vertices = BufferlessVertices { vertices: 3, instances: 1 };
+ Arc::new(AutoCommandBufferBuilder::primary_simultaneous_use(self.device.clone(), queue_family)
+ .unwrap()
+ .begin_render_pass(framebuffer.clone(), false, vec![[0.0, 0.0, 0.0, 1.0].into()])
+ .unwrap()
+ .draw(self.graphics_pipeline.clone(), &DynamicState::none(),
+ vertices, (), ())
+ .unwrap()
+ .end_render_pass()
+ .unwrap()
+ .build()
+ .unwrap())
+ })
+ .collect();
+ }
+
fn find_queue_families(surface: &Arc<Surface<Window>>, device: &PhysicalDevice) -> QueueFamilyIndices {
let mut indices = QueueFamilyIndices::new();
// TODO: replace index with id to simplify?