diff options
Diffstat (limited to 'src/api/glx')
-rw-r--r-- | src/api/glx/mod.rs | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/api/glx/mod.rs b/src/api/glx/mod.rs index fb86dfd..cb61dfa 100644 --- a/src/api/glx/mod.rs +++ b/src/api/glx/mod.rs @@ -2,8 +2,11 @@ use BuilderAttribs; use CreationError; +use GlContext; +use GlProfile; use GlRequest; use Api; +use PixelFormat; use libc; use std::ffi::CString; @@ -50,6 +53,17 @@ impl Context { }, } + if let Some(profile) = builder.gl_profile { + let flag = match profile { + GlProfile::Compatibility => + ffi::glx_extra::CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, + GlProfile::Core => + ffi::glx_extra::CONTEXT_CORE_PROFILE_BIT_ARB, + }; + attributes.push(ffi::glx_extra::CONTEXT_PROFILE_MASK_ARB as libc::c_int); + attributes.push(flag as libc::c_int); + } + if builder.gl_debug { attributes.push(ffi::glx_extra::CONTEXT_FLAGS_ARB as libc::c_int); attributes.push(ffi::glx_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int); @@ -140,35 +154,41 @@ impl Context { context: context, }) } +} - pub fn make_current(&self) { - let res = unsafe { ffi::glx::MakeCurrent(self.display as *mut _, self.window, self.context) }; +impl GlContext for Context { + unsafe fn make_current(&self) { + let res = ffi::glx::MakeCurrent(self.display as *mut _, self.window, self.context); if res == 0 { panic!("glx::MakeCurrent failed"); } } - pub fn is_current(&self) -> bool { + fn is_current(&self) -> bool { unsafe { ffi::glx::GetCurrentContext() == self.context } } - pub fn get_proc_address(&self, addr: &str) -> *const () { + fn get_proc_address(&self, addr: &str) -> *const libc::c_void { let addr = CString::new(addr.as_bytes()).unwrap(); let addr = addr.as_ptr(); unsafe { - ffi::glx::GetProcAddress(addr as *const _) as *const () + ffi::glx::GetProcAddress(addr as *const _) as *const _ } } - pub fn swap_buffers(&self) { + fn swap_buffers(&self) { unsafe { ffi::glx::SwapBuffers(self.display as *mut _, self.window) } } - pub fn get_api(&self) -> ::Api { + fn get_api(&self) -> ::Api { ::Api::OpenGl } + + fn get_pixel_format(&self) -> PixelFormat { + unimplemented!(); + } } unsafe impl Send for Context {} @@ -176,8 +196,6 @@ unsafe impl Sync for Context {} impl Drop for Context { fn drop(&mut self) { - use std::ptr; - unsafe { // we don't call MakeCurrent(0, 0) because we are not sure that the context // is still the current one |