aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/wgl/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/wgl/mod.rs')
-rw-r--r--src/api/wgl/mod.rs69
1 files changed, 55 insertions, 14 deletions
diff --git a/src/api/wgl/mod.rs b/src/api/wgl/mod.rs
index d1f42d2..cf09ad0 100644
--- a/src/api/wgl/mod.rs
+++ b/src/api/wgl/mod.rs
@@ -1,11 +1,13 @@
#![cfg(any(target_os = "windows"))]
use BuilderAttribs;
+use ContextError;
use CreationError;
use GlContext;
use GlRequest;
use GlProfile;
use PixelFormat;
+use Robustness;
use Api;
use self::make_current_guard::CurrentContextGuard;
@@ -130,9 +132,7 @@ impl Context {
// handling vsync
if builder.vsync {
- // contrary to most extensions, it is permitted to discover the presence of
- // `WGL_EXT_swap_control` by seeing if the function pointer is available
- if extra_functions.SwapIntervalEXT.is_loaded() {
+ if extensions.split(' ').find(|&i| i == "WGL_EXT_swap_control").is_some() {
let _guard = try!(CurrentContextGuard::make_current(hdc, context.0));
if extra_functions.SwapIntervalEXT(1) == 0 {
@@ -156,9 +156,12 @@ impl Context {
}
impl GlContext for Context {
- unsafe fn make_current(&self) {
- // TODO: check return value
- gl::wgl::MakeCurrent(self.hdc as *const _, self.context.0 as *const _);
+ unsafe fn make_current(&self) -> Result<(), ContextError> {
+ if gl::wgl::MakeCurrent(self.hdc as *const _, self.context.0 as *const _) != 0 {
+ Ok(())
+ } else {
+ Err(ContextError::IoError(io::Error::last_os_error()))
+ }
}
fn is_current(&self) -> bool {
@@ -176,10 +179,15 @@ impl GlContext for Context {
}
}
- fn swap_buffers(&self) {
- unsafe {
- gdi32::SwapBuffers(self.hdc);
- }
+ fn swap_buffers(&self) -> Result<(), ContextError> {
+ // TODO: decide how to handle the error
+ /*if unsafe { gdi32::SwapBuffers(self.hdc) } != 0 {
+ Ok(())
+ } else {
+ Err(ContextError::IoError(io::Error::last_os_error()))
+ }*/
+ unsafe { gdi32::SwapBuffers(self.hdc) };
+ Ok(())
}
fn get_api(&self) -> Api {
@@ -260,10 +268,43 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
}
}
- if builder.gl_debug {
- attributes.push(gl::wgl_extra::CONTEXT_FLAGS_ARB as libc::c_int);
- attributes.push(gl::wgl_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int);
- }
+ let flags = {
+ let mut flags = 0;
+
+ // robustness
+ if extensions.split(' ').find(|&i| i == "WGL_ARB_create_context_robustness").is_some() {
+ match builder.gl_robustness {
+ Robustness::RobustNoResetNotification | Robustness::TryRobustNoResetNotification => {
+ attributes.push(gl::wgl_extra::CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB as libc::c_int);
+ attributes.push(gl::wgl_extra::NO_RESET_NOTIFICATION_ARB as libc::c_int);
+ flags = flags | gl::wgl_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as libc::c_int;
+ },
+ Robustness::RobustLoseContextOnReset | Robustness::TryRobustLoseContextOnReset => {
+ attributes.push(gl::wgl_extra::CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB as libc::c_int);
+ attributes.push(gl::wgl_extra::LOSE_CONTEXT_ON_RESET_ARB as libc::c_int);
+ flags = flags | gl::wgl_extra::CONTEXT_ROBUST_ACCESS_BIT_ARB as libc::c_int;
+ },
+ Robustness::NotRobust => (),
+ Robustness::NoError => (),
+ }
+ } else {
+ match builder.gl_robustness {
+ Robustness::RobustNoResetNotification | Robustness::RobustLoseContextOnReset => {
+ return Err(CreationError::NotSupported);
+ },
+ _ => ()
+ }
+ }
+
+ if builder.gl_debug {
+ flags = flags | gl::wgl_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int;
+ }
+
+ flags
+ };
+
+ attributes.push(gl::wgl_extra::CONTEXT_FLAGS_ARB as libc::c_int);
+ attributes.push(flags);
attributes.push(0);