aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/cocoa
diff options
context:
space:
mode:
authorPierre Krieger <pierre.krieger1708@gmail.com>2015-04-30 13:23:37 +0200
committerPierre Krieger <pierre.krieger1708@gmail.com>2015-04-30 16:57:07 +0200
commitaa58f4149a65783b07c0dc401b5854ed80c4915e (patch)
treedd5d06aa46a1e18f0b93c2960dacc2cea9c81982 /src/api/cocoa
parenta08388bca1ca275fd1455ceae26ab06c02c81111 (diff)
downloadglutin-aa58f4149a65783b07c0dc401b5854ed80c4915e.tar.gz
glutin-aa58f4149a65783b07c0dc401b5854ed80c4915e.zip
Add a GlContext trait
Diffstat (limited to 'src/api/cocoa')
-rw-r--r--src/api/cocoa/headless.rs18
-rw-r--r--src/api/cocoa/mod.rs85
2 files changed, 58 insertions, 45 deletions
diff --git a/src/api/cocoa/headless.rs b/src/api/cocoa/headless.rs
index 298027f..cc2a526 100644
--- a/src/api/cocoa/headless.rs
+++ b/src/api/cocoa/headless.rs
@@ -1,6 +1,7 @@
use CreationError;
use CreationError::OsError;
use BuilderAttribs;
+use GlContext;
use libc;
use std::ptr;
@@ -56,8 +57,10 @@ impl HeadlessContext {
Ok(headless)
}
+}
- pub unsafe fn make_current(&self) {
+impl GlContext for HeadlessContext {
+ unsafe fn make_current(&self) {
self.context.makeCurrentContext();
gl::GenFramebuffersEXT(1, &mut framebuffer);
@@ -76,11 +79,11 @@ impl HeadlessContext {
}
}
- pub fn is_current(&self) -> bool {
+ fn is_current(&self) -> bool {
unimplemented!()
}
- pub fn get_proc_address(&self, _addr: &str) -> *const () {
+ fn get_proc_address(&self, _addr: &str) -> *const () {
let symbol_name: CFString = _addr.parse().unwrap();
let framework_name: CFString = "com.apple.opengl".parse().unwrap();
let framework = unsafe {
@@ -92,9 +95,16 @@ impl HeadlessContext {
symbol as *const ()
}
- pub fn get_api(&self) -> ::Api {
+ fn swap_buffers(&self) {
+ }
+
+ fn get_api(&self) -> ::Api {
::Api::OpenGl
}
+
+ fn get_pixel_format(&self) -> PixelFormat {
+ unimplemented!();
+ }
}
unsafe impl Send for HeadlessContext {}
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index 28d5ecc..101cfc0 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -9,6 +9,7 @@ use libc;
use Api;
use BuilderAttribs;
+use GlContext;
use GlRequest;
use PixelFormat;
use native_monitor::NativeMonitorId;
@@ -672,39 +673,6 @@ impl Window {
return None;
}
- pub unsafe fn make_current(&self) {
- let _: () = msg_send![*self.context, update];
- self.context.makeCurrentContext();
- }
-
- pub fn is_current(&self) -> bool {
- unsafe {
- let current = NSOpenGLContext::currentContext(nil);
- if current != nil {
- let is_equal: BOOL = msg_send![current, isEqual:*self.context];
- is_equal != NO
- } else {
- false
- }
- }
- }
-
- 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();
- let framework = unsafe {
- CFBundleGetBundleWithIdentifier(framework_name.as_concrete_TypeRef())
- };
- let symbol = unsafe {
- CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef())
- };
- symbol as *const ()
- }
-
- pub fn swap_buffers(&self) {
- unsafe { self.context.flushBuffer(); }
- }
-
pub fn platform_display(&self) -> *mut libc::c_void {
unimplemented!()
}
@@ -713,14 +681,6 @@ impl Window {
unimplemented!()
}
- pub fn get_api(&self) -> ::Api {
- ::Api::OpenGl
- }
-
- pub fn get_pixel_format(&self) -> PixelFormat {
- self.pixel_format.clone()
- }
-
pub fn set_window_resize_callback(&mut self, callback: Option<fn(u32, u32)>) {
self.delegate.state.resize_handler = callback;
}
@@ -791,6 +751,49 @@ impl Window {
}
}
+impl GlContext for Window {
+ unsafe fn make_current(&self) {
+ let _: () = msg_send![*self.context, update];
+ self.context.makeCurrentContext();
+ }
+
+ fn is_current(&self) -> bool {
+ unsafe {
+ let current = NSOpenGLContext::currentContext(nil);
+ if current != nil {
+ let is_equal: BOOL = msg_send![current, isEqual:*self.context];
+ is_equal != NO
+ } else {
+ false
+ }
+ }
+ }
+
+ fn get_proc_address(&self, addr: &str) -> *const libc::c_void {
+ let symbol_name: CFString = FromStr::from_str(_addr).unwrap();
+ let framework_name: CFString = FromStr::from_str("com.apple.opengl").unwrap();
+ let framework = unsafe {
+ CFBundleGetBundleWithIdentifier(framework_name.as_concrete_TypeRef())
+ };
+ let symbol = unsafe {
+ CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef())
+ };
+ symbol as *const _
+ }
+
+ fn swap_buffers(&self) {
+ unsafe { self.context.flushBuffer(); }
+ }
+
+ fn get_api(&self) -> ::Api {
+ ::Api::OpenGl
+ }
+
+ fn get_pixel_format(&self) -> PixelFormat {
+ self.pixel_format.clone()
+ }
+}
+
struct IdRef(id);
impl IdRef {