fyrox_graphics/error.rs
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
// Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//! Contains all possible errors that may occur during rendering, initialization of
//! renderer structures, or GAPI.
use std::{
error::Error,
ffi::NulError,
fmt::{Display, Formatter},
};
/// Set of possible renderer errors.
#[derive(Debug)]
pub enum FrameworkError {
/// Compilation of a shader has failed.
ShaderCompilationFailed {
/// Name of shader.
shader_name: String,
/// Compilation error message.
error_message: String,
},
/// Means that shader link stage failed, exact reason is inside `error_message`
ShaderLinkingFailed {
/// Name of shader.
shader_name: String,
/// Linking error message.
error_message: String,
},
/// Shader source contains invalid characters.
FaultyShaderSource,
/// There is no such shader uniform (could be optimized out).
UnableToFindShaderUniform(String),
/// There is no such shader uniform block.
UnableToFindShaderUniformBlock(String),
/// Texture has invalid data - insufficient size.
InvalidTextureData {
/// Expected data size in bytes.
expected_data_size: usize,
/// Actual data size in bytes.
actual_data_size: usize,
},
/// None variant was passed as texture data, but engine does not support it.
EmptyTextureData,
/// Means that you tried to draw element range from GeometryBuffer that
/// does not have enough elements.
InvalidElementRange {
/// First index.
start: usize,
/// Last index.
end: usize,
/// Total amount of triangles.
total: usize,
},
/// Means that attribute descriptor tries to define an attribute that does
/// not exists in vertex, or it does not match size. For example you have vertex:
/// pos: float2,
/// normal: float3
/// But you described second attribute as Float4, then you'll get this error.
InvalidAttributeDescriptor,
/// Framebuffer is invalid.
InvalidFrameBuffer,
/// OpenGL failed to construct framebuffer.
FailedToConstructFBO,
/// Custom error. Usually used for internal errors.
Custom(String),
/// Graphics server disconnected.
GraphicsServerUnavailable,
}
impl Display for FrameworkError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
FrameworkError::ShaderCompilationFailed {
shader_name,
error_message,
} => {
write!(
f,
"Compilation of \"{shader_name}\" shader has failed: {error_message}",
)
}
FrameworkError::ShaderLinkingFailed {
shader_name,
error_message,
} => {
write!(
f,
"Linking shader \"{shader_name}\" failed: {error_message}",
)
}
FrameworkError::FaultyShaderSource => {
write!(f, "Shader source contains invalid characters")
}
FrameworkError::UnableToFindShaderUniform(v) => {
write!(f, "There is no such shader uniform: {v}")
}
FrameworkError::UnableToFindShaderUniformBlock(v) => {
write!(f, "There is no such shader uniform block: {v}")
}
FrameworkError::InvalidTextureData {
expected_data_size,
actual_data_size,
} => {
write!(
f,
"Texture has invalid data (insufficent size): \
expected {expected_data_size}, actual: {actual_data_size}",
)
}
FrameworkError::EmptyTextureData => {
write!(
f,
"None variant was passed as texture data, but engine does not support it."
)
}
FrameworkError::InvalidElementRange { start, end, total } => {
write!(
f,
"Tried to draw element from GeometryBuffer that does not have enough \
elements: start: {start}, end: {end}, total: {total}",
)
}
FrameworkError::InvalidAttributeDescriptor => {
write!(
f,
"An attribute descriptor tried to define an attribute that \
does not exist in vertex or doesn't match size."
)
}
FrameworkError::InvalidFrameBuffer => {
write!(f, "Framebuffer is invalid")
}
FrameworkError::FailedToConstructFBO => {
write!(f, "OpenGL failed to construct framebuffer.")
}
FrameworkError::Custom(v) => {
write!(f, "Custom error: {v}")
}
FrameworkError::GraphicsServerUnavailable => {
write!(f, "Graphics server disconnected.")
}
}
}
}
impl From<NulError> for FrameworkError {
fn from(_: NulError) -> Self {
Self::FaultyShaderSource
}
}
#[cfg(not(target_arch = "wasm32"))]
impl From<glutin::error::Error> for FrameworkError {
fn from(err: glutin::error::Error) -> Self {
Self::Custom(format!("{err:?}"))
}
}
impl From<String> for FrameworkError {
fn from(v: String) -> Self {
Self::Custom(v)
}
}
impl From<Box<dyn Error>> for FrameworkError {
fn from(e: Box<dyn Error>) -> Self {
Self::Custom(format!("{e:?}"))
}
}