Create general SwapBuffersError

This commit is contained in:
Victor Brekenfeld 2018-11-21 09:33:33 +01:00
parent bbf28655d1
commit ccc7abc94f
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,46 @@
use std::fmt;
use std::error::Error;
/// Error that can happen when swapping buffers.
#[derive(Debug, Clone, PartialEq)]
pub enum SwapBuffersError {
/// The corresponding context has been lost and needs to be recreated.
///
/// All the objects associated to it (textures, buffers, programs, etc.)
/// need to be recreated from scratch.
///
/// Operations will have no effect. Functions that read textures, buffers, etc.
/// will return uninitialized data instead.
ContextLost,
/// The buffers have already been swapped.
///
/// This error can be returned when `swap_buffers` has been called multiple times
/// without any modification in between.
AlreadySwapped,
/// Unknown error
Unknown(u32),
}
impl fmt::Display for SwapBuffersError {
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use std::error::Error;
write!(formatter, "{}", self.description())
}
}
impl Error for SwapBuffersError {
fn description(&self) -> &str {
match *self {
SwapBuffersError::ContextLost => "The context has been lost, it needs to be recreated",
SwapBuffersError::AlreadySwapped => {
"Buffers are already swapped, swap_buffers was called too many times"
}
SwapBuffersError::Unknown(_) => "Unknown error occurred",
}
}
fn cause(&self) -> Option<&Error> {
None
}
}

View File

@ -2,6 +2,8 @@
//! //!
//! Note: Not every API may be supported by every backend //! Note: Not every API may be supported by every backend
mod errors;
pub use self::errors::*;
mod cursor; mod cursor;
pub use self::cursor::*; pub use self::cursor::*;