Merge PixelPirate's changes and fix merge conflicts

This commit is contained in:
James Gilles 2015-01-17 20:42:44 -05:00
commit 211a326036
6 changed files with 2228 additions and 4 deletions

View file

@ -4,6 +4,7 @@ pub use self::headless::HeadlessContext;
use {CreationError, Event, MouseCursor};
use CreationError::OsError;
use libc;
use std::ascii::AsciiExt;
use BuilderAttribs;
@ -71,7 +72,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)
}
}
@ -138,7 +139,7 @@ extern fn window_did_resize(this: id, _: id) -> id {
impl Window {
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<(uint, uint)>) -> Result<Window, CreationError> {
let app = match Window::create_app() {
Some(app) => app,
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
@ -152,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"))); },
};
@ -268,7 +269,12 @@ impl Window {
}
}
fn create_context(view: id, vsync: bool) -> Option<id> {
fn create_context(view: id, vsync: bool, gl_version: Option<(uint, uint)>) -> Option<id> {
let profile = match gl_version {
None | Some((0...2, _)) | Some((3, 0)) => NSOpenGLProfileVersionLegacy as uint,
Some((3, 1...2)) => NSOpenGLProfileVersion3_2Core as uint,
Some((_, _)) => NSOpenGLProfileVersion4_1Core as uint,
};
unsafe {
let attributes = [
NSOpenGLPFADoubleBuffer as u32,
@ -277,6 +283,7 @@ impl Window {
NSOpenGLPFAAlphaSize as u32, 8,
NSOpenGLPFADepthSize as u32, 24,
NSOpenGLPFAStencilSize as u32, 8,
NSOpenGLPFAOpenGLProfile as u32, profile,
0
];