Skip to content

Commit

Permalink
chore(cargo): update egui to 0.25 and wgpu to 0.29
Browse files Browse the repository at this point in the history
  • Loading branch information
maxjoehnk committed Jan 21, 2024
1 parent 0d13ed1 commit be5af64
Show file tree
Hide file tree
Showing 9 changed files with 366 additions and 251 deletions.
540 changes: 336 additions & 204 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/runtime/debug-ui/egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2021"

[dependencies]
anyhow = "1"
egui = "0.24"
egui-winit = "0.24"
egui-wgpu = { version = "0.24", features = ["winit"] }
winit = "0.28"
egui = "0.25"
egui-winit = "0.25"
egui-wgpu = { version = "0.25", features = ["winit"] }
winit = "0.29"
image = "0.24"
log = "0.4"
profiling = "1"
Expand Down
12 changes: 9 additions & 3 deletions crates/runtime/debug-ui/egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,16 @@ impl EguiDebugUi {
let events = self.window.get_events();
for event in events {
if self.egui_state.is_none() {
self.egui_state = Some(State::new(self.viewport_id, &self.window, None, None));
self.egui_state = Some(State::new(
self.egui_context.clone(),
self.viewport_id,
&self.window,
None,
None,
));
}
let state = self.egui_state.as_mut().unwrap();
let response = state.on_window_event(&self.egui_context, &event);
let response = state.on_window_event(&self.window, &event);
if response.repaint {
repaint = true;
}
Expand All @@ -105,7 +111,7 @@ impl EguiDebugUi {
fn paint(&mut self) {
if let Some(state) = self.egui_state.as_mut() {
let output = self.egui_context.end_frame();
state.handle_platform_output(&self.window, &self.egui_context, output.platform_output);
state.handle_platform_output(&self.window, output.platform_output);

let clipped_primitives = self
.egui_context
Expand Down
2 changes: 1 addition & 1 deletion crates/runtime/wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
wgpu = { version = "0.18", features = ["trace"] }
anyhow = "1"
winit = "0.28"
winit = "0.29"
bytemuck = { version = "1.14", features = ["derive"] }
raw-window-handle = "0.5"
log = "0.4"
Expand Down
10 changes: 5 additions & 5 deletions crates/runtime/wgpu/src/window/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ use crate::WgpuContext;

use super::{RawWindowRef, WindowRef};

pub(crate) type WindowEventSenders = DashMap<WindowId, Sender<WindowEvent<'static>>>;
pub(crate) type WindowEventSenders = DashMap<WindowId, Sender<WindowEvent>>;

pub struct EventLoopHandle {
pub(crate) event_loop: EventLoop<()>,
pub(crate) window_event_sender: WindowEventSenders,
}

impl EventLoopHandle {
pub fn new() -> Self {
pub fn new() -> anyhow::Result<Self> {
let mut builder = EventLoopBuilder::new();
#[cfg(target_os = "linux")]
builder.with_any_thread(true);
let event_loop = builder.build();
let event_loop = builder.build()?;

Self {
Ok(Self {
event_loop,
window_event_sender: DashMap::new(),
}
})
}

pub fn new_window(
Expand Down
2 changes: 1 addition & 1 deletion crates/runtime/wgpu/src/window/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl Module for WindowModule {

fn register(self, context: &mut impl ModuleContext) -> anyhow::Result<()> {
context.add_processor(WindowProcessor);
context.provide(EventLoopHandle::new());
context.provide(EventLoopHandle::new()?);

Ok(())
}
Expand Down
37 changes: 7 additions & 30 deletions crates/runtime/wgpu/src/window/processor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::time::Duration;

use winit::event::{Event, WindowEvent};
use winit::platform::run_return::EventLoopExtRunReturn;
use winit::platform::pump_events::EventLoopExtPumpEvents;
use winit::window::WindowId;

use mizer_module::{ClockFrame, DebuggableProcessor, Injector, Processor};
Expand All @@ -13,42 +15,17 @@ impl Processor for WindowProcessor {
let event_loop = injector.get_mut::<EventLoopHandle>().unwrap();
event_loop
.event_loop
.run_return(|event, _target, control_flow| match event {
Event::WindowEvent {
event:
winit::event::WindowEvent::ScaleFactorChanged {
new_inner_size: size,
..
},
window_id,
} => {
send_window_event(
&event_loop.window_event_sender,
window_id,
WindowEvent::Resized(*size),
);
control_flow.set_poll();
}
Event::WindowEvent { event, window_id } => {
send_window_event(
&event_loop.window_event_sender,
window_id,
event.to_static().unwrap(),
);
control_flow.set_poll();
.pump_events(Some(Duration::ZERO), |event, _target| {
if let Event::WindowEvent { event, window_id } = event {
send_window_event(&event_loop.window_event_sender, window_id, event);
}
_ => control_flow.set_exit(),
});
}
}

impl DebuggableProcessor for WindowProcessor {}

fn send_window_event(
window_events: &WindowEventSenders,
window_id: WindowId,
event: WindowEvent<'static>,
) {
fn send_window_event(window_events: &WindowEventSenders, window_id: WindowId, event: WindowEvent) {
if let Some(window) = window_events.get(&window_id) {
if let Err(err) = window.send(event) {
log::error!("Failed to send window event: {err:?}");
Expand Down
4 changes: 2 additions & 2 deletions crates/runtime/wgpu/src/window/raw_window_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use winit::event::WindowEvent;

pub struct RawWindowRef {
pub(crate) window: winit::window::Window,
pub(crate) events: Receiver<WindowEvent<'static>>,
pub(crate) events: Receiver<WindowEvent>,
}

impl Deref for RawWindowRef {
Expand All @@ -31,7 +31,7 @@ impl Drop for RawWindowRef {
}

impl RawWindowRef {
pub fn get_events(&mut self) -> Vec<WindowEvent<'static>> {
pub fn get_events(&mut self) -> Vec<WindowEvent> {
let mut events = Vec::new();
while let Ok(event) = self.events.try_recv() {
events.push(event);
Expand Down
2 changes: 1 addition & 1 deletion crates/runtime/wgpu/src/window/window_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct WindowRef {
pub(crate) window: winit::window::Window,
pub(crate) surface: wgpu::Surface,
pub(crate) surface_config: wgpu::SurfaceConfiguration,
pub(crate) events: Receiver<WindowEvent<'static>>,
pub(crate) events: Receiver<WindowEvent>,
}

impl Drop for WindowRef {
Expand Down

0 comments on commit be5af64

Please sign in to comment.