Skip to content

Commit

Permalink
Bump wgpu to 0.19 and winit to 0.29 (#391)
Browse files Browse the repository at this point in the history
* Bump `wgpu` to 0.19 and `winit` to 0.29

* Fix conway example

* Fix custom-shader example

* Fix raqote-winit example

* Fix tiny-skia-winit example

* Fix minimal-winit example

* Fix minimal-winit-android example

* Fix minimal-web example

* Fix minimal-tao example

Removed menu as it's no longer supported directly by `tao`.

* Fix invaders example

Lock game-loop to 1.1.0 - version 1.2.0 bumps `winit` to 0.30 which we
don't support yet

* Fix minimal-egui example

* Keep imgui-winit example on old dependencies

Until `imgui-wgpu-rs` updates support for `wgpu`, pin the example to an
old `pixels` commit.

* Fix minimal-fltk exmaple

* Cargo.lock
  • Loading branch information
mkrasnitski authored Sep 22, 2024
1 parent 9bdf8a2 commit 07e169d
Show file tree
Hide file tree
Showing 32 changed files with 1,953 additions and 587 deletions.
1,953 changes: 1,636 additions & 317 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ include = [

[dependencies]
bytemuck = "1.12"
raw-window-handle = "0.5"
raw-window-handle = "0.6"
thiserror = "1.0"
ultraviolet = "0.9"
wgpu = "0.17"
wgpu = "0.19"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wgpu = { version = "0.17", features = ["webgl"] }
wgpu = { version = "0.19", features = ["webgl"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
pollster = "0.3"

[dev-dependencies]
pixels-mocks = { path = "internals/pixels-mocks" }
winit = "0.28"
winit = "0.29"

[workspace]
members = [
Expand Down
4 changes: 2 additions & 2 deletions examples/conway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ clipline = "0.1.1"
log = "0.4"
pixels = { path = "../.." }
randomize = "3"
winit = "0.28"
winit_input_helper = "0.14"
winit = "0.29"
winit_input_helper = "0.15"
36 changes: 21 additions & 15 deletions examples/conway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use log::{debug, error};
use pixels::{Error, Pixels, SurfaceTexture};
use winit::{
dpi::LogicalSize,
event::{Event, VirtualKeyCode},
event_loop::{ControlFlow, EventLoop},
event::{Event, WindowEvent},
event_loop::EventLoop,
keyboard::KeyCode,
window::WindowBuilder,
};
use winit_input_helper::WinitInputHelper;
Expand All @@ -17,7 +18,7 @@ const HEIGHT: u32 = 300;

fn main() -> Result<(), Error> {
env_logger::init();
let event_loop = EventLoop::new();
let event_loop = EventLoop::new().unwrap();
let mut input = WinitInputHelper::new();

let window = {
Expand All @@ -42,13 +43,17 @@ fn main() -> Result<(), Error> {

let mut draw_state: Option<bool> = None;

event_loop.run(move |event, _, control_flow| {
let res = event_loop.run(|event, elwt| {
// The one and only event that winit_input_helper doesn't have for us...
if let Event::RedrawRequested(_) = event {
if let Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
} = event
{
life.draw(pixels.frame_mut());
if let Err(err) = pixels.render() {
log_error("pixels.render", err);
*control_flow = ControlFlow::Exit;
elwt.exit();
return;
}
}
Expand All @@ -57,26 +62,26 @@ fn main() -> Result<(), Error> {
// It returns `true` when it is time to update our game state and request a redraw.
if input.update(&event) {
// Close events
if input.key_pressed(VirtualKeyCode::Escape) || input.close_requested() {
*control_flow = ControlFlow::Exit;
if input.key_pressed(KeyCode::Escape) || input.close_requested() {
elwt.exit();
return;
}
if input.key_pressed(VirtualKeyCode::P) {
if input.key_pressed(KeyCode::KeyP) {
paused = !paused;
}
if input.key_pressed_os(VirtualKeyCode::Space) {
if input.key_pressed_os(KeyCode::Space) {
// Space is frame-step, so ensure we're paused
paused = true;
}
if input.key_pressed(VirtualKeyCode::R) {
if input.key_pressed(KeyCode::KeyR) {
life.randomize();
}
// Handle mouse. This is a bit involved since support some simple
// line drawing (mostly because it makes nice looking patterns).
let (mouse_cell, mouse_prev_cell) = input
.mouse()
.cursor()
.map(|(mx, my)| {
let (dx, dy) = input.mouse_diff();
let (dx, dy) = input.cursor_diff();
let prev_x = mx - dx;
let prev_y = my - dy;

Expand Down Expand Up @@ -125,16 +130,17 @@ fn main() -> Result<(), Error> {
if let Some(size) = input.window_resized() {
if let Err(err) = pixels.resize_surface(size.width, size.height) {
log_error("pixels.resize_surface", err);
*control_flow = ControlFlow::Exit;
elwt.exit();
return;
}
}
if !paused || input.key_pressed_os(VirtualKeyCode::Space) {
if !paused || input.key_pressed_os(KeyCode::Space) {
life.update();
}
window.request_redraw();
}
});
res.map_err(|e| Error::UserDefined(Box::new(e)))
}

fn log_error<E: std::error::Error + 'static>(method_name: &str, err: E) {
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-shader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ env_logger = "0.10"
error-iter = "0.4"
log = "0.4"
pixels = { path = "../.." }
winit = "0.28"
winit_input_helper = "0.14"
winit = "0.29"
winit_input_helper = "0.15"
26 changes: 16 additions & 10 deletions examples/custom-shader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use error_iter::ErrorIter as _;
use log::error;
use pixels::{Error, Pixels, SurfaceTexture};
use winit::dpi::LogicalSize;
use winit::event::{Event, VirtualKeyCode};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::event::{Event, WindowEvent};
use winit::event_loop::EventLoop;
use winit::keyboard::KeyCode;
use winit::window::WindowBuilder;
use winit_input_helper::WinitInputHelper;

Expand All @@ -27,7 +28,7 @@ struct World {

fn main() -> Result<(), Error> {
env_logger::init();
let event_loop = EventLoop::new();
let event_loop = EventLoop::new().unwrap();
let mut input = WinitInputHelper::new();
let window = {
let size = LogicalSize::new(WIDTH as f64, HEIGHT as f64);
Expand All @@ -48,9 +49,13 @@ fn main() -> Result<(), Error> {
let mut time = 0.0;
let mut noise_renderer = NoiseRenderer::new(&pixels, window_size.width, window_size.height)?;

event_loop.run(move |event, _, control_flow| {
let res = event_loop.run(|event, elwt| {
// Draw the current frame
if let Event::RedrawRequested(_) = event {
if let Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
} = event
{
world.draw(pixels.frame_mut());

let render_result = pixels.render_with(|encoder, render_target, context| {
Expand All @@ -67,29 +72,29 @@ fn main() -> Result<(), Error> {

if let Err(err) = render_result {
log_error("pixels.render_with", err);
*control_flow = ControlFlow::Exit;
elwt.exit();
return;
}
}

// Handle input events
if input.update(&event) {
// Close events
if input.key_pressed(VirtualKeyCode::Escape) || input.close_requested() {
*control_flow = ControlFlow::Exit;
if input.key_pressed(KeyCode::Escape) || input.close_requested() {
elwt.exit();
return;
}

// Resize the window
if let Some(size) = input.window_resized() {
if let Err(err) = pixels.resize_surface(size.width, size.height) {
log_error("pixels.resize_surface", err);
*control_flow = ControlFlow::Exit;
elwt.exit();
return;
}
if let Err(err) = noise_renderer.resize(&pixels, size.width, size.height) {
log_error("noise_renderer.resize", err);
*control_flow = ControlFlow::Exit;
elwt.exit();
return;
}
}
Expand All @@ -99,6 +104,7 @@ fn main() -> Result<(), Error> {
window.request_redraw();
}
});
res.map_err(|e| Error::UserDefined(Box::new(e)))
}

fn log_error<E: std::error::Error + 'static>(method_name: &str, err: E) {
Expand Down
4 changes: 3 additions & 1 deletion examples/custom-shader/src/renderers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,12 @@ impl NoiseRenderer {
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
rpass.set_pipeline(&self.render_pipeline);
rpass.set_bind_group(0, &self.bind_group, &[]);
Expand Down
11 changes: 9 additions & 2 deletions examples/imgui-winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ default = ["optimize"]
env_logger = "0.10"
error-iter = "0.4"
imgui = "0.11"
imgui-wgpu = "0.24"
imgui-winit-support = "0.11"
log = "0.4"
pixels = { path = "../.." }
winit = "0.27"
winit_input_helper = "0.13"

# Until this gets updated support, this example is stuck on winit 0.27 and wgpu 0.17
[dependencies.imgui-wgpu]
version = "0.24"

# Frozen dep for this specific example
[dependencies.pixels]
git = "https://github.com/parasyte/pixels"
rev = "befb84a"
6 changes: 3 additions & 3 deletions examples/invaders/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ default = ["optimize"]
byteorder = "1"
env_logger = "0.10"
error-iter = "0.4"
game-loop = { version = "0.10", features = ["winit"] }
game-loop = { version = "=1.1.0", features = ["winit"] }
getrandom = "0.2"
gilrs = "0.10"
log = "0.4"
pixels = { path = "../.." }
simple-invaders = { path = "simple-invaders" }
winit = "0.28"
winit_input_helper = "0.14"
winit = "0.29"
winit_input_helper = "0.15"
38 changes: 19 additions & 19 deletions examples/invaders/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ use gilrs::{Button, GamepadId, Gilrs};
use log::{debug, error};
use pixels::{Error, Pixels, SurfaceTexture};
use simple_invaders::{Controls, Direction, World, FPS, HEIGHT, TIME_STEP, WIDTH};
use std::sync::Arc;
use std::{env, time::Duration};
use winit::{
dpi::LogicalSize, event::VirtualKeyCode, event_loop::EventLoop, window::WindowBuilder,
};
use winit::{dpi::LogicalSize, event_loop::EventLoop, keyboard::KeyCode, window::WindowBuilder};
use winit_input_helper::WinitInputHelper;

/// Uber-struct representing the entire game.
struct Game {
/// Software renderer.
pixels: Pixels,
pixels: Pixels<'static>,
/// Invaders world.
world: World,
/// Player controls for world updates.
Expand All @@ -32,7 +31,7 @@ struct Game {
}

impl Game {
fn new(pixels: Pixels, debug: bool) -> Self {
fn new(pixels: Pixels<'static>, debug: bool) -> Self {
Self {
pixels,
world: World::new(generate_seed(), debug),
Expand All @@ -59,11 +58,11 @@ impl Game {

self.controls = {
// Keyboard controls
let mut left = self.input.key_held(VirtualKeyCode::Left);
let mut right = self.input.key_held(VirtualKeyCode::Right);
let mut fire = self.input.key_pressed(VirtualKeyCode::Space);
let mut pause = self.input.key_pressed(VirtualKeyCode::Pause)
| self.input.key_pressed(VirtualKeyCode::P);
let mut left = self.input.key_held(KeyCode::ArrowLeft);
let mut right = self.input.key_held(KeyCode::ArrowRight);
let mut fire = self.input.key_pressed(KeyCode::Space);
let mut pause =
self.input.key_pressed(KeyCode::Pause) | self.input.key_pressed(KeyCode::KeyP);

// GamePad controls
if let Some(id) = self.gamepad {
Expand Down Expand Up @@ -103,7 +102,7 @@ impl Game {

fn main() -> Result<(), Error> {
env_logger::init();
let event_loop = EventLoop::new();
let event_loop = EventLoop::new().unwrap();

// Enable debug mode with `DEBUG=true` environment variable
let debug = env::var("DEBUG")
Expand All @@ -114,23 +113,25 @@ fn main() -> Result<(), Error> {
let window = {
let size = LogicalSize::new(WIDTH as f64, HEIGHT as f64);
let scaled_size = LogicalSize::new(WIDTH as f64 * 3.0, HEIGHT as f64 * 3.0);
WindowBuilder::new()
let window = WindowBuilder::new()
.with_title("pixel invaders")
.with_inner_size(scaled_size)
.with_min_inner_size(size)
.build(&event_loop)
.unwrap()
.unwrap();
Arc::new(window)
};

let pixels = {
let window_size = window.inner_size();
let surface_texture = SurfaceTexture::new(window_size.width, window_size.height, &window);
let surface_texture =
SurfaceTexture::new(window_size.width, window_size.height, Arc::clone(&window));
Pixels::new(WIDTH as u32, HEIGHT as u32, surface_texture)?
};

let game = Game::new(pixels, debug);

game_loop(
let res = game_loop(
event_loop,
window,
game,
Expand Down Expand Up @@ -164,15 +165,13 @@ fn main() -> Result<(), Error> {
g.game.update_controls();

// Close events
if g.game.input.key_pressed(VirtualKeyCode::Escape)
|| g.game.input.close_requested()
{
if g.game.input.key_pressed(KeyCode::Escape) || g.game.input.close_requested() {
g.exit();
return;
}

// Reset game
if g.game.input.key_pressed(VirtualKeyCode::R) {
if g.game.input.key_pressed(KeyCode::KeyR) {
g.game.reset_game();
}

Expand All @@ -186,6 +185,7 @@ fn main() -> Result<(), Error> {
}
},
);
res.map_err(|e| Error::UserDefined(Box::new(e)))
}

fn log_error<E: std::error::Error + 'static>(method_name: &str, err: E) {
Expand Down
10 changes: 5 additions & 5 deletions examples/minimal-egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ optimize = ["log/release_max_level_warn"]
default = ["optimize"]

[dependencies]
egui = "0.23"
egui-wgpu = "0.23"
egui-winit = { version = "0.23", default-features = false, features = ["links"] }
egui = "0.26"
egui-wgpu = "0.26.0"
egui-winit = { version = "0.26", default-features = false, features = ["links"] }
env_logger = "0.10"
error-iter = "0.4"
log = "0.4"
pixels = { path = "../.." }
winit = "0.28"
winit_input_helper = "0.14"
winit = "0.29"
winit_input_helper = "0.15"
Loading

0 comments on commit 07e169d

Please sign in to comment.