From a8fef35dbf320448ba53af77bd8025be5022d9f4 Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Mon, 15 Jun 2015 23:28:29 +0200 Subject: [PATCH] Make legacy functions crash on osx core contexts --- Cargo.toml | 1 + examples/cursor.rs | 2 +- examples/fullscreen.rs | 1 + examples/grabbing.rs | 2 +- examples/multiwindow.rs | 6 +++--- examples/transparent.rs | 4 +++- examples/vsync.rs | 4 +++- examples/window.rs | 2 +- src/api/cocoa/mod.rs | 6 ++++++ src/lib.rs | 2 ++ 10 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 07e99beb..1643abd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ version = "0" [target.x86_64-apple-darwin.dependencies] objc = "0.1" +cgl = "0" cocoa = "0" core-foundation = "0" core-graphics = "0" diff --git a/examples/cursor.rs b/examples/cursor.rs index d3beb844..8b0d818e 100644 --- a/examples/cursor.rs +++ b/examples/cursor.rs @@ -17,7 +17,7 @@ fn main() { println!("This example requires glutin to be compiled with the `wind #[cfg(feature = "window")] fn main() { - let window = glutin::Window::new().unwrap(); + let window = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap(); window.set_title("A fantastic window!"); unsafe { window.make_current() }; diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs index d64224b1..246a1626 100644 --- a/examples/fullscreen.rs +++ b/examples/fullscreen.rs @@ -35,6 +35,7 @@ fn main() { }; let window = glutin::WindowBuilder::new() + .with_gl_profile(glutin::GlProfile::Compatibility) .with_title("Hello world!".to_string()) .with_fullscreen(monitor) .build() diff --git a/examples/grabbing.rs b/examples/grabbing.rs index 8a467509..738a939c 100644 --- a/examples/grabbing.rs +++ b/examples/grabbing.rs @@ -16,7 +16,7 @@ fn main() { println!("This example requires glutin to be compiled with the `wind #[cfg(feature = "window")] fn main() { - let window = glutin::Window::new().unwrap(); + let window = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap(); window.set_title("glutin - Cursor grabbing test"); unsafe { window.make_current() }; diff --git a/examples/multiwindow.rs b/examples/multiwindow.rs index a9a5bacb..503e0a05 100644 --- a/examples/multiwindow.rs +++ b/examples/multiwindow.rs @@ -16,9 +16,9 @@ fn main() { println!("This example requires glutin to be compiled with the `wind #[cfg(feature = "window")] fn main() { - let window1 = glutin::Window::new().unwrap(); - let window2 = glutin::Window::new().unwrap(); - let window3 = glutin::Window::new().unwrap(); + let window1 = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap(); + let window2 = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap(); + let window3 = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap(); let t1 = thread::spawn(move || { run(window1, (0.0, 1.0, 0.0, 1.0)); diff --git a/examples/transparent.rs b/examples/transparent.rs index 553c16d4..01c084a6 100644 --- a/examples/transparent.rs +++ b/examples/transparent.rs @@ -19,7 +19,9 @@ fn resize_callback(width: u32, height: u32) { #[cfg(feature = "window")] fn main() { - let mut window = glutin::WindowBuilder::new().with_decorations(false).with_transparency(true) + let mut window = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility) + .with_decorations(false) + .with_transparency(true) .build().unwrap(); window.set_title("A fantastic window!"); window.set_window_resize_callback(Some(resize_callback as fn(u32, u32))); diff --git a/examples/vsync.rs b/examples/vsync.rs index ec9ea79f..4ae25984 100644 --- a/examples/vsync.rs +++ b/examples/vsync.rs @@ -23,7 +23,9 @@ fn main() { println!("Vsync example. This example may panic if your driver or your system forces \ you out of vsync. This is intended when `build_strict` is used."); - let mut window = glutin::WindowBuilder::new().with_vsync().build_strict().unwrap(); + let mut window = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility) + .with_vsync() + .build_strict().unwrap(); window.set_window_resize_callback(Some(resize_callback as fn(u32, u32))); unsafe { window.make_current() }; diff --git a/examples/window.rs b/examples/window.rs index 4077399c..d4e1a8dc 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -19,7 +19,7 @@ fn resize_callback(width: u32, height: u32) { #[cfg(feature = "window")] fn main() { - let mut window = glutin::Window::new().unwrap(); + let mut window = glutin::WindowBuilder::new().with_gl_profile(glutin::GlProfile::Compatibility).build().unwrap(); window.set_title("A fantastic window!"); window.set_window_resize_callback(Some(resize_callback as fn(u32, u32))); unsafe { window.make_current() }; diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index 877aba7a..ba5710db 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -17,6 +17,10 @@ use native_monitor::NativeMonitorId; use objc::runtime::{Class, Object, Sel, BOOL, YES, NO}; use objc::declare::ClassDecl; +use cgl; +use cgl::{CGLEnable, kCGLCECrashOnRemovedFunctions, CGLSetParameter, kCGLCPSurfaceOpacity}; +use cgl::CGLContextObj as CGL_CGLContextObj; + use cocoa::base::{id, nil}; use cocoa::foundation::{NSAutoreleasePool, NSDate, NSDefaultRunLoopMode, NSPoint, NSRect, NSSize, NSString, NSUInteger}; @@ -572,6 +576,8 @@ impl Window { let value = if builder.vsync { 1 } else { 0 }; cxt.setValues_forParameter_(&value, NSOpenGLContextParameter::NSOpenGLCPSwapInterval); + CGLEnable(cxt.CGLContextObj(), kCGLCECrashOnRemovedFunctions); + Ok((cxt, pf)) } else { Err(CreationError::NotSupported) diff --git a/src/lib.rs b/src/lib.rs index 784ea95a..8171a5c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,8 @@ extern crate dwmapi; #[macro_use] extern crate objc; #[cfg(target_os = "macos")] +extern crate cgl; +#[cfg(target_os = "macos")] extern crate cocoa; #[cfg(target_os = "macos")] extern crate core_foundation;