diff options
-rw-r--r-- | src/android/ffi.rs | 2 | ||||
-rw-r--r-- | src/android/mod.rs | 35 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/osx/mod.rs | 13 | ||||
-rw-r--r-- | src/x11/window/mod.rs | 2 |
5 files changed, 35 insertions, 19 deletions
diff --git a/src/android/ffi.rs b/src/android/ffi.rs index b65f44d..5e7060d 100644 --- a/src/android/ffi.rs +++ b/src/android/ffi.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] #![allow(non_snake_case)] #![allow(non_camel_case_types)] -#![allow(non_uppercase_statics)] +#![allow(non_upper_case_globals)] use libc; diff --git a/src/android/mod.rs b/src/android/mod.rs index 27fc8e0..341187f 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -21,8 +21,6 @@ pub struct MonitorID; mod ffi; -compile_warning!("The Android implementation is not fully working yet") - pub fn get_available_monitors() -> Vec<MonitorID> { vec![ MonitorID ] } @@ -47,7 +45,7 @@ pub struct HeadlessContext(int); #[cfg(feature = "headless")] impl HeadlessContext { /// See the docs in the crate root file. - pub fn new(builder: HeadlessRendererBuilder) -> Result<HeadlessContext, CreationError> { + pub fn new(_builder: HeadlessRendererBuilder) -> Result<HeadlessContext, CreationError> { unimplemented!() } @@ -57,7 +55,7 @@ impl HeadlessContext { } /// See the docs in the crate root file. - pub fn get_proc_address(&self, addr: &str) -> *const () { + pub fn get_proc_address(&self, _addr: &str) -> *const () { unimplemented!() } } @@ -98,13 +96,21 @@ impl Window { android_glue::write_log("eglInitialize succeeded"); + let use_gles2 = match builder.gl_version { + Some((2, 0)) => true, + _ => false, + }; + let config = unsafe { - let attribute_list = [ - ffi::egl::RED_SIZE as i32, 1, - ffi::egl::GREEN_SIZE as i32, 1, - ffi::egl::BLUE_SIZE as i32, 1, - ffi::egl::NONE as i32 - ]; + let mut attribute_list = vec!(); + if use_gles2 { + attribute_list.push_all(&[ffi::egl::RENDERABLE_TYPE as i32, + ffi::egl::OPENGL_ES2_BIT as i32]); + } + attribute_list.push_all(&[ffi::egl::RED_SIZE as i32, 1]); + attribute_list.push_all(&[ffi::egl::GREEN_SIZE as i32, 1]); + attribute_list.push_all(&[ffi::egl::BLUE_SIZE as i32, 1]); + attribute_list.push(ffi::egl::NONE as i32); let mut num_config: ffi::egl::types::EGLint = mem::uninitialized(); let mut config: ffi::egl::types::EGLConfig = mem::uninitialized(); @@ -124,7 +130,14 @@ impl Window { android_glue::write_log("eglChooseConfig succeeded"); let context = unsafe { - let context = ffi::egl::CreateContext(display, config, ptr::null(), ptr::null()); + let mut context_attributes = vec!(); + if use_gles2 { + context_attributes.push_all(&[ffi::egl::CONTEXT_CLIENT_VERSION as i32, 2]); + } + context_attributes.push(ffi::egl::NONE as i32); + + let context = ffi::egl::CreateContext(display, config, ptr::null(), + context_attributes.as_ptr()); if context.is_null() { return Err(OsError(format!("eglCreateContext failed"))) } @@ -42,8 +42,6 @@ extern crate cocoa; extern crate core_foundation; #[cfg(target_os = "macos")] extern crate core_graphics; -#[cfg(target_os = "linux")] -extern crate sync; pub use events::*; diff --git a/src/osx/mod.rs b/src/osx/mod.rs index c4b047d..0cb4553 100644 --- a/src/osx/mod.rs +++ b/src/osx/mod.rs @@ -70,7 +70,7 @@ impl Window { unimplemented!() } - Window::new_impl(builder.dimensions, builder.title.as_slice(), builder.monitor, true) + Window::new_impl(builder.dimensions, builder.title.as_slice(), builder.monitor, builder.vsync, true) } } @@ -85,7 +85,8 @@ extern fn window_should_close(this: id, _: id) -> id { } impl Window { - fn new_impl(dimensions: Option<(uint, uint)>, title: &str, monitor: Option<MonitorID>, visible: bool) -> Result<Window, CreationError> { + fn new_impl(dimensions: Option<(uint, uint)>, title: &str, monitor: Option<MonitorID>, + vsync: bool, visible: bool) -> Result<Window, CreationError> { let app = match Window::create_app() { Some(app) => app, None => { return Err(OsError(format!("Couldn't create NSApplication"))); }, @@ -99,7 +100,7 @@ impl Window { None => { return Err(OsError(format!("Couldn't create NSView"))); }, }; - let context = match Window::create_context(view) { + let context = match Window::create_context(view, vsync) { Some(context) => context, None => { return Err(OsError(format!("Couldn't create OpenGL context"))); }, }; @@ -206,7 +207,7 @@ impl Window { } } - fn create_context(view: id) -> Option<id> { + fn create_context(view: id, vsync: bool) -> Option<id> { unsafe { let attributes = [ NSOpenGLPFADoubleBuffer as uint, @@ -228,6 +229,10 @@ impl Window { None } else { context.setView_(view); + if vsync { + let value = 1; + context.setValues_forParameter_(&value, NSOpenGLCPSwapInterval); + } Some(context) } } diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs index 668cd03..8662fdc 100644 --- a/src/x11/window/mod.rs +++ b/src/x11/window/mod.rs @@ -6,7 +6,7 @@ use std::{mem, ptr}; use std::cell::Cell; use std::sync::atomic::AtomicBool; use super::ffi; -use sync::one::{Once, ONCE_INIT}; +use std::sync::{Once, ONCE_INIT}; pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor}; |