NO_VR env var for monitor only mode

This commit is contained in:
2016-10-13 01:46:47 -07:00
parent 381157c8e2
commit f2a645730c
4 changed files with 73 additions and 44 deletions

View File

@@ -8,15 +8,20 @@ extern crate gfx_device_gl;
extern crate piston_window;
use self::piston_window::{PistonWindow, Window, WindowSettings};
use std::env;
pub fn main() {
env_logger::init().expect("env logger");
let mut vr = vr::VR::new().expect("VR init");
let mut vr = if env::var("NO_VR").is_ok() {
None
} else {
Some(vr::VR::new().expect("VR init"))
};
let mut window: PistonWindow =
WindowSettings::new("Hello, Britannia!", [1024; 2])
.exit_on_esc(true)
.vsync(false)
.vsync(vr.is_none()) // Let VR throttle framerate, if available
.build().expect("Building Window");
let mut aux_command = window.factory.create_command_buffer();
@@ -44,7 +49,7 @@ pub fn main() {
}
// handle VR events
while let Some(ev) = vr.poll_next_event() {
while let Some(ev) = vr.as_mut().and_then(|vr| vr.poll_next_event()) {
scene.event(Event::Vr(ev));
}
}