From 86af6b6387918ea93fe5ce4cae2764a1d196061e Mon Sep 17 00:00:00 2001 From: Patrick Horlebein Date: Mon, 29 Dec 2014 13:26:44 +0100 Subject: [PATCH] Started adding support for selection OpenGL versions on OS X. Needs issue #176 to be fixed. --- src/osx/mod.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/osx/mod.rs b/src/osx/mod.rs index 7df66039..59b6577b 100644 --- a/src/osx/mod.rs +++ b/src/osx/mod.rs @@ -44,6 +44,15 @@ static mut alt_pressed: bool = false; static DELEGATE_NAME: &'static [u8] = b"glutin_window_delegate\0"; static DELEGATE_STATE_IVAR: &'static [u8] = b"glutin_state"; +// TODO: Should be added to cocoa bindings +#[allow(non_camel_case_types)] +#[deriving(Show)] +enum NSOpenGLPFAOpenGLProfiles { + NSOpenGLProfileVersionLegacy = 0x1000, + NSOpenGLProfileVersion3_2Core = 0x3200, + NSOpenGLProfileVersion4_1Core = 0x4100 +} + struct DelegateState<'a> { is_closed: bool, context: id, @@ -68,7 +77,7 @@ impl Window { unimplemented!() } - Window::new_impl(builder.dimensions, builder.title.as_slice(), builder.monitor, builder.vsync, builder.visible) + Window::new_impl(builder.dimensions, builder.title.as_slice(), builder.monitor, builder.vsync, builder.visible, builder.gl_version) } } @@ -130,7 +139,7 @@ extern fn window_did_resize(this: id, _: id) -> id { impl Window { fn new_impl(dimensions: Option<(uint, uint)>, title: &str, monitor: Option, - vsync: bool, visible: bool) -> Result { + vsync: bool, visible: bool, gl_version: Option<(uint, uint)>) -> Result { let app = match Window::create_app() { Some(app) => app, None => { return Err(OsError(format!("Couldn't create NSApplication"))); }, @@ -144,7 +153,7 @@ impl Window { None => { return Err(OsError(format!("Couldn't create NSView"))); }, }; - let context = match Window::create_context(view, vsync) { + let context = match Window::create_context(view, vsync, gl_version) { Some(context) => context, None => { return Err(OsError(format!("Couldn't create OpenGL context"))); }, }; @@ -260,7 +269,16 @@ impl Window { } } - fn create_context(view: id, vsync: bool) -> Option { + fn create_context(view: id, vsync: bool, gl_version: Option<(uint, uint)>) -> Option { + let profile = { + match gl_version { + None => NSOpenGLPFAOpenGLProfiles::NSOpenGLProfileVersionLegacy as uint, + Some((0...2, _)) => NSOpenGLPFAOpenGLProfiles::NSOpenGLProfileVersionLegacy as uint, + Some((3, 0)) => NSOpenGLPFAOpenGLProfiles::NSOpenGLProfileVersionLegacy as uint, + Some((3, 1...2)) => NSOpenGLPFAOpenGLProfiles::NSOpenGLProfileVersion3_2Core as uint, + Some((_, _)) => NSOpenGLPFAOpenGLProfiles::NSOpenGLProfileVersion4_1Core as uint, + } + }; unsafe { let attributes = [ NSOpenGLPFADoubleBuffer as uint, @@ -269,6 +287,7 @@ impl Window { NSOpenGLPFAAlphaSize as uint, 8, NSOpenGLPFADepthSize as uint, 24, NSOpenGLPFAStencilSize as uint, 8, + NSOpenGLPFAOpenGLProfile as uint, profile, 0 ];