diff --git a/crates/fj-viewer/src/graphics/drawables.rs b/crates/fj-viewer/src/graphics/drawables.rs index 4c46f955d..40a0eb43f 100644 --- a/crates/fj-viewer/src/graphics/drawables.rs +++ b/crates/fj-viewer/src/graphics/drawables.rs @@ -5,13 +5,16 @@ use super::{ pub struct Drawables<'r> { pub model: Drawable<'r>, - pub mesh: Drawable<'r>, + pub mesh: Option>, } impl<'r> Drawables<'r> { pub fn new(geometries: &'r Geometries, pipelines: &'r Pipelines) -> Self { let model = Drawable::new(&geometries.mesh, &pipelines.model); - let mesh = Drawable::new(&geometries.mesh, &pipelines.mesh); + let mesh = pipelines + .mesh + .as_ref() + .map(|pipeline| Drawable::new(&geometries.mesh, pipeline)); Self { model, mesh } } diff --git a/crates/fj-viewer/src/graphics/pipelines.rs b/crates/fj-viewer/src/graphics/pipelines.rs index fb64e3cb8..4fb75dfa4 100644 --- a/crates/fj-viewer/src/graphics/pipelines.rs +++ b/crates/fj-viewer/src/graphics/pipelines.rs @@ -9,8 +9,7 @@ use super::{ #[derive(Debug)] pub struct Pipelines { pub model: Pipeline, - pub mesh: Pipeline, - pub lines: Pipeline, + pub mesh: Option, } impl Pipelines { @@ -18,6 +17,7 @@ impl Pipelines { device: &wgpu::Device, bind_group_layout: &wgpu::BindGroupLayout, color_format: wgpu::TextureFormat, + features: wgpu::Features, ) -> Self { let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -28,32 +28,32 @@ impl Pipelines { let shaders = Shaders::new(device); - Self { - model: Pipeline::new( - device, - &pipeline_layout, - shaders.model(), - wgpu::PrimitiveTopology::TriangleList, - wgpu::PolygonMode::Fill, - color_format, - ), - mesh: Pipeline::new( + let model = Pipeline::new( + device, + &pipeline_layout, + shaders.model(), + wgpu::PrimitiveTopology::TriangleList, + wgpu::PolygonMode::Fill, + color_format, + ); + + let mesh = if features.contains(wgpu::Features::POLYGON_MODE_LINE) { + // We need this feature, otherwise initializing the pipeline will + // panic. + + Some(Pipeline::new( device, &pipeline_layout, shaders.mesh(), wgpu::PrimitiveTopology::TriangleList, wgpu::PolygonMode::Line, color_format, - ), - lines: Pipeline::new( - device, - &pipeline_layout, - shaders.lines(), - wgpu::PrimitiveTopology::LineList, - wgpu::PolygonMode::Line, - color_format, - ), - } + )) + } else { + None + }; + + Self { model, mesh } } } diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index 02b68257e..9a65512df 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -20,7 +20,6 @@ use super::{ #[derive(Debug)] pub struct Renderer { surface: wgpu::Surface, - features: wgpu::Features, device: wgpu::Device, queue: wgpu::Queue, @@ -188,14 +187,13 @@ impl Renderer { let geometries = Geometries::new(&device, &Vertices::empty()); let pipelines = - Pipelines::new(&device, &bind_group_layout, color_format); + Pipelines::new(&device, &bind_group_layout, color_format, features); let navigation_cube_renderer = NavigationCubeRenderer::new(&device, &queue, &surface_config); Ok(Self { surface, - features, device, queue, @@ -311,8 +309,10 @@ impl Renderer { drawables.model.draw(&mut render_pass); } - if self.is_line_drawing_available() && config.draw_mesh { - drawables.mesh.draw(&mut render_pass); + if let Some(drawable) = drawables.mesh { + if config.draw_mesh { + drawable.draw(&mut render_pass); + } } } @@ -376,11 +376,6 @@ impl Renderer { texture.create_view(&wgpu::TextureViewDescriptor::default()) } - - /// 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-viewer/src/graphics/shader.wgsl b/crates/fj-viewer/src/graphics/shader.wgsl index 7a03144b1..d171ff502 100644 --- a/crates/fj-viewer/src/graphics/shader.wgsl +++ b/crates/fj-viewer/src/graphics/shader.wgsl @@ -56,10 +56,3 @@ fn frag_mesh(in: VertexOutput) -> FragmentOutput { out.color = vec4(1.0 - in.color.rgb, in.color.a); return out; } - -@fragment -fn frag_lines(in: VertexOutput) -> FragmentOutput { - var out: FragmentOutput; - out.color = vec4(in.color.rgb, in.color.a); - return out; -} diff --git a/crates/fj-viewer/src/graphics/shaders.rs b/crates/fj-viewer/src/graphics/shaders.rs index dc4aab79e..b228edfd2 100644 --- a/crates/fj-viewer/src/graphics/shaders.rs +++ b/crates/fj-viewer/src/graphics/shaders.rs @@ -28,13 +28,6 @@ impl Shaders { frag_entry: "frag_mesh", } } - - pub fn lines(&self) -> Shader { - Shader { - module: &self.0, - frag_entry: "frag_lines", - } - } } #[derive(Clone, Copy)] diff --git a/crates/fj-viewer/src/viewer.rs b/crates/fj-viewer/src/viewer.rs index 3f9ea1898..06a367592 100644 --- a/crates/fj-viewer/src/viewer.rs +++ b/crates/fj-viewer/src/viewer.rs @@ -47,9 +47,7 @@ impl Viewer { /// Toggle the "draw mesh" setting pub fn toggle_draw_mesh(&mut self) { - if self.renderer.is_line_drawing_available() { - self.draw_config.draw_mesh = !self.draw_config.draw_mesh; - } + self.draw_config.draw_mesh = !self.draw_config.draw_mesh; } /// Handle the model being updated