Skip to content

Commit

Permalink
Update project to work with wgpu 0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
sarchar authored and benmkw committed May 10, 2024
1 parent 798a498 commit 2b9a5c7
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 73 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Per Keep a Changelog there are 6 main categories of changes:
## Unreleased

- Internal: Fixed Scissor-Rect to not span across Framebuffersize, by limiting to framebuffer width. @PixelboysTM
- Bump wgpu version to 0.18. @calcoph
- Bump wgpu version to 0.19. @sarchar (changes based on @calcoph pull request)

## v0.24.0

Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ min = 0 # allow non-first increment

[dependencies]
bytemuck = "1"
imgui = "0.11"
imgui = { git = "https://github.com/imgui-rs/imgui-rs" }
log = "0.4"
smallvec = "1"
wgpu = "0.18"
wgpu = "0.19"

[dev-dependencies]
bytemuck = { version = "1.13", features = ["derive"] }
cgmath = "0.18"
env_logger = "0.10"
image = { version = "0.24", default-features = false, features = ["png"] }
imgui-winit-support = "0.11"
imgui-winit-support = { git = "https://github.com/imgui-rs/imgui-rs" }
pollster = "0.3"
raw-window-handle = "0.5"
winit = "0.27.5"
winit = "0.29"

[package.metadata.docs.rs]
all-features = true
48 changes: 26 additions & 22 deletions examples/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use std::time::Instant;
use wgpu::{include_wgsl, util::DeviceExt, Extent3d};
use winit::{
dpi::LogicalSize,
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event::{ElementState, Event, WindowEvent, KeyEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::{Key, NamedKey},
window::Window,
};

Expand Down Expand Up @@ -311,8 +312,8 @@ impl Example {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
timestamp_writes: None,
});
rpass.push_debug_group("Prepare data for draw.");
rpass.set_pipeline(&self.pipeline);
Expand All @@ -332,29 +333,27 @@ fn main() {
env_logger::init();

// Set up window and GPU
let event_loop = EventLoop::new();
let event_loop = EventLoop::new().expect("Error creating event loop");

let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::Backends::PRIMARY,
..Default::default()
});

let (window, size, surface) = {
let (window, size) = {
let version = env!("CARGO_PKG_VERSION");

let window = Window::new(&event_loop).unwrap();
window.set_inner_size(LogicalSize {
width: 1280.0,
height: 720.0,
});
let _ = window.request_inner_size(LogicalSize::new(1280.0, 720.0));
window.set_title(&format!("imgui-wgpu {version}"));
let size = window.inner_size();

let surface = unsafe { instance.create_surface(&window) }.unwrap();

(window, size, surface)
(window, size)
};

let surface = instance.create_surface(&window).unwrap();

let hidpi_factor = window.scale_factor();

let adapter = block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
Expand All @@ -376,6 +375,7 @@ fn main() {
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![wgpu::TextureFormat::Bgra8Unorm],
desired_maximum_frame_latency: 0,
};

surface.configure(&device, &surface_desc);
Expand Down Expand Up @@ -442,12 +442,12 @@ fn main() {
let texture = Texture::new(&device, &renderer, texture_config);
let example_texture_id = renderer.textures.insert(texture);

event_loop.set_control_flow(ControlFlow::Poll);

// Event loop
event_loop.run(move |event, _, control_flow| {
*control_flow = if cfg!(feature = "metal-auto-capture") {
ControlFlow::Exit
} else {
ControlFlow::Poll
let _ = event_loop.run(|event, elwt| {
if cfg!(feature = "metal-auto-capture") {
elwt.exit();
};
match event {
Event::WindowEvent {
Expand All @@ -462,16 +462,17 @@ fn main() {
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![wgpu::TextureFormat::Bgra8Unorm],
desired_maximum_frame_latency: 0,
};

surface.configure(&device, &surface_desc);
}
Event::WindowEvent {
event:
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Escape),
event:
KeyEvent {
logical_key: Key::Named(NamedKey::Escape),
state: ElementState::Pressed,
..
},
Expand All @@ -483,10 +484,13 @@ fn main() {
event: WindowEvent::CloseRequested,
..
} => {
*control_flow = ControlFlow::Exit;
elwt.exit();
}
Event::MainEventsCleared => window.request_redraw(),
Event::RedrawEventsCleared => {
Event::AboutToWait => window.request_redraw(),
Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
} => {
let now = Instant::now();
imgui.io_mut().update_delta_time(now - last_frame);
last_frame = now;
Expand Down Expand Up @@ -572,8 +576,8 @@ fn main() {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
timestamp_writes: None,
});

renderer
Expand Down
51 changes: 27 additions & 24 deletions examples/custom-texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,36 @@ use std::time::Instant;
use wgpu::Extent3d;
use winit::{
dpi::LogicalSize,
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event::{ElementState, Event, WindowEvent, KeyEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::{Key, NamedKey},
window::Window,
};

fn main() {
env_logger::init();

// Set up window and GPU
let event_loop = EventLoop::new();
let event_loop = EventLoop::new().expect("Error creating event loop");

let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::Backends::PRIMARY,
..Default::default()
});

let (window, size, surface) = {
let (window, size) = {
let version = env!("CARGO_PKG_VERSION");

let window = Window::new(&event_loop).unwrap();
window.set_inner_size(LogicalSize {
width: 1280.0,
height: 720.0,
});
let _ = window.request_inner_size(LogicalSize::new(1280.0, 720.0));
window.set_title(&format!("imgui-wgpu {version}"));
let size = window.inner_size();

let surface = unsafe { instance.create_surface(&window) }.unwrap();

(window, size, surface)
(window, size)
};

let surface = instance.create_surface(&window).unwrap();

let hidpi_factor = window.scale_factor();

let adapter = block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
Expand All @@ -50,8 +48,8 @@ fn main() {
let (device, queue) = block_on(adapter.request_device(
&wgpu::DeviceDescriptor {
label: None,
features: wgpu::Features::empty(),
limits: wgpu::Limits::default(),
required_features: wgpu::Features::empty(),
required_limits: wgpu::Limits::default(),
},
None,
))
Expand All @@ -66,6 +64,7 @@ fn main() {
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![wgpu::TextureFormat::Bgra8Unorm],
desired_maximum_frame_latency: 0,
};

surface.configure(&device, &surface_desc);
Expand Down Expand Up @@ -136,12 +135,12 @@ fn main() {

let mut last_cursor = None;

event_loop.set_control_flow(ControlFlow::Poll);

// Event loop
event_loop.run(move |event, _, control_flow| {
*control_flow = if cfg!(feature = "metal-auto-capture") {
ControlFlow::Exit
} else {
ControlFlow::Poll
let _ = event_loop.run(|event, elwt| {
if cfg!(feature = "metal-auto-capture") {
elwt.exit();
};
match event {
Event::WindowEvent {
Expand All @@ -156,16 +155,17 @@ fn main() {
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![wgpu::TextureFormat::Bgra8Unorm],
desired_maximum_frame_latency: 0,
};

surface.configure(&device, &surface_desc);
}
Event::WindowEvent {
event:
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Escape),
event:
KeyEvent {
logical_key: Key::Named(NamedKey::Escape),
state: ElementState::Pressed,
..
},
Expand All @@ -177,12 +177,15 @@ fn main() {
event: WindowEvent::CloseRequested,
..
} => {
*control_flow = ControlFlow::Exit;
elwt.exit();
}
Event::MainEventsCleared => {
Event::AboutToWait => {
window.request_redraw();
}
Event::RedrawEventsCleared => {
Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
} => {
let now = Instant::now();
imgui.io_mut().update_delta_time(now - last_frame);
last_frame = now;
Expand Down Expand Up @@ -233,8 +236,8 @@ fn main() {
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
timestamp_writes: None,
});

renderer
Expand Down
Loading

0 comments on commit 2b9a5c7

Please sign in to comment.