Skip to content

Commit

Permalink
Add DeviceError
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Sep 29, 2023
1 parent 0452802 commit f8bcfd4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
10 changes: 9 additions & 1 deletion crates/fj-viewer/src/graphics/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Device {
impl Device {
pub async fn new(
adapter: &wgpu::Adapter,
) -> Result<(Self, wgpu::Features), wgpu::RequestDeviceError> {
) -> Result<(Self, wgpu::Features), DeviceError> {
let features = {
let desired_features = wgpu::Features::POLYGON_MODE_LINE;
let available_features = adapter.features();
Expand Down Expand Up @@ -49,3 +49,11 @@ impl Device {
Ok((Device { device, queue }, features))
}
}

/// Render device initialization error
#[derive(Debug, thiserror::Error)]
pub enum DeviceError {
/// Failed to request device
#[error("Failed to request device")]
RequestDevice(#[from] wgpu::RequestDeviceError),
}
1 change: 1 addition & 0 deletions crates/fj-viewer/src/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod uniforms;
mod vertices;

pub use self::{
device::DeviceError,
draw_config::DrawConfig,
renderer::{DrawError, Renderer, RendererInitError},
};
Expand Down
10 changes: 4 additions & 6 deletions crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{
device::Device, draw_config::DrawConfig, drawables::Drawables,
geometries::Geometries, navigation_cube::NavigationCubeRenderer,
pipelines::Pipelines, transform::Transform, uniforms::Uniforms,
vertices::Vertices, DEPTH_FORMAT, SAMPLE_COUNT,
vertices::Vertices, DeviceError, DEPTH_FORMAT, SAMPLE_COUNT,
};

/// Graphics rendering state and target abstraction
Expand Down Expand Up @@ -378,11 +378,9 @@ pub enum RendererInitError {
#[error("Error request adapter")]
RequestAdapter,

/// Device request errors
///
/// See: [wgpu::RequestDeviceError](https://docs.rs/wgpu/latest/wgpu/struct.RequestDeviceError.html)
#[error("Error requesting device")]
RequestDevice(#[from] wgpu::RequestDeviceError),
/// Device error
#[error(transparent)]
Device(#[from] DeviceError),
}

/// Draw error
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod screen;
mod viewer;

pub use self::{
graphics::RendererInitError,
graphics::{DeviceError, RendererInitError},
input::InputEvent,
screen::{NormalizedScreenPosition, Screen, ScreenSize},
viewer::Viewer,
Expand Down

0 comments on commit f8bcfd4

Please sign in to comment.