From 689ace8b251ceb2446fc460aad3dd19a1692f3f8 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 4 Mar 2015 07:38:55 +0100 Subject: Add is_current function --- src/android/mod.rs | 9 +++++++++ src/cocoa/headless.rs | 4 ++++ src/cocoa/mod.rs | 4 ++++ src/headless.rs | 6 ++++++ src/win32/headless.rs | 5 +++++ src/win32/mod.rs | 5 +++++ src/window.rs | 6 ++++++ src/x11/headless.rs | 4 ++++ src/x11/window/mod.rs | 4 ++++ 9 files changed, 47 insertions(+) (limited to 'src') diff --git a/src/android/mod.rs b/src/android/mod.rs index 84d71c2..3c01b4c 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -61,6 +61,11 @@ impl HeadlessContext { unimplemented!() } + /// See the docs in the crate root file. + pub fn is_current(&self) -> bool { + unimplemented!() + } + /// See the docs in the crate root file. pub fn get_proc_address(&self, _addr: &str) -> *const () { unimplemented!() @@ -312,6 +317,10 @@ impl Window { } } + pub fn is_current(&self) -> bool { + unsafe { ffi::egl::GetCurrentContext() == self.context } + } + pub fn get_proc_address(&self, addr: &str) -> *const () { let addr = CString::from_slice(addr.as_bytes()); let addr = addr.as_ptr(); diff --git a/src/cocoa/headless.rs b/src/cocoa/headless.rs index fb91a0a..298027f 100644 --- a/src/cocoa/headless.rs +++ b/src/cocoa/headless.rs @@ -76,6 +76,10 @@ impl HeadlessContext { } } + pub fn is_current(&self) -> bool { + unimplemented!() + } + pub fn get_proc_address(&self, _addr: &str) -> *const () { let symbol_name: CFString = _addr.parse().unwrap(); let framework_name: CFString = "com.apple.opengl".parse().unwrap(); diff --git a/src/cocoa/mod.rs b/src/cocoa/mod.rs index e39df9f..9819319 100644 --- a/src/cocoa/mod.rs +++ b/src/cocoa/mod.rs @@ -587,6 +587,10 @@ impl Window { self.context.makeCurrentContext(); } + pub fn is_current(&self) -> bool { + unimplemented!() + } + pub fn get_proc_address(&self, _addr: &str) -> *const () { let symbol_name: CFString = FromStr::from_str(_addr).unwrap(); let framework_name: CFString = FromStr::from_str("com.apple.opengl").unwrap(); diff --git a/src/headless.rs b/src/headless.rs index a38c194..5106a7b 100644 --- a/src/headless.rs +++ b/src/headless.rs @@ -77,6 +77,12 @@ impl HeadlessContext { pub unsafe fn make_current(&self) { self.context.make_current() } + + /// Returns true if this context is the current one in this thread. + #[inline] + pub fn is_current(&self) -> bool { + self.context.is_current() + } /// Returns the address of an OpenGL function. /// diff --git a/src/win32/headless.rs b/src/win32/headless.rs index 1da8b02..6189360 100644 --- a/src/win32/headless.rs +++ b/src/win32/headless.rs @@ -20,6 +20,11 @@ impl HeadlessContext { self.0.make_current() } + /// See the docs in the crate root file. + pub fn is_current(&self) -> bool { + self.0.is_current() + } + /// See the docs in the crate root file. pub fn get_proc_address(&self, addr: &str) -> *const () { self.0.get_proc_address(addr) diff --git a/src/win32/mod.rs b/src/win32/mod.rs index 327b71d..8cb6d39 100644 --- a/src/win32/mod.rs +++ b/src/win32/mod.rs @@ -208,6 +208,11 @@ impl Window { self.context.0 as *const libc::c_void); } + /// See the docs in the crate root file. + pub fn is_current(&self) -> bool { + unsafe { gl::wgl::GetCurrentContext() == self.context.0 as *const libc::c_void } + } + /// See the docs in the crate root file. pub fn get_proc_address(&self, addr: &str) -> *const () { let addr = CString::new(addr.as_bytes()).unwrap(); diff --git a/src/window.rs b/src/window.rs index 6b2269f..1bab245 100644 --- a/src/window.rs +++ b/src/window.rs @@ -329,6 +329,12 @@ impl Window { self.window.make_current() } + /// Returns true if this context is the current one in this thread. + #[inline] + pub fn is_current(&self) -> bool { + self.window.is_current() + } + /// Returns the address of an OpenGL function. /// /// Contrary to `wglGetProcAddress`, all available OpenGL functions return an address. diff --git a/src/x11/headless.rs b/src/x11/headless.rs index ca47414..e23dfa7 100644 --- a/src/x11/headless.rs +++ b/src/x11/headless.rs @@ -47,6 +47,10 @@ impl HeadlessContext { } } + pub fn is_current(&self) -> bool { + unsafe { ffi::OSMesaGetCurrentContext() == self.context } + } + pub fn get_proc_address(&self, addr: &str) -> *const () { unsafe { with_c_str(addr, |s| { diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs index 8664b4a..404324a 100644 --- a/src/x11/window/mod.rs +++ b/src/x11/window/mod.rs @@ -701,6 +701,10 @@ impl Window { } } + pub fn is_current(&self) -> bool { + unsafe { ffi::glx::GetCurrentContext() == self.x.context } + } + pub fn get_proc_address(&self, addr: &str) -> *const () { use std::mem; -- cgit v1.2.3