1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Types to ease integration of windowing libraries with rovr.

#[cfg(feature = "glutin")]
mod glutin_target {
    use glutin;
    use libc;

    use RenderTarget;
    use HmdDisplay;
    use HmdDisplayId;

    /// Wrapper to use a glutin window as a render target.
    pub struct GlutinRenderTarget<'a> {
        #[allow(dead_code)] // only used on windows

        window: &'a glutin::Window,
        multisample: u32
    }

    impl<'a> GlutinRenderTarget<'a> {
        /// Create a glutin render target from the specified window. `multisample` should match the
        /// multisampling level used when creating the window.
        pub fn new(window: &'a glutin::Window,
                   multisample: u32) -> GlutinRenderTarget<'a> {
            // wish we didn't need to do this, but currently, glutin won't tell us what multisampling

            // was set to on creation

            GlutinRenderTarget {
                window: window,
                multisample: multisample
            }
        }
    }

    impl<'a> RenderTarget for GlutinRenderTarget<'a> {
        fn get_multisample(&self) -> u32 {
            self.multisample
        }

        #[cfg(windows)]
        unsafe fn get_native_window(&self) -> *const libc::c_void {
            self.window.platform_window()
        }

        // glutin currently panics for non-windows platforms if we even ask for the native window, so

        // don't!

        #[cfg(not(windows))]
        unsafe fn get_native_window(&self) -> *const libc::c_void {
            use std::ptr;
            ptr::null()
        }
    }

    impl PartialEq<glutin::NativeMonitorId> for HmdDisplayId {
        fn eq(&self, other: &glutin::NativeMonitorId) -> bool {
            match (self, other) {
                (&HmdDisplayId::Numeric(ref s), &glutin::NativeMonitorId::Numeric(ref o)) => s == o,
                (&HmdDisplayId::Name(ref s), &glutin::NativeMonitorId::Name(ref o)) => s == o,
                _ => false
            }
        }
    }

    impl PartialEq<HmdDisplayId> for glutin::NativeMonitorId {
        fn eq(&self, other: &HmdDisplayId) -> bool {
            other == self
        }
    }

    /// Find the glutin monitor that matches the HmdDisplay details.
    pub fn find_glutin_monitor(display: &HmdDisplay) -> Option<glutin::MonitorID> {
        // TODO: this needs to also compare window position if the id type is Unavailable, but

        // glutin doesn't currently expose this information

        for mon in glutin::get_available_monitors() {
            if mon.get_native_identifier() == display.id {
                return Some(mon);
            }
        }
        None
    }
}

#[cfg(feature = "glutin")]
pub use target::glutin_target::{GlutinRenderTarget, find_glutin_monitor};