vulkan-tutorial/src/lib.rs

60 lines
1.8 KiB
Rust
Raw Normal View History

2023-04-05 10:48:25 -04:00
mod app;
pub use app::App;
2023-04-05 13:04:20 -04:00
use ::anyhow::Result;
2023-04-07 11:20:48 -04:00
use ::vulkanalia::vk::DeviceV1_0;
use ::winit::dpi::LogicalSize;
use ::winit::event::{Event, WindowEvent};
use ::winit::event_loop::{ControlFlow, EventLoop};
use ::winit::window::WindowBuilder;
2023-04-05 10:48:25 -04:00
pub const VALIDATION_ENABLED: bool = cfg!(debug_assertions);
pub fn run() -> Result<()> {
// Window
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_title("Vulkan Tutorial (Rust)")
.with_inner_size(LogicalSize::new(1024, 768))
.build(&event_loop)?;
// App
let mut app = unsafe { App::create(&window)? };
let mut destroying = false;
2023-04-07 14:48:12 -04:00
let mut minimized = false;
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
// Render a frame if our Vulkan app is not being destroyed
2023-04-07 14:48:12 -04:00
Event::MainEventsCleared if !destroying && !minimized => {
unsafe { app.render(&window) }.unwrap()
}
// Let the app know it has been resized
Event::WindowEvent {
event: WindowEvent::Resized(size),
..
} => {
if size.width == 0 || size.height == 0 {
minimized = true;
} else {
minimized = false;
app.resized = true;
}
}
// Destroy our Vulkan app.
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => {
destroying = true;
*control_flow = ControlFlow::Exit;
unsafe {
2023-04-07 11:20:48 -04:00
app.device.device_wait_idle().unwrap();
app.destroy();
}
}
_ => {}
}
});
2023-04-05 10:48:25 -04:00
}