1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::fmt;
use crate::{error::Error, render::graph::RenderGraphError};
#[derive(Debug)]
pub enum RenderError {
Surface(wgpu::SurfaceError),
Graph(RenderGraphError),
Device(wgpu::RequestDeviceError),
}
impl fmt::Display for RenderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RenderError::Surface(e) => write!(f, "{}", e),
RenderError::Graph(e) => write!(f, "{:?}", e),
RenderError::Device(e) => write!(f, "{}", e),
}
}
}
impl RenderError {
pub fn should_exit(&self) -> bool {
match self {
RenderError::Surface(e) => match e {
wgpu::SurfaceError::OutOfMemory => true,
_ => false,
},
_ => true,
}
}
}
impl From<RenderGraphError> for RenderError {
fn from(e: RenderGraphError) -> Self {
RenderError::Graph(e)
}
}
impl From<wgpu::SurfaceError> for Error {
fn from(e: wgpu::SurfaceError) -> Self {
Error::Render(RenderError::Surface(e))
}
}
impl From<wgpu::RequestDeviceError> for Error {
fn from(e: wgpu::RequestDeviceError) -> Self {
Error::Render(RenderError::Device(e))
}
}