veloren_voxygen/render/
error.rs

1/// Used to represent one of many possible errors that may be omitted by the
2/// rendering subsystem.
3pub enum RenderError {
4    RequestDeviceError(wgpu::RequestDeviceError),
5    MappingError(wgpu::BufferAsyncError),
6    SurfaceError(wgpu::SurfaceError),
7    CustomError(String),
8    CouldNotFindAdapter,
9    ErrorInitializingCompiler,
10    ShaderError(String, shaderc::Error),
11}
12
13use std::fmt;
14impl fmt::Debug for RenderError {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            Self::RequestDeviceError(err) => {
18                f.debug_tuple("RequestDeviceError").field(err).finish()
19            },
20            Self::MappingError(err) => f.debug_tuple("MappingError").field(err).finish(),
21            Self::SurfaceError(err) => f
22                .debug_tuple("SurfaceError")
23                // Use Display formatting for this error since they have nice descriptions
24                .field(&format!("{}", err))
25                .finish(),
26            Self::CustomError(err) => f.debug_tuple("CustomError").field(err).finish(),
27            Self::CouldNotFindAdapter => f.debug_tuple("CouldNotFindAdapter").finish(),
28            Self::ErrorInitializingCompiler => f.debug_tuple("ErrorInitializingCompiler").finish(),
29            Self::ShaderError(shader_name, err) => write!(
30                f,
31                "\"{shader_name}\" shader failed to compile due to the following error: {err}",
32            ),
33        }
34    }
35}
36
37impl From<wgpu::RequestDeviceError> for RenderError {
38    fn from(err: wgpu::RequestDeviceError) -> Self { Self::RequestDeviceError(err) }
39}
40
41impl From<wgpu::BufferAsyncError> for RenderError {
42    fn from(err: wgpu::BufferAsyncError) -> Self { Self::MappingError(err) }
43}
44
45impl From<wgpu::SurfaceError> for RenderError {
46    fn from(err: wgpu::SurfaceError) -> Self { Self::SurfaceError(err) }
47}
48
49impl From<(&str, shaderc::Error)> for RenderError {
50    fn from((shader_name, err): (&str, shaderc::Error)) -> Self {
51        Self::ShaderError(shader_name.into(), err)
52    }
53}