Merge pull request #208 from kazimuth/osxcontext

Fix #177 merge conflicts
This commit is contained in:
tomaka 2015-01-18 09:09:50 +01:00
commit 00460364ca

View file

@ -71,7 +71,7 @@ impl Window {
unimplemented!() 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)
} }
} }
@ -138,7 +138,7 @@ extern fn window_did_resize(this: id, _: id) -> id {
impl Window { impl Window {
fn new_impl(dimensions: Option<(u32, u32)>, title: &str, monitor: Option<MonitorID>, fn new_impl(dimensions: Option<(u32, u32)>, title: &str, monitor: Option<MonitorID>,
vsync: bool, visible: bool) -> Result<Window, CreationError> { vsync: bool, visible: bool, gl_version: Option<(u32, u32)>) -> Result<Window, CreationError> {
let app = match Window::create_app() { let app = match Window::create_app() {
Some(app) => app, Some(app) => app,
None => { return Err(OsError(format!("Couldn't create NSApplication"))); }, None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
@ -152,7 +152,7 @@ impl Window {
None => { return Err(OsError(format!("Couldn't create NSView"))); }, 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, Some(context) => context,
None => { return Err(OsError(format!("Couldn't create OpenGL context"))); }, None => { return Err(OsError(format!("Couldn't create OpenGL context"))); },
}; };
@ -268,7 +268,12 @@ impl Window {
} }
} }
fn create_context(view: id, vsync: bool) -> Option<id> { fn create_context(view: id, vsync: bool, gl_version: Option<(u32, u32)>) -> Option<id> {
let profile = match gl_version {
None | Some((0...2, _)) | Some((3, 0)) => NSOpenGLProfileVersionLegacy as u32,
Some((3, 1...2)) => NSOpenGLProfileVersion3_2Core as u32,
Some((_, _)) => NSOpenGLProfileVersion4_1Core as u32,
};
unsafe { unsafe {
let attributes = [ let attributes = [
NSOpenGLPFADoubleBuffer as u32, NSOpenGLPFADoubleBuffer as u32,
@ -277,6 +282,7 @@ impl Window {
NSOpenGLPFAAlphaSize as u32, 8, NSOpenGLPFAAlphaSize as u32, 8,
NSOpenGLPFADepthSize as u32, 24, NSOpenGLPFADepthSize as u32, 24,
NSOpenGLPFAStencilSize as u32, 8, NSOpenGLPFAStencilSize as u32, 8,
NSOpenGLPFAOpenGLProfile as u32, profile,
0 0
]; ];