1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 use glutin::{self, ContextBuilder, ContextCurrentState, CreationError}; 6 use winit::{EventsLoop, Window, WindowBuilder}; 7 8 #[cfg(not(windows))] 9 pub enum Context {} 10 11 #[cfg(windows)] 12 pub use crate::egl::Context; 13 14 impl Context { 15 #[cfg(not(windows))] with_window<T: ContextCurrentState>( _: WindowBuilder, _: ContextBuilder<'_, T>, _: &EventsLoop, ) -> Result<(Window, Self), CreationError>16 pub fn with_window<T: ContextCurrentState>( 17 _: WindowBuilder, 18 _: ContextBuilder<'_, T>, 19 _: &EventsLoop, 20 ) -> Result<(Window, Self), CreationError> { 21 Err(CreationError::PlatformSpecific( 22 "ANGLE rendering is only supported on Windows".into(), 23 )) 24 } 25 26 #[cfg(windows)] with_window<T: ContextCurrentState>( window_builder: WindowBuilder, context_builder: ContextBuilder<'_, T>, events_loop: &EventsLoop, ) -> Result<(Window, Self), CreationError>27 pub fn with_window<T: ContextCurrentState>( 28 window_builder: WindowBuilder, 29 context_builder: ContextBuilder<'_, T>, 30 events_loop: &EventsLoop, 31 ) -> Result<(Window, Self), CreationError> { 32 use winit::os::windows::WindowExt; 33 34 // FIXME: &context_builder.pf_reqs https://github.com/tomaka/glutin/pull/1002 35 let pf_reqs = &glutin::PixelFormatRequirements::default(); 36 let gl_attr = &context_builder.gl_attr.map_sharing(|_| unimplemented!()); 37 let window = window_builder.build(events_loop)?; 38 Self::new(pf_reqs, gl_attr) 39 .and_then(|p| p.finish(window.get_hwnd() as _)) 40 .map(|context| (window, context)) 41 } 42 43 #[cfg(not(windows))] make_current(&self) -> Result<(), glutin::ContextError>44 pub unsafe fn make_current(&self) -> Result<(), glutin::ContextError> { 45 match *self {} 46 } 47 48 #[cfg(not(windows))] get_proc_address(&self, _: &str) -> *const ()49 pub fn get_proc_address(&self, _: &str) -> *const () { 50 match *self {} 51 } 52 53 #[cfg(not(windows))] swap_buffers(&self) -> Result<(), glutin::ContextError>54 pub fn swap_buffers(&self) -> Result<(), glutin::ContextError> { 55 match *self {} 56 } 57 58 #[cfg(not(windows))] get_api(&self) -> glutin::Api59 pub fn get_api(&self) -> glutin::Api { 60 match *self {} 61 } 62 } 63