forked from bwasty/vulkan-tutorial-rs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
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
@@ -37,6 +37,7 @@ use vulkano::sync::SharingMode;
use vulkano::pipeline::{
GraphicsPipeline,
vertex::BufferlessDefinition,
+ vertex::BufferlessVertices,
viewport::Viewport,
};
use vulkano::framebuffer::{
@@ -46,6 +47,11 @@ use vulkano::framebuffer::{
Framebuffer,
};
use vulkano::descriptor::PipelineLayoutAbstract;
+use vulkano::command_buffer::{
+ AutoCommandBuffer,
+ AutoCommandBufferBuilder,
+ DynamicState,
+};
const WIDTH: u32 = 800;
const HEIGHT: u32 = 600;
@@ -108,6 +114,8 @@ struct HelloTriangleApplication {
graphics_pipeline: Arc<ConcreteGraphicsPipeline>,
swap_chain_framebuffers: Vec<Arc<FramebufferAbstract + Send + Sync>>,
+
+ command_buffers: Vec<Arc<AutoCommandBuffer>>,
}
impl HelloTriangleApplication {
@@ -128,7 +136,7 @@ impl HelloTriangleApplication {
let swap_chain_framebuffers = Self::create_framebuffers(&swap_chain_images, &render_pass);
- Self {
+ let mut app = Self {
instance,
debug_callback,
@@ -148,7 +156,12 @@ impl HelloTriangleApplication {
graphics_pipeline,
swap_chain_framebuffers,
- }
+
+ command_buffers: vec![],
+ };
+
+ app.create_command_buffers();
+ app
}
fn create_instance() -> Arc<Instance> {
@@ -410,6 +423,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?