Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update winit dependency to 0.29 #244

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion examples/src/bin/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
37 changes: 20 additions & 17 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions tutorial/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand Down
2 changes: 1 addition & 1 deletion tutorial/book/preprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions tutorial/book/src/development_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` &ndash; used for simple error handling
Expand Down
16 changes: 10 additions & 6 deletions tutorial/book/src/dynamic/secondary_command_buffers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
_ => { }
}
}
}
// ...
}
// ...
}
Expand Down
31 changes: 17 additions & 14 deletions tutorial/book/src/setup/base_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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<()> {
pretty_env_logger::init();

// 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))
Expand All @@ -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.
Expand Down
27 changes: 15 additions & 12 deletions tutorial/book/src/swapchain/recreation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
30 changes: 17 additions & 13 deletions tutorial/src/00_base_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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))
Expand All @@ -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.
Expand Down
30 changes: 17 additions & 13 deletions tutorial/src/01_instance_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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))
Expand All @@ -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.
Expand Down
Loading