From f6c26ec593ba96d89cb3476c815d6f33a915bfdd Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 16 Jun 2015 10:15:31 +0200 Subject: Handle errors from MakeCurrent and SwapBuffers --- src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 784ea95..b567916 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,6 +63,8 @@ pub use window::{AvailableMonitorsIter, MonitorID, get_available_monitors, get_p #[cfg(feature = "window")] pub use native_monitor::NativeMonitorId; +use std::io; + mod api; mod platform; mod events; @@ -73,7 +75,7 @@ mod window; /// Trait that describes objects that have access to an OpenGL context. pub trait GlContext { /// Sets the context as the current context. - unsafe fn make_current(&self); + unsafe fn make_current(&self) -> Result<(), ContextError>; /// Returns true if this context is the current one in this thread. fn is_current(&self) -> bool; @@ -84,12 +86,12 @@ pub trait GlContext { /// Swaps the buffers in case of double or triple buffering. /// /// You should call this function every time you have finished rendering, or the image - /// may not be displayed on the screen. + /// may not be displayed on the screen. /// /// **Warning**: if you enabled vsync, this function will block until the next time the screen /// is refreshed. However drivers can choose to override your vsync settings, which means that /// you can't know in advance whether `swap_buffers` will block or not. - fn swap_buffers(&self); + fn swap_buffers(&self) -> Result<(), ContextError>; /// Returns the OpenGL API being used. fn get_api(&self) -> Api; @@ -126,6 +128,13 @@ impl std::error::Error for CreationError { } } +/// Error that can happen when manipulating an OpenGL context. +#[derive(Debug)] +pub enum ContextError { + IoError(io::Error), + ContextLost, +} + /// All APIs related to OpenGL that you can possibly get while using glutin. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Api { -- cgit v1.2.3