exposed_gl/
lib.rs

1#[cfg(target_os = "windows")]
2pub mod win32_gl;
3#[cfg(target_os = "windows")]
4pub use win32_gl as platform;
5
6#[cfg(target_os = "linux")]
7pub mod x11_gl;
8#[cfg(target_os = "linux")]
9pub use x11_gl as platform;
10
11#[cfg(target_os = "android")]
12pub mod gles;
13#[cfg(target_os = "android")]
14pub use gles as platform;
15
16mod picker;
17pub use picker::*;
18
19pub mod tokens;
20
21pub use platform::{free_lib_opengl, get_proc_addr, load_lib_opengl};
22
23use std::io::Error;
24
25use exposed::{
26    destroy::Destroy,
27    window::{Context, Event, WindowBuilder, WindowHandle},
28};
29
30use platform::GlPixelFormat;
31
32#[repr(C)]
33#[derive(Debug, Clone, Copy)]
34pub struct GlSurface(pub platform::GlSurface);
35
36impl GlSurface {
37    pub fn swap_buffers(self) -> Result<(), Error> {
38        self.0.swap_buffers()
39    }
40
41    pub fn make_current(self, context: GlContext) -> Result<(), Error> {
42        self.0.make_current(context.0)
43    }
44
45    pub fn set_swap_interval(self, interval: i32) -> Result<(), Error> {
46        self.0.set_swap_interval(interval)
47    }
48
49    pub fn build_with<E: Event>(
50        window_builder: &WindowBuilder, context: Context, min_config: &[u32], picker: &mut impl GlConfigPicker,
51    ) -> Result<(GlSurface, WindowHandle), Error> {
52        let (surface, window) = platform::GlSurface::build_with::<E, _>(&window_builder.0, context, min_config, picker)?;
53        Ok((surface.into(), window.into()))
54    }
55
56    pub fn build<E: Event>(window: WindowHandle, config: &[u32], picker: &mut impl GlConfigPicker) -> Result<GlSurface, Error> {
57        Ok(platform::GlSurface::build::<E, _>(window.0, config, picker)?.into())
58    }
59
60    pub fn create_context(&self, config: &[u32], share_context: GlContext) -> Result<GlContext, Error> {
61        Ok(self.0.create_context(config, share_context.0)?.into())
62    }
63}
64
65impl Destroy for GlSurface {
66    fn destroy(&mut self) -> Result<(), std::io::Error> {
67        self.0.destroy()
68    }
69}
70
71#[repr(C)]
72#[derive(Debug, Clone, Copy)]
73/// Just a wrapper struct around OpenGl context handle.
74pub struct GlContext(pub platform::GlContext);
75
76impl GlContext {
77    pub const NO_CONTEXT: Self = Self(platform::GlContext::NO_CONTEXT);
78}
79
80impl Destroy for GlContext {
81    fn destroy(&mut self) -> Result<(), std::io::Error> {
82        self.0.destroy()
83    }
84}
85
86impl From<platform::GlContext> for GlContext {
87    fn from(value: platform::GlContext) -> Self {
88        Self(value)
89    }
90}
91
92impl From<platform::GlSurface> for GlSurface {
93    fn from(value: platform::GlSurface) -> Self {
94        Self(value)
95    }
96}
97
98pub trait GlConfigPicker {
99    fn pick(&mut self, pixel_format: GlPixelFormat) -> Option<usize>;
100}