Skip to content

Commit

Permalink
Update UI crates
Browse files Browse the repository at this point in the history
  • Loading branch information
branpk committed Mar 6, 2024
1 parent 6a7b976 commit 9b7356b
Show file tree
Hide file tree
Showing 28 changed files with 962 additions and 773 deletions.
699 changes: 419 additions & 280 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ opt-level = 3
debug = true

[workspace.dependencies]
wgpu = "0.17.0"
egui = "0.23.0"
egui-wgpu = "0.23.0"
egui-winit = "0.23.0"
wgpu = "0.19.3"
egui = "0.26.2"
egui-wgpu = "0.26.2"
egui-winit = "0.26.2"
egui_dock = "0.11.2"
winit = "0.29.13"
8 changes: 4 additions & 4 deletions wafel_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ edition = "2021"

[dependencies]
chrono = "0.4.29"
egui.workspace = true
egui-wgpu.workspace = true
egui-winit.workspace = true
egui = { workspace = true }
egui-wgpu = { workspace = true }
egui-winit = { workspace = true }
winit = { workspace = true }
image = "0.24.7"
once_cell = "1.18.0"
pollster = "0.3.0"
tracing = "0.1.37"
tracing-log = "0.1.3"
tracing-subscriber = "0.3.17"
wgpu = { workspace = true }
winit = "0.28.6"
wafel_app_ui = { path = "../wafel_app_ui" }
sysinfo = { version = "0.29.10", default-features = false }
wafel_viz_wgpu = { path = "../wafel_viz_wgpu" }
Expand Down
12 changes: 7 additions & 5 deletions wafel_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ impl WindowedApp for WafelApp {
}
}

fn window_event(&mut self, event: &WindowEvent<'_>) {
fn window_event(&mut self, window: &Window, event: &WindowEvent) {
if let Some(egui_state) = self.egui_state.lock().unwrap().as_mut() {
let consumed = egui_state.window_event(event);
let consumed = egui_state.window_event(window, event);
if !consumed {
// handle event
}
Expand Down Expand Up @@ -189,10 +189,11 @@ impl WafelApp {
resolve_target: Some(output_view),
ops: wgpu::Operations {
load: clear_op.take().unwrap_or(wgpu::LoadOp::Load),
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
..Default::default()
});

egui_state.render(&mut rp);
Expand Down Expand Up @@ -229,17 +230,18 @@ impl WafelApp {
resolve_target: Some(output_view),
ops: wgpu::Operations {
load: clear_op.take().unwrap_or(wgpu::LoadOp::Load),
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &depth_texture_view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: true,
store: wgpu::StoreOp::Store,
}),
stencil_ops: None,
}),
..Default::default()
});

self.viz_renderer.render(&mut rp);
Expand Down
24 changes: 16 additions & 8 deletions wafel_app/src/egui_state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;

use egui::{ClippedPrimitive, Context, TexturesDelta};
use egui_wgpu::{renderer::ScreenDescriptor, Renderer};
use egui_wgpu::{Renderer, ScreenDescriptor};
use egui_winit::State;
use winit::{event::WindowEvent, window::Window};

Expand All @@ -21,10 +21,16 @@ impl EguiState {
output_format: wgpu::TextureFormat,
msaa_samples: u32,
) -> Self {
let mut state = State::new(window);
state.set_pixels_per_point(window.scale_factor() as f32);
let context = Context::default();
let state = State::new(
context.clone(),
context.viewport_id(),
window,
Some(window.scale_factor() as f32),
None,
);
EguiState {
context: Context::default(),
context,
state,
renderer: Renderer::new(device, output_format, None, msaa_samples),
primitives: Vec::new(),
Expand All @@ -33,8 +39,8 @@ impl EguiState {
}
}

pub fn window_event(&mut self, event: &WindowEvent<'_>) -> bool {
let response = self.state.on_event(&self.context, event);
pub fn window_event(&mut self, window: &Window, event: &WindowEvent) -> bool {
let response = self.state.on_window_event(window, event);
if response.repaint {
self.context.request_repaint();
}
Expand All @@ -50,8 +56,10 @@ impl EguiState {
run_ui(ctx);
});
self.state
.handle_platform_output(window, &self.context, egui_output.platform_output);
self.primitives = self.context.tessellate(egui_output.shapes);
.handle_platform_output(window, egui_output.platform_output);
self.primitives = self
.context
.tessellate(egui_output.shapes, egui_output.pixels_per_point);
self.textures_delta = egui_output.textures_delta;
}

Expand Down
100 changes: 52 additions & 48 deletions wafel_app/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub trait WindowedApp: Sized + 'static {
msaa_samples: u32,
) -> Self;

fn window_event(&mut self, event: &WindowEvent<'_>);
fn window_event(&mut self, window: &Window, event: &WindowEvent);

fn update(&mut self, window: &Window, device: &wgpu::Device);

Expand All @@ -43,7 +43,7 @@ pub fn run_app<A: WindowedApp>(env: WafelEnv, title: &str) {
..Default::default()
});

let event_loop = EventLoop::new();
let event_loop = EventLoop::new().expect("failed to create event loop");
let max_screen_dim = event_loop
.available_monitors()
.flat_map(|m| [m.size().width, m.size().height])
Expand All @@ -66,8 +66,9 @@ pub fn run_app<A: WindowedApp>(env: WafelEnv, title: &str) {
window.set_window_level(WindowLevel::AlwaysOnTop); // TODO: Add config option
}

let surface =
unsafe { instance.create_surface(&window) }.expect("failed to create surface");
let surface = instance
.create_surface(&window)
.expect("failed to create surface");
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
Expand All @@ -90,8 +91,8 @@ pub fn run_app<A: WindowedApp>(env: WafelEnv, title: &str) {
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features: wgpu::Features::empty(),
limits: wgpu::Limits {
required_features: wgpu::Features::empty(),
required_limits: wgpu::Limits {
max_texture_dimension_2d,
..wgpu::Limits::downlevel_webgl2_defaults()
},
Expand Down Expand Up @@ -124,6 +125,7 @@ pub fn run_app<A: WindowedApp>(env: WafelEnv, title: &str) {
present_mode,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: Vec::new(),
desired_maximum_frame_latency: 2,
};
surface.configure(&device, &surface_config);

Expand All @@ -139,64 +141,66 @@ pub fn run_app<A: WindowedApp>(env: WafelEnv, title: &str) {
window.set_visible(true);
let mut first_render = false;

event_loop.run(move |event, _, control_flow| {
// Since event_loop.run never returns, we should move all Drop objects
// into this closure. These ones aren't referenced elsewhere in the
// closure, so we reference them explicitly here.
let _ = (&instance, &adapter);
let window = &window;

*control_flow = ControlFlow::Poll;
event_loop
.run(move |event, event_loop| {
// Since event_loop.run never returns, we should move all Drop objects
// into this closure. These ones aren't referenced elsewhere in the
// closure, so we reference them explicitly here.
let _ = (&instance, &adapter);

match event {
Event::WindowEvent { event, .. } => {
app.window_event(&event);
if let Event::WindowEvent { event, .. } = event {
app.window_event(window, &event);
match event {
WindowEvent::Resized(size) => {
surface_config.width = size.width;
surface_config.height = size.height;
if surface_config.width > 0 && surface_config.height > 0 {
surface.configure(&device, &surface_config);
}
window.request_redraw();
}
WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
event_loop.exit();
}
_ => {}
}
}
Event::MainEventsCleared => {
if !first_render {
app.update(&window, &device);
}
WindowEvent::RedrawRequested => {
if !first_render {
app.update(window, &device);
}

if surface_config.width != 0 && surface_config.height != 0 {
let frame = surface
.get_current_texture()
.expect("failed to acquire next swap chain texture");
let output_view = frame
.texture
.create_view(&wgpu::TextureViewDescriptor::default());

if first_render {
// Draw a black screen as quickly as possible
first_render = false;
} else {
app.render(
&device,
&queue,
&output_view,
output_format,
[surface_config.width, surface_config.height],
window.scale_factor() as f32,
);
}
if surface_config.width != 0 && surface_config.height != 0 {
let frame = surface
.get_current_texture()
.expect("failed to acquire next swap chain texture");
let output_view = frame
.texture
.create_view(&wgpu::TextureViewDescriptor::default());

if first_render {
// Draw a black screen as quickly as possible
first_render = false;
} else {
app.render(
&device,
&queue,
&output_view,
output_format,
[surface_config.width, surface_config.height],
window.scale_factor() as f32,
);
}

frame.present();
}

frame.present();
window.request_redraw();
}
_ => {}
}
}
_ => {}
}
});
})
.expect("event loop error");
});
}

Expand Down
4 changes: 2 additions & 2 deletions wafel_app_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
egui.workspace = true
egui_dock = "0.8.1"
egui = { workspace = true }
egui_dock = { workspace = true }
itertools = "0.11.0"
log = "0.4.20"
once_cell = "1.18.0"
Expand Down
2 changes: 2 additions & 0 deletions wafel_app_ui/src/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use wafel_api::{Emu, VizScene};

use crate::{data_explorer::DataExplorer, pane::Pane, Env};
Expand Down
2 changes: 1 addition & 1 deletion wafel_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ indexmap = "1.6.2"
serde = { version = "1.0.126", features = ["derive", "rc"] }
wgpu = { workspace = true }
futures = "0.3.15"
winit = "0.28.6"
winit = { workspace = true }
bytemuck = "1.5.1"
nalgebra = "0.31.0"
image = "0.23.14"
Expand Down
3 changes: 2 additions & 1 deletion wafel_core/src/graphics/imgui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,11 @@ impl ImguiRenderer {
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
..Default::default()
});

render_pass.set_pipeline(&self.pipeline);
Expand Down
5 changes: 3 additions & 2 deletions wafel_core/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,18 @@ impl Renderer {
b: 0.06,
a: 1.0,
}),
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &depth_texture_view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: true,
store: wgpu::StoreOp::Store,
}),
stencil_ops: None,
}),
..Default::default()
});

for (scene, bundle) in scenes.iter().zip(&scene_bundles) {
Expand Down
5 changes: 3 additions & 2 deletions wafel_core/src/graphics/viz_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ impl VizContainer {
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &depth_texture_view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: true,
store: wgpu::StoreOp::Store,
}),
stencil_ops: None,
}),
..Default::default()
});

self.renderer.render(&mut rp);
Expand Down
Loading

0 comments on commit 9b7356b

Please sign in to comment.