summaryrefslogtreecommitdiffstats
path: root/gfx/wr/wrench/src/angle.rs
blob: 94be95a62522778cfeb39ed6b0e35a1c1231d5e0 (plain)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use glutin::{self, ContextBuilder, ContextCurrentState, CreationError};
use winit::{event_loop::EventLoop, window::Window, window::WindowBuilder};

#[cfg(not(windows))]
pub enum Context {}

#[cfg(windows)]
pub use crate::egl::Context;

impl Context {
    #[cfg(not(windows))]
    pub fn with_window<T: ContextCurrentState>(
        _: WindowBuilder,
        _: ContextBuilder<'_, T>,
        _: &EventLoop<()>,
    ) -> Result<(Window, Self), CreationError> {
        Err(CreationError::PlatformSpecific(
            "ANGLE rendering is only supported on Windows".into(),
        ))
    }

    #[cfg(windows)]
    pub fn with_window<T: ContextCurrentState>(
        window_builder: WindowBuilder,
        context_builder: ContextBuilder<'_, T>,
        events_loop: &EventLoop<()>,
    ) -> Result<(Window, Self), CreationError> {
        use winit::platform::windows::WindowExtWindows;

        // FIXME: &context_builder.pf_reqs  https://github.com/tomaka/glutin/pull/1002
        let pf_reqs = &glutin::PixelFormatRequirements::default();
        let gl_attr = &context_builder.gl_attr.map_sharing(|_| unimplemented!());
        let window = window_builder.build(events_loop)?;
        Self::new(pf_reqs, gl_attr)
            .and_then(|p| p.finish(window.hwnd() as _))
            .map(|context| (window, context))
    }

    #[cfg(not(windows))]
    pub unsafe fn make_current(&self) -> Result<(), glutin::ContextError> {
        match *self {}
    }

    #[cfg(not(windows))]
    pub fn get_proc_address(&self, _: &str) -> *const () {
        match *self {}
    }

    #[cfg(not(windows))]
    pub fn swap_buffers(&self) -> Result<(), glutin::ContextError> {
        match *self {}
    }

    #[cfg(not(windows))]
    pub fn get_api(&self) -> glutin::Api {
        match *self {}
    }
}