-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy path17_vertex_input.rs
689 lines (612 loc) · 24.7 KB
/
17_vertex_input.rs
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
use vulkan_tutorial_rust::{
utility, // the mod define some fixed functions that have been learned before.
utility::constants::*,
utility::debug::*,
utility::share,
utility::structures::*,
};
use ash::version::DeviceV1_0;
use ash::version::InstanceV1_0;
use ash::vk;
use memoffset::offset_of;
use winit::event::{Event, VirtualKeyCode, ElementState, KeyboardInput, WindowEvent};
use winit::event_loop::{EventLoop, ControlFlow};
use std::ffi::CString;
use std::ptr;
// Constants
const WINDOW_TITLE: &'static str = "17.Vertex Input";
#[repr(C)]
#[derive(Debug, Clone)]
struct Vertex {
pos: [f32; 2],
color: [f32; 3],
}
impl Vertex {
fn get_binding_descriptions() -> [vk::VertexInputBindingDescription; 1] {
[vk::VertexInputBindingDescription {
binding: 0,
stride: std::mem::size_of::<Self>() as u32,
input_rate: vk::VertexInputRate::VERTEX,
}]
}
fn get_attribute_descriptions() -> [vk::VertexInputAttributeDescription; 2] {
[
vk::VertexInputAttributeDescription {
location: 0,
binding: 0,
format: vk::Format::R32G32_SFLOAT,
offset: offset_of!(Self, pos) as u32,
},
vk::VertexInputAttributeDescription {
binding: 0,
location: 1,
format: vk::Format::R32G32B32_SFLOAT,
offset: offset_of!(Self, color) as u32,
},
]
}
}
const _VERTICES_DATA: [Vertex; 3] = [
Vertex {
pos: [0.0, -0.5],
color: [1.0, 0.0, 0.0],
},
Vertex {
pos: [0.5, 0.5],
color: [0.0, 1.0, 0.0],
},
Vertex {
pos: [-0.5, 0.5],
color: [0.0, 0.0, 1.0],
},
];
struct VulkanApp {
window: winit::window::Window,
// vulkan stuff
_entry: ash::Entry,
instance: ash::Instance,
surface_loader: ash::extensions::khr::Surface,
surface: vk::SurfaceKHR,
debug_utils_loader: ash::extensions::ext::DebugUtils,
debug_merssager: vk::DebugUtilsMessengerEXT,
physical_device: vk::PhysicalDevice,
device: ash::Device,
queue_family: QueueFamilyIndices,
graphics_queue: vk::Queue,
present_queue: vk::Queue,
swapchain_loader: ash::extensions::khr::Swapchain,
swapchain: vk::SwapchainKHR,
swapchain_images: Vec<vk::Image>,
swapchain_format: vk::Format,
swapchain_extent: vk::Extent2D,
swapchain_imageviews: Vec<vk::ImageView>,
swapchain_framebuffers: Vec<vk::Framebuffer>,
render_pass: vk::RenderPass,
pipeline_layout: vk::PipelineLayout,
graphics_pipeline: vk::Pipeline,
command_pool: vk::CommandPool,
command_buffers: Vec<vk::CommandBuffer>,
image_available_semaphores: Vec<vk::Semaphore>,
render_finished_semaphores: Vec<vk::Semaphore>,
in_flight_fences: Vec<vk::Fence>,
current_frame: usize,
is_framebuffer_resized: bool,
}
impl VulkanApp {
pub fn new(event_loop: &winit::event_loop::EventLoop<()>) -> VulkanApp {
let window = utility::window::init_window(event_loop, WINDOW_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT);
// init vulkan stuff
let entry = ash::Entry::new().unwrap();
let instance = share::create_instance(
&entry,
WINDOW_TITLE,
VALIDATION.is_enable,
&VALIDATION.required_validation_layers.to_vec(),
);
let surface_stuff =
share::create_surface(&entry, &instance, &window, WINDOW_WIDTH, WINDOW_HEIGHT);
let (debug_utils_loader, debug_merssager) =
setup_debug_utils(VALIDATION.is_enable, &entry, &instance);
let physical_device =
share::pick_physical_device(&instance, &surface_stuff, &DEVICE_EXTENSIONS);
let (device, queue_family) = share::create_logical_device(
&instance,
physical_device,
&VALIDATION,
&DEVICE_EXTENSIONS,
&surface_stuff,
);
let graphics_queue =
unsafe { device.get_device_queue(queue_family.graphics_family.unwrap(), 0) };
let present_queue =
unsafe { device.get_device_queue(queue_family.present_family.unwrap(), 0) };
let swapchain_stuff = share::create_swapchain(
&instance,
&device,
physical_device,
&window,
&surface_stuff,
&queue_family,
);
let swapchain_imageviews = share::v1::create_image_views(
&device,
swapchain_stuff.swapchain_format,
&swapchain_stuff.swapchain_images,
);
let render_pass = share::v1::create_render_pass(&device, swapchain_stuff.swapchain_format);
let (graphics_pipeline, pipeline_layout) = VulkanApp::create_graphics_pipeline(
&device,
render_pass,
swapchain_stuff.swapchain_extent,
);
let swapchain_framebuffers = share::v1::create_framebuffers(
&device,
render_pass,
&swapchain_imageviews,
swapchain_stuff.swapchain_extent,
);
let command_pool = share::v1::create_command_pool(&device, &queue_family);
let command_buffers = share::v1::create_command_buffers(
&device,
command_pool,
graphics_pipeline,
&swapchain_framebuffers,
render_pass,
swapchain_stuff.swapchain_extent,
);
let sync_ojbects = share::v1::create_sync_objects(&device, MAX_FRAMES_IN_FLIGHT);
// cleanup(); the 'drop' function will take care of it.
VulkanApp {
// winit stuff
window,
// vulkan stuff
_entry: entry,
instance,
surface: surface_stuff.surface,
surface_loader: surface_stuff.surface_loader,
debug_utils_loader,
debug_merssager,
physical_device,
device,
queue_family,
graphics_queue,
present_queue,
swapchain_loader: swapchain_stuff.swapchain_loader,
swapchain: swapchain_stuff.swapchain,
swapchain_format: swapchain_stuff.swapchain_format,
swapchain_images: swapchain_stuff.swapchain_images,
swapchain_extent: swapchain_stuff.swapchain_extent,
swapchain_imageviews,
swapchain_framebuffers,
pipeline_layout,
render_pass,
graphics_pipeline,
command_pool,
command_buffers,
image_available_semaphores: sync_ojbects.image_available_semaphores,
render_finished_semaphores: sync_ojbects.render_finished_semaphores,
in_flight_fences: sync_ojbects.inflight_fences,
current_frame: 0,
is_framebuffer_resized: false,
}
}
fn create_graphics_pipeline(
device: &ash::Device,
render_pass: vk::RenderPass,
swapchain_extent: vk::Extent2D,
) -> (vk::Pipeline, vk::PipelineLayout) {
let vert_shader_module = share::create_shader_module(
device,
include_bytes!("../../shaders/spv/17-shader-vertexbuffer.vert.spv").to_vec(),
);
let frag_shader_module = share::create_shader_module(
device,
include_bytes!("../../shaders/spv/17-shader-vertexbuffer.frag.spv").to_vec(),
);
let main_function_name = CString::new("main").unwrap(); // the beginning function name in shader code.
let shader_stages = [
vk::PipelineShaderStageCreateInfo {
// Vertex Shader
s_type: vk::StructureType::PIPELINE_SHADER_STAGE_CREATE_INFO,
p_next: ptr::null(),
flags: vk::PipelineShaderStageCreateFlags::empty(),
module: vert_shader_module,
p_name: main_function_name.as_ptr(),
p_specialization_info: ptr::null(),
stage: vk::ShaderStageFlags::VERTEX,
},
vk::PipelineShaderStageCreateInfo {
// Fragment Shader
s_type: vk::StructureType::PIPELINE_SHADER_STAGE_CREATE_INFO,
p_next: ptr::null(),
flags: vk::PipelineShaderStageCreateFlags::empty(),
module: frag_shader_module,
p_name: main_function_name.as_ptr(),
p_specialization_info: ptr::null(),
stage: vk::ShaderStageFlags::FRAGMENT,
},
];
let binding_description = Vertex::get_binding_descriptions();
let attribute_description = Vertex::get_attribute_descriptions();
let vertex_input_state_create_info = vk::PipelineVertexInputStateCreateInfo {
s_type: vk::StructureType::PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
p_next: ptr::null(),
flags: vk::PipelineVertexInputStateCreateFlags::empty(),
vertex_attribute_description_count: attribute_description.len() as u32,
p_vertex_attribute_descriptions: attribute_description.as_ptr(),
vertex_binding_description_count: binding_description.len() as u32,
p_vertex_binding_descriptions: binding_description.as_ptr(),
};
let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo {
s_type: vk::StructureType::PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
flags: vk::PipelineInputAssemblyStateCreateFlags::empty(),
p_next: ptr::null(),
primitive_restart_enable: vk::FALSE,
topology: vk::PrimitiveTopology::TRIANGLE_LIST,
};
let viewports = [vk::Viewport {
x: 0.0,
y: 0.0,
width: swapchain_extent.width as f32,
height: swapchain_extent.height as f32,
min_depth: 0.0,
max_depth: 1.0,
}];
let scissors = [vk::Rect2D {
offset: vk::Offset2D { x: 0, y: 0 },
extent: swapchain_extent,
}];
let viewport_state_create_info = vk::PipelineViewportStateCreateInfo {
s_type: vk::StructureType::PIPELINE_VIEWPORT_STATE_CREATE_INFO,
p_next: ptr::null(),
flags: vk::PipelineViewportStateCreateFlags::empty(),
scissor_count: scissors.len() as u32,
p_scissors: scissors.as_ptr(),
viewport_count: viewports.len() as u32,
p_viewports: viewports.as_ptr(),
};
let rasterization_statue_create_info = vk::PipelineRasterizationStateCreateInfo {
s_type: vk::StructureType::PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
p_next: ptr::null(),
flags: vk::PipelineRasterizationStateCreateFlags::empty(),
depth_clamp_enable: vk::FALSE,
cull_mode: vk::CullModeFlags::BACK,
front_face: vk::FrontFace::CLOCKWISE,
line_width: 1.0,
polygon_mode: vk::PolygonMode::FILL,
rasterizer_discard_enable: vk::FALSE,
depth_bias_clamp: 0.0,
depth_bias_constant_factor: 0.0,
depth_bias_enable: vk::FALSE,
depth_bias_slope_factor: 0.0,
};
let multisample_state_create_info = vk::PipelineMultisampleStateCreateInfo {
s_type: vk::StructureType::PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
flags: vk::PipelineMultisampleStateCreateFlags::empty(),
p_next: ptr::null(),
rasterization_samples: vk::SampleCountFlags::TYPE_1,
sample_shading_enable: vk::FALSE,
min_sample_shading: 0.0,
p_sample_mask: ptr::null(),
alpha_to_one_enable: vk::FALSE,
alpha_to_coverage_enable: vk::FALSE,
};
let stencil_state = vk::StencilOpState {
fail_op: vk::StencilOp::KEEP,
pass_op: vk::StencilOp::KEEP,
depth_fail_op: vk::StencilOp::KEEP,
compare_op: vk::CompareOp::ALWAYS,
compare_mask: 0,
write_mask: 0,
reference: 0,
};
let depth_state_create_info = vk::PipelineDepthStencilStateCreateInfo {
s_type: vk::StructureType::PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
p_next: ptr::null(),
flags: vk::PipelineDepthStencilStateCreateFlags::empty(),
depth_test_enable: vk::FALSE,
depth_write_enable: vk::FALSE,
depth_compare_op: vk::CompareOp::LESS_OR_EQUAL,
depth_bounds_test_enable: vk::FALSE,
stencil_test_enable: vk::FALSE,
front: stencil_state,
back: stencil_state,
max_depth_bounds: 1.0,
min_depth_bounds: 0.0,
};
let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState {
blend_enable: vk::FALSE,
color_write_mask: vk::ColorComponentFlags::all(),
src_color_blend_factor: vk::BlendFactor::ONE,
dst_color_blend_factor: vk::BlendFactor::ZERO,
color_blend_op: vk::BlendOp::ADD,
src_alpha_blend_factor: vk::BlendFactor::ONE,
dst_alpha_blend_factor: vk::BlendFactor::ZERO,
alpha_blend_op: vk::BlendOp::ADD,
}];
let color_blend_state = vk::PipelineColorBlendStateCreateInfo {
s_type: vk::StructureType::PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
p_next: ptr::null(),
flags: vk::PipelineColorBlendStateCreateFlags::empty(),
logic_op_enable: vk::FALSE,
logic_op: vk::LogicOp::COPY,
attachment_count: color_blend_attachment_states.len() as u32,
p_attachments: color_blend_attachment_states.as_ptr(),
blend_constants: [0.0, 0.0, 0.0, 0.0],
};
let pipeline_layout_create_info = vk::PipelineLayoutCreateInfo {
s_type: vk::StructureType::PIPELINE_LAYOUT_CREATE_INFO,
p_next: ptr::null(),
flags: vk::PipelineLayoutCreateFlags::empty(),
set_layout_count: 0,
p_set_layouts: ptr::null(),
push_constant_range_count: 0,
p_push_constant_ranges: ptr::null(),
};
let pipeline_layout = unsafe {
device
.create_pipeline_layout(&pipeline_layout_create_info, None)
.expect("Failed to create pipeline layout!")
};
let graphic_pipeline_create_infos = [vk::GraphicsPipelineCreateInfo {
s_type: vk::StructureType::GRAPHICS_PIPELINE_CREATE_INFO,
p_next: ptr::null(),
flags: vk::PipelineCreateFlags::empty(),
stage_count: shader_stages.len() as u32,
p_stages: shader_stages.as_ptr(),
p_vertex_input_state: &vertex_input_state_create_info,
p_input_assembly_state: &vertex_input_assembly_state_info,
p_tessellation_state: ptr::null(),
p_viewport_state: &viewport_state_create_info,
p_rasterization_state: &rasterization_statue_create_info,
p_multisample_state: &multisample_state_create_info,
p_depth_stencil_state: &depth_state_create_info,
p_color_blend_state: &color_blend_state,
p_dynamic_state: ptr::null(),
layout: pipeline_layout,
render_pass,
subpass: 0,
base_pipeline_handle: vk::Pipeline::null(),
base_pipeline_index: -1,
}];
let graphics_pipelines = unsafe {
device
.create_graphics_pipelines(
vk::PipelineCache::null(),
&graphic_pipeline_create_infos,
None,
)
.expect("Failed to create Graphics Pipeline!.")
};
unsafe {
device.destroy_shader_module(vert_shader_module, None);
device.destroy_shader_module(frag_shader_module, None);
}
(graphics_pipelines[0], pipeline_layout)
}
}
// Fix content -------------------------------------------------------------------------------
impl VulkanApp {
fn draw_frame(&mut self) {
let wait_fences = [self.in_flight_fences[self.current_frame]];
unsafe {
self.device
.wait_for_fences(&wait_fences, true, std::u64::MAX)
.expect("Failed to wait for Fence!");
}
let (image_index, _is_sub_optimal) = unsafe {
let result = self.swapchain_loader.acquire_next_image(
self.swapchain,
std::u64::MAX,
self.image_available_semaphores[self.current_frame],
vk::Fence::null(),
);
match result {
Ok(image_index) => image_index,
Err(vk_result) => match vk_result {
vk::Result::ERROR_OUT_OF_DATE_KHR => {
self.recreate_swapchain();
return;
}
_ => panic!("Failed to acquire Swap Chain Image!"),
},
}
};
let wait_semaphores = [self.image_available_semaphores[self.current_frame]];
let wait_stages = [vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT];
let signal_semaphores = [self.render_finished_semaphores[self.current_frame]];
let submit_infos = [vk::SubmitInfo {
s_type: vk::StructureType::SUBMIT_INFO,
p_next: ptr::null(),
wait_semaphore_count: wait_semaphores.len() as u32,
p_wait_semaphores: wait_semaphores.as_ptr(),
p_wait_dst_stage_mask: wait_stages.as_ptr(),
command_buffer_count: 1,
p_command_buffers: &self.command_buffers[image_index as usize],
signal_semaphore_count: signal_semaphores.len() as u32,
p_signal_semaphores: signal_semaphores.as_ptr(),
}];
unsafe {
self.device
.reset_fences(&wait_fences)
.expect("Failed to reset Fence!");
self.device
.queue_submit(
self.graphics_queue,
&submit_infos,
self.in_flight_fences[self.current_frame],
)
.expect("Failed to execute queue submit.");
}
let swapchains = [self.swapchain];
let present_info = vk::PresentInfoKHR {
s_type: vk::StructureType::PRESENT_INFO_KHR,
p_next: ptr::null(),
wait_semaphore_count: 1,
p_wait_semaphores: signal_semaphores.as_ptr(),
swapchain_count: 1,
p_swapchains: swapchains.as_ptr(),
p_image_indices: &image_index,
p_results: ptr::null_mut(),
};
let result = unsafe {
self.swapchain_loader
.queue_present(self.present_queue, &present_info)
};
let is_resized = match result {
Ok(_) => self.is_framebuffer_resized,
Err(vk_result) => match vk_result {
vk::Result::ERROR_OUT_OF_DATE_KHR | vk::Result::SUBOPTIMAL_KHR => true,
_ => panic!("Failed to execute queue present."),
},
};
if is_resized {
self.is_framebuffer_resized = false;
self.recreate_swapchain();
}
self.current_frame = (self.current_frame + 1) % MAX_FRAMES_IN_FLIGHT;
}
fn recreate_swapchain(&mut self) {
// parameters -------------
let surface_suff = SurfaceStuff {
surface_loader: self.surface_loader.clone(),
surface: self.surface,
screen_width: WINDOW_WIDTH,
screen_height: WINDOW_HEIGHT,
};
// ------------------------
unsafe {
self.device
.device_wait_idle()
.expect("Failed to wait device idle!")
};
self.cleanup_swapchain();
let swapchain_stuff = share::create_swapchain(
&self.instance,
&self.device,
self.physical_device,
&self.window,
&surface_suff,
&self.queue_family,
);
self.swapchain_loader = swapchain_stuff.swapchain_loader;
self.swapchain = swapchain_stuff.swapchain;
self.swapchain_images = swapchain_stuff.swapchain_images;
self.swapchain_format = swapchain_stuff.swapchain_format;
self.swapchain_extent = swapchain_stuff.swapchain_extent;
self.swapchain_imageviews = share::v1::create_image_views(
&self.device,
self.swapchain_format,
&self.swapchain_images,
);
self.render_pass = share::v1::create_render_pass(&self.device, self.swapchain_format);
let (graphics_pipeline, pipeline_layout) = VulkanApp::create_graphics_pipeline(
&self.device,
self.render_pass,
swapchain_stuff.swapchain_extent,
);
self.graphics_pipeline = graphics_pipeline;
self.pipeline_layout = pipeline_layout;
self.swapchain_framebuffers = share::v1::create_framebuffers(
&self.device,
self.render_pass,
&self.swapchain_imageviews,
self.swapchain_extent,
);
self.command_buffers = share::v1::create_command_buffers(
&self.device,
self.command_pool,
self.graphics_pipeline,
&self.swapchain_framebuffers,
self.render_pass,
self.swapchain_extent,
);
}
fn cleanup_swapchain(&self) {
unsafe {
self.device
.free_command_buffers(self.command_pool, &self.command_buffers);
for &framebuffer in self.swapchain_framebuffers.iter() {
self.device.destroy_framebuffer(framebuffer, None);
}
self.device.destroy_pipeline(self.graphics_pipeline, None);
self.device
.destroy_pipeline_layout(self.pipeline_layout, None);
self.device.destroy_render_pass(self.render_pass, None);
for &image_view in self.swapchain_imageviews.iter() {
self.device.destroy_image_view(image_view, None);
}
self.swapchain_loader
.destroy_swapchain(self.swapchain, None);
}
}
}
impl Drop for VulkanApp {
fn drop(&mut self) {
unsafe {
for i in 0..MAX_FRAMES_IN_FLIGHT {
self.device
.destroy_semaphore(self.image_available_semaphores[i], None);
self.device
.destroy_semaphore(self.render_finished_semaphores[i], None);
self.device.destroy_fence(self.in_flight_fences[i], None);
}
self.cleanup_swapchain();
self.device.destroy_command_pool(self.command_pool, None);
self.device.destroy_device(None);
self.surface_loader.destroy_surface(self.surface, None);
if VALIDATION.is_enable {
self.debug_utils_loader
.destroy_debug_utils_messenger(self.debug_merssager, None);
}
self.instance.destroy_instance(None);
}
}
}
impl VulkanApp {
pub fn main_loop(mut self, event_loop: EventLoop<()>) {
event_loop.run(move |event, _, control_flow| {
match event {
| Event::WindowEvent { event, .. } => {
match event {
| WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit
},
| WindowEvent::KeyboardInput { input, .. } => {
match input {
| KeyboardInput { virtual_keycode, state, .. } => {
match (virtual_keycode, state) {
| (Some(VirtualKeyCode::Escape), ElementState::Pressed) => {
*control_flow = ControlFlow::Exit
},
| _ => {},
}
},
}
},
| _ => {},
}
},
| Event::MainEventsCleared => {
self.window.request_redraw();
},
| Event::RedrawRequested(_window_id) => {
self.draw_frame();
},
| Event::LoopDestroyed => {
unsafe {
self.device.device_wait_idle()
.expect("Failed to wait device idle!")
};
},
_ => (),
}
})
}
}
fn main() {
let event_loop = EventLoop::new();
let vulkan_app = VulkanApp::new(&event_loop);
vulkan_app.main_loop(event_loop);
}
// -------------------------------------------------------------------------------------------