diff options
author | tomaka <pierre.krieger1708@gmail.com> | 2015-05-21 18:15:20 +0200 |
---|---|---|
committer | tomaka <pierre.krieger1708@gmail.com> | 2015-05-21 18:15:20 +0200 |
commit | e606281862dfd016051e2ee66e67eddb71c6d0ac (patch) | |
tree | 14673f9745e4760e5e93412a5126d229828ec7de /src/api/win32/make_current_guard.rs | |
parent | b72ac990e67771ca8c256859ce3fc472458becd9 (diff) | |
parent | ea17038ac2a25982ffc8e9308eec312864938d20 (diff) | |
download | glutin-e606281862dfd016051e2ee66e67eddb71c6d0ac.tar.gz glutin-e606281862dfd016051e2ee66e67eddb71c6d0ac.zip |
Merge pull request #458 from tomaka/detach-wgl
Detach wgl and win32
Diffstat (limited to 'src/api/win32/make_current_guard.rs')
-rw-r--r-- | src/api/win32/make_current_guard.rs | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/src/api/win32/make_current_guard.rs b/src/api/win32/make_current_guard.rs deleted file mode 100644 index 8983899..0000000 --- a/src/api/win32/make_current_guard.rs +++ /dev/null @@ -1,52 +0,0 @@ -use std::marker::PhantomData; -use std::io; - -use libc; -use winapi; -use CreationError; - -use super::gl; -use super::ContextWrapper; -use super::WindowWrapper; - -/// A guard for when you want to make the context current. Destroying the guard restores the -/// previously-current context. -pub struct CurrentContextGuard<'a, 'b> { - previous_hdc: winapi::HDC, - previous_hglrc: winapi::HGLRC, - marker1: PhantomData<&'a ()>, - marker2: PhantomData<&'b ()>, -} - -impl<'a, 'b> CurrentContextGuard<'a, 'b> { - pub unsafe fn make_current(window: &'a WindowWrapper, context: &'b ContextWrapper) - -> Result<CurrentContextGuard<'a, 'b>, CreationError> - { - let previous_hdc = gl::wgl::GetCurrentDC() as winapi::HDC; - let previous_hglrc = gl::wgl::GetCurrentContext() as winapi::HGLRC; - - let result = gl::wgl::MakeCurrent(window.1 as *const libc::c_void, - context.0 as *const libc::c_void); - - if result == 0 { - return Err(CreationError::OsError(format!("wglMakeCurrent function failed: {}", - format!("{}", io::Error::last_os_error())))); - } - - Ok(CurrentContextGuard { - previous_hdc: previous_hdc, - previous_hglrc: previous_hglrc, - marker1: PhantomData, - marker2: PhantomData, - }) - } -} - -impl<'a, 'b> Drop for CurrentContextGuard<'a, 'b> { - fn drop(&mut self) { - unsafe { - gl::wgl::MakeCurrent(self.previous_hdc as *const libc::c_void, - self.previous_hglrc as *const libc::c_void); - } - } -} |