1use std::ops::Deref;
16use std::os::raw::c_void;
17use std::rc::Rc;
18
19use crate::CapabilitiesSource;
20use crate::SwapBuffersError;
21
22use crate::version::Version;
23
24pub use crate::context::Capabilities;
25pub use crate::context::Context;
26pub use crate::context::ExtensionsList;
27pub use crate::context::ReleaseBehavior;
28
29#[cfg(feature = "glutin")]
30pub mod glutin;
31
32use ::glutin::surface::SwapInterval;
33#[cfg(feature = "simple_window_builder")]
34pub use winit;
35
36pub unsafe trait Backend {
41 fn swap_buffers(&self) -> Result<(), SwapBuffersError>;
43
44 unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void;
48
49 fn get_framebuffer_dimensions(&self) -> (u32, u32);
51
52 fn resize(&self, new_size: (u32, u32));
54
55 fn set_swap_interval(&self, interval: SwapInterval);
57
58 fn is_current(&self) -> bool;
60
61 unsafe fn make_current(&self);
63}
64
65unsafe impl<T> Backend for Rc<T>
66where
67 T: Backend,
68{
69 fn swap_buffers(&self) -> Result<(), SwapBuffersError> {
70 self.deref().swap_buffers()
71 }
72
73 unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void {
74 self.deref().get_proc_address(symbol)
75 }
76
77 fn get_framebuffer_dimensions(&self) -> (u32, u32) {
78 self.deref().get_framebuffer_dimensions()
79 }
80
81 fn resize(&self, new_size: (u32, u32)) {
82 self.deref().resize(new_size);
83 }
84
85 fn set_swap_interval(&self, interval: SwapInterval) {
86 self.deref().set_swap_interval(interval);
87 }
88
89 fn is_current(&self) -> bool {
90 self.deref().is_current()
91 }
92
93 unsafe fn make_current(&self) {
94 self.deref().make_current();
95 }
96}
97
98pub trait Facade {
100 fn get_context(&self) -> &Rc<Context>;
102}
103
104impl<T: ?Sized> CapabilitiesSource for T
105where
106 T: Facade,
107{
108 fn get_version(&self) -> &Version {
109 self.get_context().deref().get_opengl_version()
110 }
111
112 fn get_extensions(&self) -> &ExtensionsList {
113 self.get_context().deref().get_extensions()
114 }
115
116 fn get_capabilities(&self) -> &Capabilities {
117 self.get_context().deref().get_capabilities()
118 }
119}
120
121impl Facade for Rc<Context> {
122 #[inline]
123 fn get_context(&self) -> &Rc<Context> {
124 self
125 }
126}