2022-12-04 10:32:10 +11:00
|
|
|
use std::any::Any;
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
#[non_exhaustive]
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum LibrashaderError {
|
|
|
|
#[error("The parameter was null or invalid.")]
|
|
|
|
InvalidParameter(&'static str),
|
|
|
|
#[error("The path was invalid.")]
|
|
|
|
InvalidPath(#[from] std::str::Utf8Error),
|
|
|
|
#[error("There was an error parsing the preset.")]
|
|
|
|
PresetError(#[from] librashader::presets::ParsePresetError),
|
|
|
|
#[error("There was an error preprocessing the shader source.")]
|
|
|
|
PreprocessError(#[from] librashader::preprocess::PreprocessError),
|
|
|
|
|
|
|
|
// #[cfg(feature = "runtime-opengl")]
|
|
|
|
#[error("There was an error in the OpenGL filter chain.")]
|
|
|
|
OpenGlFilterError(#[from] librashader::runtime::gl::error::FilterChainError),
|
|
|
|
#[error("There was an unknown error.")]
|
|
|
|
UnknownError(Box<dyn Any + Send + 'static>)
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LibrashaderError {
|
|
|
|
pub const fn ok() -> libra_error_t {
|
|
|
|
std::ptr::null()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn panic(panic: Box<dyn Any + Send + 'static>) -> libra_error_t {
|
|
|
|
LibrashaderError::UnknownError(panic).export()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn export(self) -> libra_error_t {
|
|
|
|
Box::into_raw(Box::new(self))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! assert_non_null {
|
|
|
|
($value:ident) => {
|
|
|
|
if $value.is_null() {
|
|
|
|
return $crate::error::LibrashaderError::InvalidParameter(stringify!($value)).export()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
macro_rules! assert_some {
|
|
|
|
($value:ident) => {
|
|
|
|
if $value.is_none() {
|
|
|
|
return $crate::error::LibrashaderError::InvalidParameter(stringify!($value)).export()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-04 11:55:27 +11:00
|
|
|
macro_rules! assert_some_ptr {
|
|
|
|
($value:ident) => {
|
|
|
|
if $value.is_none() {
|
|
|
|
return $crate::error::LibrashaderError::InvalidParameter(stringify!($value)).export()
|
|
|
|
}
|
|
|
|
|
|
|
|
let $value = unsafe { $value.as_ref().unwrap().as_ref() };
|
|
|
|
};
|
|
|
|
(mut $value:ident) => {
|
|
|
|
if $value.is_none() {
|
|
|
|
return $crate::error::LibrashaderError::InvalidParameter(stringify!($value)).export()
|
|
|
|
}
|
|
|
|
|
|
|
|
let $value = unsafe { $value.as_mut().unwrap().as_mut() };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-04 10:32:10 +11:00
|
|
|
pub(crate) use assert_non_null;
|
|
|
|
pub(crate) use assert_some;
|
2022-12-04 11:55:27 +11:00
|
|
|
pub(crate) use assert_some_ptr;
|
2022-12-04 10:32:10 +11:00
|
|
|
use crate::ctypes::libra_error_t;
|