From 7d345fa4637acc3cede32681a32dfecc43bca43c Mon Sep 17 00:00:00 2001 From: Stephen Weeks Date: Tue, 2 Apr 2019 00:28:18 -0700 Subject: [PATCH] Attempt to implement context sharing on Mac (#1132) Attempt to implement context sharing on Mac --- glutin/src/platform/macos/mod.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/glutin/src/platform/macos/mod.rs b/glutin/src/platform/macos/mod.rs index 6b23ecaafa..9cb08734e4 100644 --- a/glutin/src/platform/macos/mod.rs +++ b/glutin/src/platform/macos/mod.rs @@ -60,9 +60,7 @@ impl Context { let transparent = wb.window.transparent; let win = wb.build(el)?; - if gl_attr.sharing.is_some() { - unimplemented!() - } + let share_ctx = gl_attr.sharing.map_or(nil, |c| *c.get_id()); match gl_attr.robustness { Robustness::RobustNoResetNotification @@ -86,10 +84,9 @@ impl Context { Some(pf) => pf, }; - // TODO: Add context sharing let gl_context = IdRef::new( NSOpenGLContext::alloc(nil) - .initWithFormat_shareContext_(*pixel_format, nil), + .initWithFormat_shareContext_(*pixel_format, share_ctx), ); let gl_context = match gl_context.non_nil() { Some(gl_context) => gl_context, @@ -296,6 +293,14 @@ impl Context { Context::HeadlessContext(ref c) => *c.context.deref() as *mut _, } } + + #[inline] + fn get_id(&self) -> IdRef { + match self { + Context::WindowedContext(w) => w.context.clone(), + Context::HeadlessContext(h) => h.context.clone(), + } + } } #[derive(Debug)]