From 3b30169bf0c50a4c4dbf348a1e0a866c5fa2f081 Mon Sep 17 00:00:00 2001 From: Ivan Kalinin Date: Wed, 6 Dec 2023 20:57:36 +0100 Subject: [PATCH 1/3] Update winit dependency to 0.29 (#242) --- examples/Cargo.toml | 4 +- examples/src/bin/triangle.rs | 3 +- examples/src/lib.rs | 37 +++++----- tutorial/Cargo.toml | 10 ++- tutorial/book/preprocessor/Cargo.toml | 2 +- tutorial/book/src/development_environment.md | 6 +- .../src/dynamic/secondary_command_buffers.md | 16 +++-- tutorial/book/src/setup/base_code.md | 31 +++++---- tutorial/book/src/swapchain/recreation.md | 27 ++++---- tutorial/src/00_base_code.rs | 30 +++++---- tutorial/src/01_instance_creation.rs | 30 +++++---- tutorial/src/02_validation_layers.rs | 30 +++++---- tutorial/src/03_physical_device_selection.rs | 30 +++++---- tutorial/src/04_logical_device.rs | 30 +++++---- tutorial/src/05_window_surface.rs | 30 +++++---- tutorial/src/06_swapchain_creation.rs | 30 +++++---- tutorial/src/07_image_views.rs | 30 +++++---- tutorial/src/08_graphics_pipeline.rs | 30 +++++---- tutorial/src/09_shader_modules.rs | 30 +++++---- tutorial/src/10_fixed_functions.rs | 30 +++++---- tutorial/src/11_render_passes.rs | 30 +++++---- tutorial/src/12_graphics_pipeline_complete.rs | 30 +++++---- tutorial/src/13_framebuffers.rs | 30 +++++---- tutorial/src/14_command_buffers.rs | 30 +++++---- tutorial/src/15_hello_triangle.rs | 30 +++++---- tutorial/src/16_swapchain_recreation.rs | 48 +++++++------ tutorial/src/17_vertex_input.rs | 48 +++++++------ tutorial/src/18_vertex_buffer.rs | 48 +++++++------ tutorial/src/19_staging_buffer.rs | 48 +++++++------ tutorial/src/20_index_buffer.rs | 48 +++++++------ tutorial/src/21_descriptor_set_layout.rs | 48 +++++++------ tutorial/src/22_descriptor_sets.rs | 48 +++++++------ tutorial/src/23_texture_image.rs | 48 +++++++------ tutorial/src/24_sampler.rs | 48 +++++++------ tutorial/src/25_texture_mapping.rs | 48 +++++++------ tutorial/src/26_depth_buffering.rs | 48 +++++++------ tutorial/src/27_model_loading.rs | 48 +++++++------ tutorial/src/28_mipmapping.rs | 48 +++++++------ tutorial/src/29_multisampling.rs | 48 +++++++------ tutorial/src/30_push_constants.rs | 48 +++++++------ tutorial/src/31_recycling_command_buffers.rs | 48 +++++++------ tutorial/src/32_secondary_command_buffers.rs | 67 ++++++++++--------- vulkanalia/Cargo.toml | 4 +- vulkanalia/src/window.rs | 60 ++++++++++------- 44 files changed, 856 insertions(+), 659 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 58b281ef..0311bed0 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -19,7 +19,7 @@ description = "Examples." anyhow = "1" log = "0.4" cgmath = "0.18" -pretty_env_logger = "0.4" +pretty_env_logger = "0.5" thiserror = "1" vulkanalia = { path = "../vulkanalia", features = ["libloading", "provisional", "window"] } -winit = "0.28.1" +winit = "0.29.1" diff --git a/examples/src/bin/triangle.rs b/examples/src/bin/triangle.rs index 7221e16e..72f5b691 100644 --- a/examples/src/bin/triangle.rs +++ b/examples/src/bin/triangle.rs @@ -16,7 +16,8 @@ static VERTICES: [Vertex; 3] = [ ]; fn main() -> Result<()> { - unsafe { App::new("Triangle", TriangleExample::default())?.run() } + unsafe { App::new("Triangle", TriangleExample::default())?.run()? }; + Ok(()) } #[derive(Copy, Clone, Debug, Default)] diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 1157b6c3..66f54908 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -19,8 +19,9 @@ use vulkanalia::prelude::v1_0::*; use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; +use winit::error::EventLoopError; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vk::{KhrSurfaceExtension, KhrSwapchainExtension}; @@ -67,7 +68,7 @@ impl App { pretty_env_logger::init(); info!("Starting app."); - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title(title) .with_inner_size(LogicalSize::new(800, 600)) @@ -112,25 +113,27 @@ impl App { /// Starts the rendering loop for this app. #[rustfmt::skip] - pub unsafe fn run(mut self) -> ! { - let mut destroying = false; - self.event_loop.take().unwrap().run(move |event, _, flow| { - *flow = ControlFlow::Poll; + pub unsafe fn run(mut self) -> Result<(), EventLoopError> { + self.event_loop.take().unwrap().run(move |event, elwt| { match event { - // Render a frame for this app. - Event::MainEventsCleared if !destroying => self.render().unwrap(), - // Recreate the swapchain on next render. - Event::WindowEvent { event: WindowEvent::Resized(_), .. } => self.resized = true, - // Destroy this app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - *flow = ControlFlow::Exit; - destroying = true; - self.device.device_wait_idle().unwrap(); - self.destroy(); + // Request a redraw when all events were processed. + Event::AboutToWait => self.window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame for this app. + WindowEvent::RedrawRequested if !elwt.exiting() => self.render().unwrap(), + // Recreate the swapchain on next render. + WindowEvent::Resized(_) => self.resized = true, + // Destroy this app. + WindowEvent::CloseRequested => { + elwt.exit(); + self.device.device_wait_idle().unwrap(); + self.destroy(); + } + _ => {} } _ => {} } - }); + }) } /// Renders a frame for this app. diff --git a/tutorial/Cargo.toml b/tutorial/Cargo.toml index 6b314fcc..ae76aade 100644 --- a/tutorial/Cargo.toml +++ b/tutorial/Cargo.toml @@ -20,11 +20,15 @@ anyhow = "1" log = "0.4" cgmath = "0.18" png = "0.17" -pretty_env_logger = "0.4" +pretty_env_logger = "0.5" thiserror = "1" tobj = { version = "3", features = ["log"] } -vulkanalia = { version = "=0.22.0", features = ["libloading", "provisional", "window"] } -winit = "0.28" +vulkanalia = { path = "../vulkanalia", version = "=0.22.0", features = [ + "libloading", + "provisional", + "window", +] } +winit = "0.29" [[bin]] diff --git a/tutorial/book/preprocessor/Cargo.toml b/tutorial/book/preprocessor/Cargo.toml index d13ec672..77847a20 100644 --- a/tutorial/book/preprocessor/Cargo.toml +++ b/tutorial/book/preprocessor/Cargo.toml @@ -22,7 +22,7 @@ anyhow = "1" clap = "2" log = "0.4" mdbook = { version = "=0.4.21", default-features = false } -pretty_env_logger = "0.4" +pretty_env_logger = "0.5" pulldown-cmark = "0.8" pulldown-cmark-to-cmark = "6" serde_json = "1" diff --git a/tutorial/book/src/development_environment.md b/tutorial/book/src/development_environment.md index 3d6c6a6c..5a540275 100644 --- a/tutorial/book/src/development_environment.md +++ b/tutorial/book/src/development_environment.md @@ -17,11 +17,11 @@ anyhow = "1" log = "0.4" cgmath = "0.18" png = "0.17" -pretty_env_logger = "0.4" +pretty_env_logger = "0.5" thiserror = "1" tobj = { version = "3", features = ["log"] } -vulkanalia = { version = "=0.21.0", features = ["libloading", "provisional", "window"] } -winit = "0.28" +vulkanalia = { version = "=0.22.0", features = ["libloading", "provisional", "window"] } +winit = "0.29" ``` * `anyhow` – used for simple error handling diff --git a/tutorial/book/src/dynamic/secondary_command_buffers.md b/tutorial/book/src/dynamic/secondary_command_buffers.md index d2b60c80..8528d485 100644 --- a/tutorial/book/src/dynamic/secondary_command_buffers.md +++ b/tutorial/book/src/dynamic/secondary_command_buffers.md @@ -293,14 +293,18 @@ Finally, add a case to the event match block in the `main` function that handles ```rust,noplaypen match event { // ... - Event::WindowEvent { event: WindowEvent::KeyboardInput { input, .. }, .. } => { - if input.state == ElementState::Pressed { - match input.virtual_keycode { - Some(VirtualKeyCode::Left) if app.models > 1 => app.models -= 1, - Some(VirtualKeyCode::Right) if app.models < 4 => app.models += 1, - _ => { } + Event::WindowEvent { event, .. } => match event { + // ... + WindowEvent::KeyboardInput { event, .. } => { + if event.state == ElementState::Pressed { + match event.physical_key { + PhysicalKey::Code(KeyCode::ArrowLeft) if app.models > 1 => app.models -= 1, + PhysicalKey::Code(KeyCode::ArrowRight) if app.models < 4 => app.models += 1, + _ => { } + } } } + // ... } // ... } diff --git a/tutorial/book/src/setup/base_code.md b/tutorial/book/src/setup/base_code.md index 0f80697a..c8235fde 100644 --- a/tutorial/book/src/setup/base_code.md +++ b/tutorial/book/src/setup/base_code.md @@ -15,7 +15,7 @@ In the `Development environment` chapter we created a Cargo project and added th use anyhow::Result; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; fn main() -> Result<()> { @@ -23,7 +23,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -32,22 +32,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => - unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/book/src/swapchain/recreation.md b/tutorial/book/src/swapchain/recreation.md index 6d412a26..494aac77 100644 --- a/tutorial/book/src/swapchain/recreation.md +++ b/tutorial/book/src/swapchain/recreation.md @@ -171,24 +171,27 @@ There is another case where a swapchain may become out of date and that is a spe ```rust,noplaypen let mut app = unsafe { App::create(&window)? }; -let mut destroying = false; let mut minimized = false; -event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; +event_loop.run(move |event,elwt| { match event { - Event::MainEventsCleared if !destroying && !minimized => - unsafe { app.render(&window) }.unwrap(), - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // ... + Event::WindowEvent { event, .. } => match event { + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + WindowEvent::Resized(size) => { + if size.width == 0 || size.height == 0 { + minimized = true; + } else { + minimized = false; + app.resized = true; + } } + // ... } // ... } -}); +})?; ``` Congratulations, you've now finished your very first well-behaved Vulkan program! In the next chapter we're going to get rid of the hardcoded vertices in the vertex shader and actually use a vertex buffer. diff --git a/tutorial/src/00_base_code.rs b/tutorial/src/00_base_code.rs index 2ea5772b..a8edc2ee 100644 --- a/tutorial/src/00_base_code.rs +++ b/tutorial/src/00_base_code.rs @@ -11,7 +11,7 @@ use anyhow::Result; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; #[rustfmt::skip] @@ -20,7 +20,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -29,21 +29,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/01_instance_creation.rs b/tutorial/src/01_instance_creation.rs index 1f4b7dbd..f55e1c44 100644 --- a/tutorial/src/01_instance_creation.rs +++ b/tutorial/src/01_instance_creation.rs @@ -16,7 +16,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; /// The Vulkan SDK version that started requiring the portability subset extension for macOS. @@ -28,7 +28,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -37,21 +37,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/02_validation_layers.rs b/tutorial/src/02_validation_layers.rs index 33296a65..8274a123 100644 --- a/tutorial/src/02_validation_layers.rs +++ b/tutorial/src/02_validation_layers.rs @@ -20,7 +20,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -39,7 +39,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -48,21 +48,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/03_physical_device_selection.rs b/tutorial/src/03_physical_device_selection.rs index 0964d11b..d94f8c3b 100644 --- a/tutorial/src/03_physical_device_selection.rs +++ b/tutorial/src/03_physical_device_selection.rs @@ -21,7 +21,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -40,7 +40,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -49,21 +49,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/04_logical_device.rs b/tutorial/src/04_logical_device.rs index d2dde394..c50231ff 100644 --- a/tutorial/src/04_logical_device.rs +++ b/tutorial/src/04_logical_device.rs @@ -21,7 +21,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -40,7 +40,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -49,21 +49,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/05_window_surface.rs b/tutorial/src/05_window_surface.rs index b8ee2c31..401d1277 100644 --- a/tutorial/src/05_window_surface.rs +++ b/tutorial/src/05_window_surface.rs @@ -21,7 +21,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -41,7 +41,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -50,21 +50,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/06_swapchain_creation.rs b/tutorial/src/06_swapchain_creation.rs index 9d81633d..30150c34 100644 --- a/tutorial/src/06_swapchain_creation.rs +++ b/tutorial/src/06_swapchain_creation.rs @@ -21,7 +21,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -44,7 +44,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -53,21 +53,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/07_image_views.rs b/tutorial/src/07_image_views.rs index 90cf3579..c1d48044 100644 --- a/tutorial/src/07_image_views.rs +++ b/tutorial/src/07_image_views.rs @@ -21,7 +21,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -44,7 +44,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -53,21 +53,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/08_graphics_pipeline.rs b/tutorial/src/08_graphics_pipeline.rs index 90a3a64d..d520dd90 100644 --- a/tutorial/src/08_graphics_pipeline.rs +++ b/tutorial/src/08_graphics_pipeline.rs @@ -21,7 +21,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -44,7 +44,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -53,21 +53,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/09_shader_modules.rs b/tutorial/src/09_shader_modules.rs index 0ad97fac..1a145a4c 100644 --- a/tutorial/src/09_shader_modules.rs +++ b/tutorial/src/09_shader_modules.rs @@ -22,7 +22,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -45,7 +45,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -54,21 +54,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/10_fixed_functions.rs b/tutorial/src/10_fixed_functions.rs index 3ea7e032..cb12d7dc 100644 --- a/tutorial/src/10_fixed_functions.rs +++ b/tutorial/src/10_fixed_functions.rs @@ -22,7 +22,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -45,7 +45,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -54,21 +54,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/11_render_passes.rs b/tutorial/src/11_render_passes.rs index 61e462f2..5c324cab 100644 --- a/tutorial/src/11_render_passes.rs +++ b/tutorial/src/11_render_passes.rs @@ -22,7 +22,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -45,7 +45,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -54,21 +54,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/12_graphics_pipeline_complete.rs b/tutorial/src/12_graphics_pipeline_complete.rs index 357a9c5b..d58f5ff8 100644 --- a/tutorial/src/12_graphics_pipeline_complete.rs +++ b/tutorial/src/12_graphics_pipeline_complete.rs @@ -22,7 +22,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -45,7 +45,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -54,21 +54,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/13_framebuffers.rs b/tutorial/src/13_framebuffers.rs index 53e530aa..ea24392f 100644 --- a/tutorial/src/13_framebuffers.rs +++ b/tutorial/src/13_framebuffers.rs @@ -22,7 +22,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -45,7 +45,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -54,21 +54,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/14_command_buffers.rs b/tutorial/src/14_command_buffers.rs index 03e79de6..ee2a43c5 100644 --- a/tutorial/src/14_command_buffers.rs +++ b/tutorial/src/14_command_buffers.rs @@ -22,7 +22,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -45,7 +45,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -54,21 +54,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/15_hello_triangle.rs b/tutorial/src/15_hello_triangle.rs index 3736eed7..2be218f6 100644 --- a/tutorial/src/15_hello_triangle.rs +++ b/tutorial/src/15_hello_triangle.rs @@ -22,7 +22,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -48,7 +48,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -57,21 +57,25 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying => unsafe { app.render(&window) }.unwrap(), - // Destroy our Vulkan app. - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - destroying = true; - *control_flow = ControlFlow::Exit; - unsafe { app.destroy(); } + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() => unsafe { app.render(&window) }.unwrap(), + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/16_swapchain_recreation.rs b/tutorial/src/16_swapchain_recreation.rs index 1fe96896..8bfd92fb 100644 --- a/tutorial/src/16_swapchain_recreation.rs +++ b/tutorial/src/16_swapchain_recreation.rs @@ -22,7 +22,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -48,7 +48,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -57,31 +57,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/17_vertex_input.rs b/tutorial/src/17_vertex_input.rs index 9bd3ba80..ba7644ed 100644 --- a/tutorial/src/17_vertex_input.rs +++ b/tutorial/src/17_vertex_input.rs @@ -24,7 +24,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -60,7 +60,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -69,31 +69,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/18_vertex_buffer.rs b/tutorial/src/18_vertex_buffer.rs index a5c8cc18..9ac44221 100644 --- a/tutorial/src/18_vertex_buffer.rs +++ b/tutorial/src/18_vertex_buffer.rs @@ -25,7 +25,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -61,7 +61,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -70,31 +70,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/19_staging_buffer.rs b/tutorial/src/19_staging_buffer.rs index b70c40f7..408ba032 100644 --- a/tutorial/src/19_staging_buffer.rs +++ b/tutorial/src/19_staging_buffer.rs @@ -25,7 +25,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -61,7 +61,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -70,31 +70,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/20_index_buffer.rs b/tutorial/src/20_index_buffer.rs index ac20d309..1199eb39 100644 --- a/tutorial/src/20_index_buffer.rs +++ b/tutorial/src/20_index_buffer.rs @@ -25,7 +25,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -64,7 +64,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -73,31 +73,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/21_descriptor_set_layout.rs b/tutorial/src/21_descriptor_set_layout.rs index ca079894..fb7fd249 100644 --- a/tutorial/src/21_descriptor_set_layout.rs +++ b/tutorial/src/21_descriptor_set_layout.rs @@ -26,7 +26,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -66,7 +66,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -75,31 +75,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/22_descriptor_sets.rs b/tutorial/src/22_descriptor_sets.rs index 12437c18..170c2b00 100644 --- a/tutorial/src/22_descriptor_sets.rs +++ b/tutorial/src/22_descriptor_sets.rs @@ -26,7 +26,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -66,7 +66,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -75,31 +75,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/23_texture_image.rs b/tutorial/src/23_texture_image.rs index de4f933c..f33ad295 100644 --- a/tutorial/src/23_texture_image.rs +++ b/tutorial/src/23_texture_image.rs @@ -27,7 +27,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -67,7 +67,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -76,31 +76,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/24_sampler.rs b/tutorial/src/24_sampler.rs index 57cc3768..3d6e3ec8 100644 --- a/tutorial/src/24_sampler.rs +++ b/tutorial/src/24_sampler.rs @@ -27,7 +27,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -67,7 +67,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -76,31 +76,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/25_texture_mapping.rs b/tutorial/src/25_texture_mapping.rs index a3ddc351..7cd49a49 100644 --- a/tutorial/src/25_texture_mapping.rs +++ b/tutorial/src/25_texture_mapping.rs @@ -27,7 +27,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -67,7 +67,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -76,31 +76,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/26_depth_buffering.rs b/tutorial/src/26_depth_buffering.rs index f0b6c1e2..85cd39bc 100644 --- a/tutorial/src/26_depth_buffering.rs +++ b/tutorial/src/26_depth_buffering.rs @@ -27,7 +27,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -77,7 +77,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -86,31 +86,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/27_model_loading.rs b/tutorial/src/27_model_loading.rs index b1256757..9704d4af 100644 --- a/tutorial/src/27_model_loading.rs +++ b/tutorial/src/27_model_loading.rs @@ -29,7 +29,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -59,7 +59,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -68,31 +68,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/28_mipmapping.rs b/tutorial/src/28_mipmapping.rs index bc47462e..602bee0d 100644 --- a/tutorial/src/28_mipmapping.rs +++ b/tutorial/src/28_mipmapping.rs @@ -29,7 +29,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -59,7 +59,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -68,31 +68,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/29_multisampling.rs b/tutorial/src/29_multisampling.rs index a90420c2..40b8a477 100644 --- a/tutorial/src/29_multisampling.rs +++ b/tutorial/src/29_multisampling.rs @@ -29,7 +29,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -59,7 +59,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -68,31 +68,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/30_push_constants.rs b/tutorial/src/30_push_constants.rs index fdaf95db..c715e65e 100644 --- a/tutorial/src/30_push_constants.rs +++ b/tutorial/src/30_push_constants.rs @@ -29,7 +29,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -59,7 +59,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -68,31 +68,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/31_recycling_command_buffers.rs b/tutorial/src/31_recycling_command_buffers.rs index c94848f5..033ab936 100644 --- a/tutorial/src/31_recycling_command_buffers.rs +++ b/tutorial/src/31_recycling_command_buffers.rs @@ -29,7 +29,7 @@ use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; use winit::event::{Event, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event_loop::EventLoop; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -59,7 +59,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -68,31 +68,37 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/tutorial/src/32_secondary_command_buffers.rs b/tutorial/src/32_secondary_command_buffers.rs index e029aa59..919a21e8 100644 --- a/tutorial/src/32_secondary_command_buffers.rs +++ b/tutorial/src/32_secondary_command_buffers.rs @@ -28,8 +28,9 @@ use vulkanalia::prelude::v1_0::*; use vulkanalia::window as vk_window; use vulkanalia::Version; use winit::dpi::LogicalSize; -use winit::event::{ElementState, Event, VirtualKeyCode, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event::{ElementState, Event, WindowEvent}; +use winit::event_loop::EventLoop; +use winit::keyboard::{KeyCode, PhysicalKey}; use winit::window::{Window, WindowBuilder}; use vulkanalia::vk::ExtDebugUtilsExtension; @@ -59,7 +60,7 @@ fn main() -> Result<()> { // Window - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; let window = WindowBuilder::new() .with_title("Vulkan Tutorial (Rust)") .with_inner_size(LogicalSize::new(1024, 768)) @@ -68,41 +69,47 @@ fn main() -> Result<()> { // App let mut app = unsafe { App::create(&window)? }; - let mut destroying = false; let mut minimized = false; - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, elwt| { match event { - // Render a frame if our Vulkan app is not being destroyed. - Event::MainEventsCleared if !destroying && !minimized => unsafe { app.render(&window) }.unwrap(), - // Mark the window as having been resized. - Event::WindowEvent { event: WindowEvent::Resized(size), .. } => { - if size.width == 0 || size.height == 0 { - minimized = true; - } else { - minimized = false; - app.resized = true; + // Request a redraw when all events were processed. + Event::AboutToWait => window.request_redraw(), + Event::WindowEvent { event, .. } => match event { + // Render a frame if our Vulkan app is not being destroyed. + WindowEvent::RedrawRequested if !elwt.exiting() && !minimized => { + unsafe { app.render(&window) }.unwrap(); + }, + // Mark the window as having been resized. + 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 { app.destroy(); } - } - // Handle keyboard events. - Event::WindowEvent { event: WindowEvent::KeyboardInput { input, .. }, .. } => { - if input.state == ElementState::Pressed { - match input.virtual_keycode { - Some(VirtualKeyCode::Left) if app.models > 1 => app.models -= 1, - Some(VirtualKeyCode::Right) if app.models < 4 => app.models += 1, - _ => { } + // Destroy our Vulkan app. + WindowEvent::CloseRequested => { + elwt.exit(); + unsafe { app.destroy(); } + } + // Handle keyboard events. + WindowEvent::KeyboardInput { event, .. } => { + if event.state == ElementState::Pressed { + match event.physical_key { + PhysicalKey::Code(KeyCode::ArrowLeft) if app.models > 1 => app.models -= 1, + PhysicalKey::Code(KeyCode::ArrowRight) if app.models < 4 => app.models += 1, + _ => { } + } } } + _ => {} } _ => {} } - }); + })?; + + Ok(()) } /// Our Vulkan app. diff --git a/vulkanalia/Cargo.toml b/vulkanalia/Cargo.toml index f9292229..4fba8f42 100644 --- a/vulkanalia/Cargo.toml +++ b/vulkanalia/Cargo.toml @@ -30,8 +30,8 @@ window = ["raw-window-handle", "cocoa", "metal", "objc"] [dependencies] -libloading = { version = "0.7", optional = true } -raw-window-handle = { version = "0.5", optional = true } +libloading = { version = "0.8", optional = true } +raw-window-handle = { version = "0.6", optional = true } vulkanalia-sys = { version = "0.22", path = "../vulkanalia-sys", default-features = false } [target.'cfg(target_os = "macos")'.dependencies] diff --git a/vulkanalia/src/window.rs b/vulkanalia/src/window.rs index e34af3a3..4c496804 100644 --- a/vulkanalia/src/window.rs +++ b/vulkanalia/src/window.rs @@ -2,18 +2,15 @@ //! Window integration. -use raw_window_handle::{ - HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, -}; +use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawDisplayHandle, RawWindowHandle}; use crate::prelude::v1_0::*; /// Gets the required instance extensions for window integration. -#[allow(deprecated, unused_variables)] pub fn get_required_instance_extensions( - window: &dyn HasRawWindowHandle, + window: &dyn HasWindowHandle, ) -> &'static [&'static vk::ExtensionName] { - match window.raw_window_handle() { + match window.window_handle().map(|handle| handle.as_raw()) { // BSD / Linux #[cfg(any( target_os = "dragonfly", @@ -22,7 +19,7 @@ pub fn get_required_instance_extensions( target_os = "netbsd", target_os = "openbsd" ))] - RawWindowHandle::Wayland(window) => &[ + Ok(RawWindowHandle::Wayland(_window)) => &[ &vk::KHR_SURFACE_EXTENSION.name, &vk::KHR_WAYLAND_SURFACE_EXTENSION.name, ], @@ -33,7 +30,7 @@ pub fn get_required_instance_extensions( target_os = "netbsd", target_os = "openbsd" ))] - RawWindowHandle::Xcb(window) => &[ + Ok(RawWindowHandle::Xcb(_window)) => &[ &vk::KHR_SURFACE_EXTENSION.name, &vk::KHR_XCB_SURFACE_EXTENSION.name, ], @@ -44,19 +41,19 @@ pub fn get_required_instance_extensions( target_os = "netbsd", target_os = "openbsd" ))] - RawWindowHandle::Xlib(window) => &[ + Ok(RawWindowHandle::Xlib(_window)) => &[ &vk::KHR_SURFACE_EXTENSION.name, &vk::KHR_XLIB_SURFACE_EXTENSION.name, ], // macOS #[cfg(target_os = "macos")] - RawWindowHandle::AppKit(window) => &[ + Ok(RawWindowHandle::AppKit(window)) => &[ &vk::KHR_SURFACE_EXTENSION.name, &vk::EXT_METAL_SURFACE_EXTENSION.name, ], // Windows #[cfg(target_os = "windows")] - RawWindowHandle::Win32(_) => &[ + Ok(RawWindowHandle::Win32(_)) => &[ &vk::KHR_SURFACE_EXTENSION.name, &vk::KHR_WIN32_SURFACE_EXTENSION.name, ], @@ -75,10 +72,13 @@ pub fn get_required_instance_extensions( #[allow(deprecated, unused_variables)] pub unsafe fn create_surface( instance: &Instance, - display: &dyn HasRawDisplayHandle, - window: &dyn HasRawWindowHandle, + display: &dyn HasDisplayHandle, + window: &dyn HasWindowHandle, ) -> VkResult { - match (display.raw_display_handle(), window.raw_window_handle()) { + match ( + display.display_handle().map(|handle| handle.as_raw()), + window.window_handle().map(|handle| handle.as_raw()), + ) { // BSD / Linux #[cfg(any( target_os = "dragonfly", @@ -87,11 +87,11 @@ pub unsafe fn create_surface( target_os = "netbsd", target_os = "openbsd" ))] - (RawDisplayHandle::Wayland(display), RawWindowHandle::Wayland(window)) => { + (Ok(RawDisplayHandle::Wayland(display)), Ok(RawWindowHandle::Wayland(window))) => { use vk::KhrWaylandSurfaceExtension; let info = vk::WaylandSurfaceCreateInfoKHR::builder() - .display(display.display) - .surface(window.surface); + .display(display.display.as_ptr()) + .surface(window.surface.as_ptr()); instance.create_wayland_surface_khr(&info, None) } #[cfg(any( @@ -101,11 +101,17 @@ pub unsafe fn create_surface( target_os = "netbsd", target_os = "openbsd" ))] - (RawDisplayHandle::Xcb(display), RawWindowHandle::Xcb(window)) => { + (Ok(RawDisplayHandle::Xcb(display)), Ok(RawWindowHandle::Xcb(window))) => { use vk::KhrXcbSurfaceExtension; + + let connection_ptr = display + .connection + .map(|connection| connection.as_ptr()) + .unwrap_or(std::ptr::null_mut()); + let info = vk::XcbSurfaceCreateInfoKHR::builder() - .connection(display.connection) - .window(window.window as _); + .connection(connection_ptr) + .window(window.window.get() as _); instance.create_xcb_surface_khr(&info, None) } #[cfg(any( @@ -115,17 +121,23 @@ pub unsafe fn create_surface( target_os = "netbsd", target_os = "openbsd" ))] - (RawDisplayHandle::Xlib(display), RawWindowHandle::Xlib(window)) => { + (Ok(RawDisplayHandle::Xlib(display)), Ok(RawWindowHandle::Xlib(window))) => { use vk::KhrXlibSurfaceExtension; + + let display_ptr = display + .display + .map(|display| display.as_ptr()) + .unwrap_or(std::ptr::null_mut()); + let info = vk::XlibSurfaceCreateInfoKHR::builder() - .dpy(&mut (*(display.display as *mut _))) + .dpy(&mut *(display_ptr as *mut _)) .window(window.window); instance.create_xlib_surface_khr(&info, None) } // macOS #[cfg(target_os = "macos")] - (RawDisplayHandle::AppKit(_), RawWindowHandle::AppKit(window)) => { + (Ok(RawDisplayHandle::AppKit(_)), Ok(RawWindowHandle::AppKit(window))) => { use std::mem; use std::os::raw::c_void; @@ -159,7 +171,7 @@ pub unsafe fn create_surface( } // Windows #[cfg(target_os = "windows")] - (RawDisplayHandle::Windows(_), RawWindowHandle::Win32(window)) => { + (Ok(RawDisplayHandle::Windows(_)), Ok(RawWindowHandle::Win32(window))) => { use vk::KhrWin32SurfaceExtension; let info = vk::Win32SurfaceCreateInfoKHR::builder() .hinstance(window.hinstance) From f914a5a821833a9cb0f2c205d85468ef866a48f7 Mon Sep 17 00:00:00 2001 From: Ivan Kalinin Date: Sun, 4 Feb 2024 19:14:44 +0100 Subject: [PATCH 2/3] Fix build on windows --- vulkanalia/src/window.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vulkanalia/src/window.rs b/vulkanalia/src/window.rs index 4c496804..8fef38ea 100644 --- a/vulkanalia/src/window.rs +++ b/vulkanalia/src/window.rs @@ -173,9 +173,17 @@ pub unsafe fn create_surface( #[cfg(target_os = "windows")] (Ok(RawDisplayHandle::Windows(_)), Ok(RawWindowHandle::Win32(window))) => { use vk::KhrWin32SurfaceExtension; + + let hinstance_ptr = window + .hinstance + .map(|hinstance| hinstance.get() as vk::HINSTANCE) + .unwrap_or(std::ptr::null_mut()); + let hwnd_ptr = window.hwnd.get() as vk::HWND; + let info = vk::Win32SurfaceCreateInfoKHR::builder() - .hinstance(window.hinstance) - .hwnd(window.hwnd); + .hinstance(hinstance_ptr) + .hwnd(hwnd_ptr); + instance.create_win32_surface_khr(&info, None) } // Unsupported (currently) From 90a8404ac79712215b4a44a61aa6e7a9488607e1 Mon Sep 17 00:00:00 2001 From: Ivan Kalinin Date: Mon, 5 Feb 2024 18:38:41 +0100 Subject: [PATCH 3/3] Fix build on macos --- vulkanalia/Cargo.toml | 4 ++-- vulkanalia/src/window.rs | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/vulkanalia/Cargo.toml b/vulkanalia/Cargo.toml index 4fba8f42..d72d305e 100644 --- a/vulkanalia/Cargo.toml +++ b/vulkanalia/Cargo.toml @@ -36,8 +36,8 @@ vulkanalia-sys = { version = "0.22", path = "../vulkanalia-sys", default-feature [target.'cfg(target_os = "macos")'.dependencies] -cocoa = { version = "0.24", optional = true } -metal = { version = "0.21", optional = true } +cocoa = { version = "0.25", optional = true } +metal = { version = "0.27", optional = true } objc = { version = "0.2", optional = true } [package.metadata.docs.rs] diff --git a/vulkanalia/src/window.rs b/vulkanalia/src/window.rs index 8fef38ea..fd265eb7 100644 --- a/vulkanalia/src/window.rs +++ b/vulkanalia/src/window.rs @@ -47,13 +47,13 @@ pub fn get_required_instance_extensions( ], // macOS #[cfg(target_os = "macos")] - Ok(RawWindowHandle::AppKit(window)) => &[ + Ok(RawWindowHandle::AppKit(_window)) => &[ &vk::KHR_SURFACE_EXTENSION.name, &vk::EXT_METAL_SURFACE_EXTENSION.name, ], // Windows #[cfg(target_os = "windows")] - Ok(RawWindowHandle::Win32(_)) => &[ + Ok(RawWindowHandle::Win32(_window)) => &[ &vk::KHR_SURFACE_EXTENSION.name, &vk::KHR_WIN32_SURFACE_EXTENSION.name, ], @@ -138,7 +138,6 @@ pub unsafe fn create_surface( // macOS #[cfg(target_os = "macos")] (Ok(RawDisplayHandle::AppKit(_)), Ok(RawWindowHandle::AppKit(window))) => { - use std::mem; use std::os::raw::c_void; use cocoa::appkit::{NSView, NSWindow}; @@ -147,10 +146,8 @@ pub unsafe fn create_surface( use objc::runtime::YES; use vk::ExtMetalSurfaceExtension; - let (view, layer) = { - let id = mem::transmute::<_, id>(window.ns_window); - - let view = id.contentView(); + let layer = { + let view = window.ns_view.as_ptr() as id; let layer = MetalLayer::new(); layer.set_contents_scale(view.backingScaleFactor()); @@ -162,7 +159,7 @@ pub unsafe fn create_surface( view.setLayer(layer_ref as *mut objc::runtime::Object); view.setWantsLayer(YES); - (&mut *window.ns_view, layer) + layer }; let layer = (layer.as_ref() as *const MetalLayerRef).cast::();