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 project to work with wgpu 0.19 #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +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.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.17"
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
52 changes: 30 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 @@ -307,10 +308,12 @@ impl Example {
b: 0.3,
a: 1.0,
}),
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
occlusion_query_set: None,
timestamp_writes: None,
});
rpass.push_debug_group("Prepare data for draw.");
rpass.set_pipeline(&self.pipeline);
Expand All @@ -330,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 @@ -374,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 @@ -440,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 @@ -460,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 @@ -481,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 @@ -566,10 +572,12 @@ fn main() {
ops: wgpu::Operations {
load: wgpu::LoadOp::Load, // Do not clear
// load: wgpu::LoadOp::Clear(clear_color),
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
occlusion_query_set: None,
timestamp_writes: None,
});

renderer
Expand Down
53 changes: 29 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 @@ -229,10 +232,12 @@ fn main() {
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(clear_color),
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
occlusion_query_set: None,
timestamp_writes: None,
});

renderer
Expand Down
Loading
Loading