Skip to content

Commit

Permalink
Merge pull request #902 from hekno25/main
Browse files Browse the repository at this point in the history
Store and check adapter features before using them
  • Loading branch information
hannobraun authored Aug 2, 2022
2 parents 506dc9c + 13a0606 commit 7d6e84b
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl std::fmt::Debug for EguiState {
#[derive(Debug)]
pub struct Renderer {
surface: wgpu::Surface,
features: wgpu::Features,
device: wgpu::Device,
queue: wgpu::Queue,

Expand Down Expand Up @@ -134,6 +135,8 @@ impl Renderer {
.await
.ok_or(InitError::RequestAdapter)?;

let features = adapter.features();

let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
Expand All @@ -144,7 +147,7 @@ impl Renderer {
//
// See this issue:
// https://github.com/hannobraun/fornjot/issues/33
features: wgpu::Features::POLYGON_MODE_LINE,
features,
limits: wgpu::Limits::default(),
},
None,
Expand Down Expand Up @@ -239,6 +242,7 @@ impl Renderer {

Ok(Self {
surface,
features,
device,
queue,

Expand Down Expand Up @@ -328,21 +332,26 @@ impl Renderer {
&self.bind_group,
);
}
if config.draw_mesh {
drawables.mesh.draw(
&mut encoder,
&color_view,
&self.depth_view,
&self.bind_group,
);
}
if config.draw_debug {
drawables.lines.draw(
&mut encoder,
&color_view,
&self.depth_view,
&self.bind_group,
);

// NOTE: This does not inform the user if the renderer cannot
// use the POLYGON_MODE_LINE feature.
if self.features.contains(wgpu::Features::POLYGON_MODE_LINE) {
if config.draw_mesh {
drawables.mesh.draw(
&mut encoder,
&color_view,
&self.depth_view,
&self.bind_group,
);
}
if config.draw_debug {
drawables.lines.draw(
&mut encoder,
&color_view,
&self.depth_view,
&self.bind_group,
);
}
}

if self.egui.options.show_original_ui {
Expand Down

0 comments on commit 7d6e84b

Please sign in to comment.