From 82c1b7547520cb380b241c144885059d60933ed4 Mon Sep 17 00:00:00 2001 From: Anand Thamban Date: Wed, 3 Aug 2022 23:48:15 -0500 Subject: [PATCH] Disable mesh and debug rendering checkboxes if line drawing is unavailable --- crates/fj-viewer/src/graphics/renderer.rs | 20 ++++++++++++++++---- crates/fj-window/src/run.rs | 8 ++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index c73e6d0ee..cd2179e46 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -424,16 +424,23 @@ impl Renderer { info } + let line_drawing_available = self.is_line_drawing_available(); egui::SidePanel::left("fj-left-panel").show(&self.egui.context, |ui| { ui.add_space(16.0); ui.group(|ui| { ui.checkbox(&mut config.draw_model, "Render model") .on_hover_text_at_pointer("Toggle with 1"); - ui.checkbox(&mut config.draw_mesh, "Render mesh") - .on_hover_text_at_pointer("Toggle with 2"); - ui.checkbox(&mut config.draw_debug, "Render debug") - .on_hover_text_at_pointer("Toggle with 3"); + ui.add_enabled(line_drawing_available, egui::Checkbox::new(&mut config.draw_mesh, "Render mesh")) + .on_hover_text_at_pointer("Toggle with 2") + .on_disabled_hover_text( + "Rendering device does not have line rendering feature support", + ); + ui.add_enabled(line_drawing_available, egui::Checkbox::new(&mut config.draw_debug, "Render debug")) + .on_hover_text_at_pointer("Toggle with 3") + .on_disabled_hover_text( + "Rendering device does not have line rendering feature support" + ); ui.checkbox( &mut self.egui.options.show_original_ui, "Render original UI", @@ -636,6 +643,11 @@ impl Renderer { ), }); } + + /// Returns true if the renderer's adapter can draw lines + pub fn is_line_drawing_available(&self) -> bool { + self.features.contains(wgpu::Features::POLYGON_MODE_LINE) + } } /// Error describing the set of render surface initialization errors diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index 67071390a..4264a48a4 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -137,10 +137,14 @@ pub fn run( draw_config.draw_model = !draw_config.draw_model } VirtualKeyCode::Key2 => { - draw_config.draw_mesh = !draw_config.draw_mesh + if renderer.is_line_drawing_available() { + draw_config.draw_mesh = !draw_config.draw_mesh + } } VirtualKeyCode::Key3 => { - draw_config.draw_debug = !draw_config.draw_debug + if renderer.is_line_drawing_available() { + draw_config.draw_debug = !draw_config.draw_debug + } } _ => {} },