aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml17
-rw-r--r--build.rs242
-rw-r--r--src/api/cocoa/mod.rs19
-rw-r--r--src/api/x11/events.rs1
-rw-r--r--src/api/x11/window.rs55
5 files changed, 160 insertions, 174 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 294d55d..f1434d1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,31 +16,30 @@ libc = "0.2"
shared_library = "0.1.0"
[build-dependencies]
-gl_generator = "0.4"
-khronos_api = "1.0"
+gl_generator = "0.5"
[target.arm-linux-androideabi.dependencies.android_glue]
version = "0.1"
[target.i386-apple-ios.dependencies]
-objc = "0.1.8"
+objc = "0.2"
[target.x86_64-apple-ios.dependencies]
-objc = "0.1.8"
+objc = "0.2"
[target.aarch64-apple-ios.dependencies]
-objc = "0.1.8"
+objc = "0.2"
[target.armv7s-apple-ios.dependencies]
-objc = "0.1.8"
+objc = "0.2"
[target.armv7-apple-ios.dependencies]
-objc = "0.1.8"
+objc = "0.2"
[target.x86_64-apple-darwin.dependencies]
-objc = "0.1.8"
+objc = "0.2"
cgl = "0.1"
-cocoa = "0.2.4"
+cocoa = "0.3"
core-foundation = "0"
core-graphics = "0.3"
diff --git a/build.rs b/build.rs
index 5367173..7d911f5 100644
--- a/build.rs
+++ b/build.rs
@@ -1,6 +1,6 @@
extern crate gl_generator;
-extern crate khronos_api;
+use gl_generator::{Registry, Api, Profile, Fallbacks};
use std::env;
use std::fs::File;
use std::path::PathBuf;
@@ -13,175 +13,135 @@ fn main() {
if target.contains("windows") {
let mut file = File::create(&dest.join("wgl_bindings.rs")).unwrap();
- gl_generator::generate_bindings(gl_generator::StaticGenerator,
- gl_generator::registry::Ns::Wgl,
- gl_generator::Fallbacks::All,
- khronos_api::WGL_XML, vec![],
- "1.0", "core", &mut file).unwrap();
+ Registry::new(Api::Wgl, (1, 0), Profile::Core, Fallbacks::All, [])
+ .write_bindings(gl_generator::StaticGenerator, &mut file)
+ .unwrap();
let mut file = File::create(&dest.join("wgl_extra_bindings.rs")).unwrap();
- gl_generator::generate_bindings(gl_generator::StructGenerator,
- gl_generator::registry::Ns::Wgl,
- gl_generator::Fallbacks::All,
- khronos_api::WGL_XML,
- vec![
- "WGL_ARB_create_context".to_string(),
- "WGL_ARB_create_context_profile".to_string(),
- "WGL_ARB_create_context_robustness".to_string(),
- "WGL_ARB_context_flush_control".to_string(),
- "WGL_ARB_extensions_string".to_string(),
- "WGL_ARB_framebuffer_sRGB".to_string(),
- "WGL_ARB_multisample".to_string(),
- "WGL_ARB_pixel_format".to_string(),
- "WGL_ARB_pixel_format_float".to_string(),
- "WGL_EXT_create_context_es2_profile".to_string(),
- "WGL_EXT_extensions_string".to_string(),
- "WGL_EXT_framebuffer_sRGB".to_string(),
- "WGL_EXT_swap_control".to_string(),
- ],
- "1.0", "core", &mut file).unwrap();
+ Registry::new(Api::Wgl, (1, 0), Profile::Core, Fallbacks::All, [
+ "WGL_ARB_create_context",
+ "WGL_ARB_create_context_profile",
+ "WGL_ARB_create_context_robustness",
+ "WGL_ARB_context_flush_control",
+ "WGL_ARB_extensions_string",
+ "WGL_ARB_framebuffer_sRGB",
+ "WGL_ARB_multisample",
+ "WGL_ARB_pixel_format",
+ "WGL_ARB_pixel_format_float",
+ "WGL_EXT_create_context_es2_profile",
+ "WGL_EXT_extensions_string",
+ "WGL_EXT_framebuffer_sRGB",
+ "WGL_EXT_swap_control",
+ ])
+ .write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
- gl_generator::generate_bindings(gl_generator::StructGenerator,
- gl_generator::registry::Ns::Egl,
- gl_generator::Fallbacks::All,
- khronos_api::EGL_XML,
- vec![
- "EGL_KHR_create_context".to_string(),
- "EGL_EXT_create_context_robustness".to_string(),
- "EGL_KHR_create_context_no_error".to_string(),
- "EGL_KHR_platform_x11".to_string(),
- "EGL_KHR_platform_android".to_string(),
- "EGL_KHR_platform_wayland".to_string(),
- "EGL_KHR_platform_gbm".to_string(),
- "EGL_EXT_platform_base".to_string(),
- "EGL_EXT_platform_x11".to_string(),
- "EGL_MESA_platform_gbm".to_string(),
- "EGL_EXT_platform_wayland".to_string(),
- "EGL_EXT_platform_device".to_string(),
- ],
- "1.5", "core", &mut file).unwrap();
+ Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [
+ "EGL_KHR_create_context",
+ "EGL_EXT_create_context_robustness",
+ "EGL_KHR_create_context_no_error",
+ "EGL_KHR_platform_x11",
+ "EGL_KHR_platform_android",
+ "EGL_KHR_platform_wayland",
+ "EGL_KHR_platform_gbm",
+ "EGL_EXT_platform_base",
+ "EGL_EXT_platform_x11",
+ "EGL_MESA_platform_gbm",
+ "EGL_EXT_platform_wayland",
+ "EGL_EXT_platform_device",
+ ])
+ .write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
}
if target.contains("linux") || target.contains("dragonfly") || target.contains("freebsd") || target.contains("openbsd") {
let mut file = File::create(&dest.join("glx_bindings.rs")).unwrap();
- gl_generator::generate_bindings(gl_generator::StructGenerator,
- gl_generator::registry::Ns::Glx,
- gl_generator::Fallbacks::All,
- khronos_api::GLX_XML, vec![],
- "1.4", "core", &mut file).unwrap();
+ Registry::new(Api::Glx, (1, 4), Profile::Core, Fallbacks::All, [])
+ .write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
let mut file = File::create(&dest.join("glx_extra_bindings.rs")).unwrap();
- gl_generator::generate_bindings(gl_generator::StructGenerator,
- gl_generator::registry::Ns::Glx,
- gl_generator::Fallbacks::All,
- khronos_api::GLX_XML,
- vec![
- "GLX_ARB_create_context".to_string(),
- "GLX_ARB_create_context_profile".to_string(),
- "GLX_ARB_create_context_robustness".to_string(),
- "GLX_ARB_context_flush_control".to_string(),
- "GLX_ARB_fbconfig_float".to_string(),
- "GLX_ARB_framebuffer_sRGB".to_string(),
- "GLX_EXT_framebuffer_sRGB".to_string(),
- "GLX_ARB_multisample".to_string(),
- "GLX_EXT_swap_control".to_string(),
- "GLX_SGI_swap_control".to_string()
- ],
- "1.4", "core", &mut file).unwrap();
+ Registry::new(Api::Glx, (1, 4), Profile::Core, Fallbacks::All, [
+ "GLX_ARB_create_context",
+ "GLX_ARB_create_context_profile",
+ "GLX_ARB_create_context_robustness",
+ "GLX_ARB_context_flush_control",
+ "GLX_ARB_fbconfig_float",
+ "GLX_ARB_framebuffer_sRGB",
+ "GLX_EXT_framebuffer_sRGB",
+ "GLX_ARB_multisample",
+ "GLX_EXT_swap_control",
+ "GLX_SGI_swap_control"
+ ])
+ .write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
- gl_generator::generate_bindings(gl_generator::StructGenerator,
- gl_generator::registry::Ns::Egl,
- gl_generator::Fallbacks::All,
- khronos_api::EGL_XML,
- vec![
- "EGL_KHR_create_context".to_string(),
- "EGL_EXT_create_context_robustness".to_string(),
- "EGL_KHR_create_context_no_error".to_string(),
- "EGL_KHR_platform_x11".to_string(),
- "EGL_KHR_platform_android".to_string(),
- "EGL_KHR_platform_wayland".to_string(),
- "EGL_KHR_platform_gbm".to_string(),
- "EGL_EXT_platform_base".to_string(),
- "EGL_EXT_platform_x11".to_string(),
- "EGL_MESA_platform_gbm".to_string(),
- "EGL_EXT_platform_wayland".to_string(),
- "EGL_EXT_platform_device".to_string(),
- ],
- "1.5", "core", &mut file).unwrap();
+ Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [
+ "EGL_KHR_create_context",
+ "EGL_EXT_create_context_robustness",
+ "EGL_KHR_create_context_no_error",
+ "EGL_KHR_platform_x11",
+ "EGL_KHR_platform_android",
+ "EGL_KHR_platform_wayland",
+ "EGL_KHR_platform_gbm",
+ "EGL_EXT_platform_base",
+ "EGL_EXT_platform_x11",
+ "EGL_MESA_platform_gbm",
+ "EGL_EXT_platform_wayland",
+ "EGL_EXT_platform_device",
+ ])
+ .write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
}
if target.contains("android") {
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
- gl_generator::generate_bindings(gl_generator::StaticStructGenerator,
- gl_generator::registry::Ns::Egl,
- gl_generator::Fallbacks::All,
- khronos_api::EGL_XML,
- vec![
- "EGL_KHR_create_context".to_string(),
- "EGL_EXT_create_context_robustness".to_string(),
- "EGL_KHR_create_context_no_error".to_string(),
- "EGL_KHR_platform_x11".to_string(),
- "EGL_KHR_platform_android".to_string(),
- "EGL_KHR_platform_wayland".to_string(),
- "EGL_KHR_platform_gbm".to_string(),
- "EGL_EXT_platform_base".to_string(),
- "EGL_EXT_platform_x11".to_string(),
- "EGL_MESA_platform_gbm".to_string(),
- "EGL_EXT_platform_wayland".to_string(),
- "EGL_EXT_platform_device".to_string(),
- ],
- "1.5", "core", &mut file).unwrap();
+ Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [
+ "EGL_KHR_create_context",
+ "EGL_EXT_create_context_robustness",
+ "EGL_KHR_create_context_no_error",
+ "EGL_KHR_platform_x11",
+ "EGL_KHR_platform_android",
+ "EGL_KHR_platform_wayland",
+ "EGL_KHR_platform_gbm",
+ "EGL_EXT_platform_base",
+ "EGL_EXT_platform_x11",
+ "EGL_MESA_platform_gbm",
+ "EGL_EXT_platform_wayland",
+ "EGL_EXT_platform_device",
+ ])
+ .write_bindings(gl_generator::StaticStructGenerator, &mut file).unwrap();
}
if target.contains("ios") {
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
- gl_generator::generate_bindings(gl_generator::StaticStructGenerator,
- gl_generator::registry::Ns::Egl,
- gl_generator::Fallbacks::All,
- khronos_api::EGL_XML,
- vec![
- "EGL_KHR_create_context".to_string(),
- "EGL_EXT_create_context_robustness".to_string(),
- "EGL_KHR_create_context_no_error".to_string(),
- "EGL_KHR_platform_x11".to_string(),
- "EGL_KHR_platform_android".to_string(),
- "EGL_KHR_platform_wayland".to_string(),
- "EGL_KHR_platform_gbm".to_string(),
- "EGL_EXT_platform_base".to_string(),
- "EGL_EXT_platform_x11".to_string(),
- "EGL_MESA_platform_gbm".to_string(),
- "EGL_EXT_platform_wayland".to_string(),
- "EGL_EXT_platform_device".to_string(),
- ],
- "1.5", "core", &mut file).unwrap();
+ Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [
+ "EGL_KHR_create_context",
+ "EGL_EXT_create_context_robustness",
+ "EGL_KHR_create_context_no_error",
+ "EGL_KHR_platform_x11",
+ "EGL_KHR_platform_android",
+ "EGL_KHR_platform_wayland",
+ "EGL_KHR_platform_gbm",
+ "EGL_EXT_platform_base",
+ "EGL_EXT_platform_x11",
+ "EGL_MESA_platform_gbm",
+ "EGL_EXT_platform_wayland",
+ "EGL_EXT_platform_device",
+ ])
+ .write_bindings(gl_generator::StaticStructGenerator, &mut file).unwrap();
let mut file = File::create(&dest.join("gles2_bindings.rs")).unwrap();
- gl_generator::generate_bindings(gl_generator::StaticStructGenerator,
- gl_generator::registry::Ns::Gles2,
- gl_generator::Fallbacks::None,
- khronos_api::GL_XML,
- vec![],
- "2.0", "core", &mut file).unwrap();
+ Registry::new(Api::Gles2, (2, 0), Profile::Core, Fallbacks::None, [])
+ .write_bindings(gl_generator::StaticStructGenerator, &mut file).unwrap();
}
if target.contains("darwin") {
let mut file = File::create(&dest.join("gl_bindings.rs")).unwrap();
- gl_generator::generate_bindings(gl_generator::GlobalGenerator,
- gl_generator::registry::Ns::Gl,
- gl_generator::Fallbacks::All,
- khronos_api::GL_XML,
- vec!["GL_EXT_framebuffer_object".to_string()],
- "3.2", "core", &mut file).unwrap();
+ Registry::new(Api::Gl, (3, 2), Profile::Core, Fallbacks::All, ["GL_EXT_framebuffer_object"])
+ .write_bindings(gl_generator::GlobalGenerator, &mut file).unwrap();
}
// TODO: only build the bindings below if we run tests/examples
let mut file = File::create(&dest.join("test_gl_bindings.rs")).unwrap();
- gl_generator::generate_bindings(gl_generator::StructGenerator,
- gl_generator::registry::Ns::Gles2,
- gl_generator::Fallbacks::All,
- khronos_api::GL_XML, vec![],
- "3.0", "core", &mut file).unwrap();
+ Registry::new(Api::Gles2, (3, 0), Profile::Core, Fallbacks::All, [])
+ .write_bindings(gl_generator::StructGenerator, &mut file).unwrap();
}
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index bec56d2..e935805 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -79,11 +79,12 @@ struct WindowDelegate {
impl WindowDelegate {
/// Get the delegate class, initiailizing it neccessary
fn class() -> *const Class {
+ use std::os::raw::c_void;
use std::sync::{Once, ONCE_INIT};
extern fn window_should_close(this: &Object, _: Sel, _: id) -> BOOL {
unsafe {
- let state: *mut libc::c_void = *this.get_ivar("glutinState");
+ let state: *mut c_void = *this.get_ivar("glutinState");
let state = state as *mut DelegateState;
(*state).pending_events.lock().unwrap().push_back(Closed);
}
@@ -92,7 +93,7 @@ impl WindowDelegate {
extern fn window_did_resize(this: &Object, _: Sel, _: id) {
unsafe {
- let state: *mut libc::c_void = *this.get_ivar("glutinState");
+ let state: *mut c_void = *this.get_ivar("glutinState");
let state = &mut *(state as *mut DelegateState);
let _: () = msg_send![*state.context, update];
@@ -111,7 +112,7 @@ impl WindowDelegate {
// TODO: center the cursor if the window had mouse grab when it
// lost focus
- let state: *mut libc::c_void = *this.get_ivar("glutinState");
+ let state: *mut c_void = *this.get_ivar("glutinState");
let state = state as *mut DelegateState;
(*state).pending_events.lock().unwrap().push_back(Focused(true));
}
@@ -119,7 +120,7 @@ impl WindowDelegate {
extern fn window_did_resign_key(this: &Object, _: Sel, _: id) {
unsafe {
- let state: *mut libc::c_void = *this.get_ivar("glutinState");
+ let state: *mut c_void = *this.get_ivar("glutinState");
let state = state as *mut DelegateState;
(*state).pending_events.lock().unwrap().push_back(Focused(false));
}
@@ -131,7 +132,7 @@ impl WindowDelegate {
INIT.call_once(|| unsafe {
// Create new NSWindowDelegate
let superclass = Class::get("NSObject").unwrap();
- let mut decl = ClassDecl::new(superclass, "GlutinWindowDelegate").unwrap();
+ let mut decl = ClassDecl::new("GlutinWindowDelegate", superclass).unwrap();
// Add callback methods
decl.add_method(sel!(windowShouldClose:),
@@ -145,7 +146,7 @@ impl WindowDelegate {
window_did_resign_key as extern fn(&Object, Sel, id));
// Store internal state as user data
- decl.add_ivar::<*mut libc::c_void>("glutinState");
+ decl.add_ivar::<*mut c_void>("glutinState");
delegate_class = decl.register();
});
@@ -162,7 +163,7 @@ impl WindowDelegate {
unsafe {
let delegate = IdRef::new(msg_send![WindowDelegate::class(), new]);
- (&mut **delegate).set_ivar("glutinState", state_ptr as *mut libc::c_void);
+ (&mut **delegate).set_ivar("glutinState", state_ptr as *mut ::std::os::raw::c_void);
let _: () = msg_send![*state.window, setDelegate:*delegate];
WindowDelegate { state: state, _this: delegate }
@@ -673,8 +674,8 @@ impl Window {
let sel = Sel::register(cursor_name);
let cls = Class::get("NSCursor").unwrap();
unsafe {
- use objc::MessageArguments;
- let cursor: id = ().send(cls as *const _ as id, sel);
+ use objc::Message;
+ let cursor: id = cls.send_message(sel, ()).unwrap();
let _: () = msg_send![cursor, set];
}
}
diff --git a/src/api/x11/events.rs b/src/api/x11/events.rs
index d497319..1c6668c 100644
--- a/src/api/x11/events.rs
+++ b/src/api/x11/events.rs
@@ -3,7 +3,6 @@ use super::ffi;
use VirtualKeyCode;
pub fn keycode_to_element(scancode: libc::c_uint) -> Option<VirtualKeyCode> {
- println!("{:?}", scancode);
Some(match scancode {
ffi::XK_BackSpace => events::VirtualKeyCode::Back,
ffi::XK_Tab => events::VirtualKeyCode::Tab,
diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs
index 8cae2be..b4019e4 100644
--- a/src/api/x11/window.rs
+++ b/src/api/x11/window.rs
@@ -339,7 +339,7 @@ impl Window {
let m = (0 .. mode_num).map(|i| {
let m: ffi::XF86VidModeModeInfo = ptr::read(*modes.offset(i as isize) as *const _); m
}).find(|m| m.hdisplay >= dimensions.0 as u16 && m.vdisplay >= dimensions.1 as u16);
-
+
match m {
Some(m) => Some(m),
None => return Err(OsError(format!("Could not find a suitable graphics mode")))
@@ -845,29 +845,61 @@ impl Window {
self.x.display.check_errors().expect("Failed to call XcursorLibraryLoadCursor");
(self.x.display.xlib.XDefineCursor)(self.x.display.display, self.x.window, xcursor);
(self.x.display.xlib.XFlush)(self.x.display.display);
+ (self.x.display.xlib.XFreeCursor)(self.x.display.display, xcursor);
self.x.display.check_errors().expect("Failed to call XDefineCursor");
}
}
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
- use CursorState::{ Grab, Normal };
+ use CursorState::{ Grab, Normal, Hide };
let mut cursor_state = self.cursor_state.lock().unwrap();
-
match (state, *cursor_state) {
- (Normal, Grab) => {
+ (Normal, Normal) | (Hide, Hide) | (Grab, Grab) => return Ok(()),
+ _ => {},
+ }
+
+ match *cursor_state {
+ Grab => {
unsafe {
(self.x.display.xlib.XUngrabPointer)(self.x.display.display, ffi::CurrentTime);
self.x.display.check_errors().expect("Failed to call XUngrabPointer");
- *cursor_state = Normal;
- Ok(())
}
},
-
- (Grab, Normal) => {
+ Normal => {},
+ Hide => {
unsafe {
- *cursor_state = Grab;
+ let xcursor = (self.x.display.xlib.XCreateFontCursor)(self.x.display.display, 68/*XC_left_ptr*/);
+ self.x.display.check_errors().expect("Failed to call XCreateFontCursor");
+ (self.x.display.xlib.XDefineCursor)(self.x.display.display, self.x.window, xcursor);
+ self.x.display.check_errors().expect("Failed to call XDefineCursor");
+ (self.x.display.xlib.XFlush)(self.x.display.display);
+ (self.x.display.xlib.XFreeCursor)(self.x.display.display, xcursor);
+ }
+ },
+ }
+ *cursor_state = state;
+ match state {
+ Normal => Ok(()),
+ Hide => {
+ let data = &[0, 0, 0, 0, 0, 0, 0, 0];
+ unsafe {
+ let mut black = ffi::XColor {
+ red: 0, green: 0, blue: 0,
+ pad: 0, pixel: 0, flags: 0,
+ };
+ let bitmap = (self.x.display.xlib.XCreateBitmapFromData)(self.x.display.display, self.x.window, data.as_ptr(), 8, 8);
+ let cursor = (self.x.display.xlib.XCreatePixmapCursor)(self.x.display.display, bitmap, bitmap, &mut black, &mut black, 0, 0);
+ (self.x.display.xlib.XDefineCursor)(self.x.display.display, self.x.window, cursor);
+ self.x.display.check_errors().expect("Failed to call XDefineCursor");
+ (self.x.display.xlib.XFreeCursor)(self.x.display.display, cursor);
+ (self.x.display.xlib.XFreePixmap)(self.x.display.display, bitmap);
+ }
+ Ok(())
+ },
+ Grab => {
+ unsafe {
match (self.x.display.xlib.XGrabPointer)(
self.x.display.display, self.x.window, ffi::False,
(ffi::ButtonPressMask | ffi::ButtonReleaseMask | ffi::EnterWindowMask |
@@ -886,11 +918,6 @@ impl Window {
}
}
},
-
- // Nothing needs to change
- (Grab, Grab) | (Normal, Normal) => Ok(()),
-
- _ => unimplemented!(),
}
}