diff options
Diffstat (limited to 'src/api/osmesa')
-rw-r--r-- | src/api/osmesa/mod.rs | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/api/osmesa/mod.rs b/src/api/osmesa/mod.rs index ea90583..22df72a 100644 --- a/src/api/osmesa/mod.rs +++ b/src/api/osmesa/mod.rs @@ -1,10 +1,12 @@ -#![cfg(all(any(target_os = "linux", target_os = "freebsd"), feature="headless"))] +#![cfg(any(target_os = "linux", target_os = "freebsd"))] extern crate osmesa_sys; +use Api; use BuilderAttribs; use CreationError; -use CreationError::OsError; +use GlContext; +use PixelFormat; use libc; use std::{mem, ptr}; use std::ffi::CString; @@ -16,8 +18,23 @@ pub struct OsMesaContext { height: u32, } +pub enum OsMesaCreationError { + CreationError(CreationError), + NotSupported, +} + +impl From<CreationError> for OsMesaCreationError { + fn from(e: CreationError) -> OsMesaCreationError { + OsMesaCreationError::CreationError(e) + } +} + impl OsMesaContext { - pub fn new(builder: BuilderAttribs) -> Result<OsMesaContext, CreationError> { + pub fn new(builder: BuilderAttribs) -> Result<OsMesaContext, OsMesaCreationError> { + if let Err(_) = osmesa_sys::OsMesa::try_loading() { + return Err(OsMesaCreationError::NotSupported); + } + let dimensions = builder.dimensions.unwrap(); Ok(OsMesaContext { @@ -28,7 +45,7 @@ impl OsMesaContext { context: unsafe { let ctxt = osmesa_sys::OSMesaCreateContext(0x1908, ptr::null_mut()); if ctxt.is_null() { - return Err(OsError("OSMesaCreateContext failed".to_string())); + return Err(CreationError::OsError("OSMesaCreateContext failed".to_string()).into()); } ctxt } @@ -43,7 +60,13 @@ impl OsMesaContext { (self.width, self.height) } - pub unsafe fn make_current(&self) { + // TODO: can we remove this without causing havoc? + pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) { + } +} + +impl GlContext for OsMesaContext { + unsafe fn make_current(&self) { let ret = osmesa_sys::OSMesaMakeCurrent(self.context, self.buffer.as_ptr() as *mut libc::c_void, 0x1401, self.width as libc::c_int, self.height as libc::c_int); @@ -53,23 +76,26 @@ impl OsMesaContext { } } - pub fn is_current(&self) -> bool { + fn is_current(&self) -> bool { unsafe { osmesa_sys::OSMesaGetCurrentContext() == self.context } } - pub fn get_proc_address(&self, addr: &str) -> *const () { + fn get_proc_address(&self, addr: &str) -> *const libc::c_void { unsafe { let c_str = CString::new(addr.as_bytes().to_vec()).unwrap(); mem::transmute(osmesa_sys::OSMesaGetProcAddress(mem::transmute(c_str.as_ptr()))) } } - /// See the docs in the crate root file. - pub fn get_api(&self) -> ::Api { - ::Api::OpenGl + fn swap_buffers(&self) { } - pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) { + fn get_api(&self) -> Api { + Api::OpenGl + } + + fn get_pixel_format(&self) -> PixelFormat { + unimplemented!(); } } |