Started adding support for selection OpenGL versions on OS X. Needs issue #176 to be fixed.

This commit is contained in:
Patrick Horlebein 2014-12-29 13:26:44 +01:00
parent 29bf3385ad
commit 86af6b6387

View file

@ -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<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"))); },
@ -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<id> {
fn create_context(view: id, vsync: bool, gl_version: Option<(uint, uint)>) -> Option<id> {
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
];