Merge pull request #305 from tomaka/is-current

Add is_current function
This commit is contained in:
tomaka 2015-03-04 08:00:56 +01:00
commit 15d0379633
9 changed files with 47 additions and 0 deletions

View file

@ -61,6 +61,11 @@ impl HeadlessContext {
unimplemented!() unimplemented!()
} }
/// See the docs in the crate root file.
pub fn is_current(&self) -> bool {
unimplemented!()
}
/// See the docs in the crate root file. /// See the docs in the crate root file.
pub fn get_proc_address(&self, _addr: &str) -> *const () { pub fn get_proc_address(&self, _addr: &str) -> *const () {
unimplemented!() 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 () { pub fn get_proc_address(&self, addr: &str) -> *const () {
let addr = CString::from_slice(addr.as_bytes()); let addr = CString::from_slice(addr.as_bytes());
let addr = addr.as_ptr(); let addr = addr.as_ptr();

View file

@ -76,6 +76,10 @@ impl HeadlessContext {
} }
} }
pub fn is_current(&self) -> bool {
unimplemented!()
}
pub fn get_proc_address(&self, _addr: &str) -> *const () { pub fn get_proc_address(&self, _addr: &str) -> *const () {
let symbol_name: CFString = _addr.parse().unwrap(); let symbol_name: CFString = _addr.parse().unwrap();
let framework_name: CFString = "com.apple.opengl".parse().unwrap(); let framework_name: CFString = "com.apple.opengl".parse().unwrap();

View file

@ -587,6 +587,10 @@ impl Window {
self.context.makeCurrentContext(); self.context.makeCurrentContext();
} }
pub fn is_current(&self) -> bool {
unimplemented!()
}
pub fn get_proc_address(&self, _addr: &str) -> *const () { pub fn get_proc_address(&self, _addr: &str) -> *const () {
let symbol_name: CFString = FromStr::from_str(_addr).unwrap(); let symbol_name: CFString = FromStr::from_str(_addr).unwrap();
let framework_name: CFString = FromStr::from_str("com.apple.opengl").unwrap(); let framework_name: CFString = FromStr::from_str("com.apple.opengl").unwrap();

View file

@ -77,6 +77,12 @@ impl HeadlessContext {
pub unsafe fn make_current(&self) { pub unsafe fn make_current(&self) {
self.context.make_current() 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. /// Returns the address of an OpenGL function.
/// ///

View file

@ -20,6 +20,11 @@ impl HeadlessContext {
self.0.make_current() 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. /// See the docs in the crate root file.
pub fn get_proc_address(&self, addr: &str) -> *const () { pub fn get_proc_address(&self, addr: &str) -> *const () {
self.0.get_proc_address(addr) self.0.get_proc_address(addr)

View file

@ -208,6 +208,11 @@ impl Window {
self.context.0 as *const libc::c_void); 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. /// See the docs in the crate root file.
pub fn get_proc_address(&self, addr: &str) -> *const () { pub fn get_proc_address(&self, addr: &str) -> *const () {
let addr = CString::new(addr.as_bytes()).unwrap(); let addr = CString::new(addr.as_bytes()).unwrap();

View file

@ -329,6 +329,12 @@ impl Window {
self.window.make_current() 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. /// Returns the address of an OpenGL function.
/// ///
/// Contrary to `wglGetProcAddress`, all available OpenGL functions return an address. /// Contrary to `wglGetProcAddress`, all available OpenGL functions return an address.

View file

@ -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 () { pub fn get_proc_address(&self, addr: &str) -> *const () {
unsafe { unsafe {
with_c_str(addr, |s| { with_c_str(addr, |s| {

View file

@ -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 () { pub fn get_proc_address(&self, addr: &str) -> *const () {
use std::mem; use std::mem;