glutin_egl_sys/
egl.rs

1//! Manual implementation of EGL bindings.
2//!
3//! This is necessary since `gl_generator` is unmaintaned and incapable of
4//! generating bindings for some of the newer extensions.
5
6use std::ffi::c_uint;
7
8pub type khronos_utime_nanoseconds_t = super::khronos_utime_nanoseconds_t;
9pub type khronos_uint64_t = super::khronos_uint64_t;
10pub type khronos_ssize_t = super::khronos_ssize_t;
11pub type EGLNativeDisplayType = super::EGLNativeDisplayType;
12pub type EGLNativePixmapType = super::EGLNativePixmapType;
13pub type EGLNativeWindowType = super::EGLNativeWindowType;
14pub type EGLint = super::EGLint;
15pub type NativeDisplayType = super::EGLNativeDisplayType;
16pub type NativePixmapType = super::EGLNativePixmapType;
17pub type NativeWindowType = super::EGLNativeWindowType;
18
19include!(concat!(env!("OUT_DIR"), "/egl_bindings.rs"));
20
21// EGL_EXT_platform_xcb
22pub const PLATFORM_XCB_EXT: super::EGLenum = 0x31DC;
23pub const PLATFORM_XCB_SCREEN_EXT: super::EGLenum = 0x31DE;
24// EGL_EXT_device_query_name
25pub const RENDERER_EXT: super::EGLenum = 0x335F;
26// EGL_ANGLE_platform_angle - https://chromium.googlesource.com/angle/angle/+/HEAD/extensions/EGL_ANGLE_platform_angle.txt
27pub const PLATFORM_ANGLE_ANGLE: super::EGLenum = 0x3202;
28pub const PLATFORM_ANGLE_TYPE_ANGLE: super::EGLenum = 0x3203;
29pub const PLATFORM_ANGLE_TYPE_VULKAN_ANGLE: super::EGLenum = 0x3450;
30pub const PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE: super::EGLenum = 0x3204;
31pub const PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE: super::EGLenum = 0x3205;
32pub const PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED: super::EGLenum = 0x3451;
33pub const PLATFORM_ANGLE_NATIVE_PLATFORM_TYPE_ANGLE: super::EGLenum = 0x348F;
34pub const PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE: super::EGLenum = 0x3206;
35pub const PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE: super::EGLenum = 0x320A;
36pub const PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE: super::EGLenum = 0x345E;
37
38mod wayland_storage {
39    use super::FnPtr;
40    use super::__gl_imports::raw;
41
42    // EGL_WL_create_wayland_buffer_from_image
43    pub static mut CREATE_WAYLAND_BUFFER_FROM_IMAGE_WL: FnPtr =
44        FnPtr { f: super::missing_fn_panic as *const raw::c_void, is_loaded: false };
45
46    // EGL_WL_bind_wayland_display
47    pub static mut BIND_WAYLAND_DISPLAY_WL: FnPtr =
48        FnPtr { f: super::missing_fn_panic as *const raw::c_void, is_loaded: false };
49    pub static mut UNBIND_WAYLAND_DISPLAY_WL: FnPtr =
50        FnPtr { f: super::missing_fn_panic as *const raw::c_void, is_loaded: false };
51    pub static mut QUERY_WAYLAND_BUFFER_WL: FnPtr =
52        FnPtr { f: super::missing_fn_panic as *const raw::c_void, is_loaded: false };
53}
54
55impl Egl {
56    #[allow(non_snake_case, unused_variables, dead_code)]
57    #[inline]
58    pub unsafe fn CreateWaylandBufferFromImageWL(
59        &self,
60        dpy: types::EGLDisplay,
61        image: types::EGLImageKHR,
62    ) -> *mut std::ffi::c_void {
63        __gl_imports::mem::transmute::<
64            _,
65            extern "system" fn(types::EGLDisplay, types::EGLImageKHR) -> *mut std::ffi::c_void,
66        >(wayland_storage::CREATE_WAYLAND_BUFFER_FROM_IMAGE_WL.f)(dpy, image)
67    }
68
69    #[allow(non_snake_case, unused_variables, dead_code)]
70    #[inline]
71    pub unsafe fn BindWaylandDisplayWL(
72        &self,
73        dpy: types::EGLDisplay,
74        display: *mut __gl_imports::raw::c_void,
75    ) -> types::EGLBoolean {
76        __gl_imports::mem::transmute::<
77            _,
78            extern "system" fn(
79                types::EGLDisplay,
80                *mut __gl_imports::raw::c_void,
81            ) -> types::EGLBoolean,
82        >(wayland_storage::BIND_WAYLAND_DISPLAY_WL.f)(dpy, display)
83    }
84
85    #[allow(non_snake_case, unused_variables, dead_code)]
86    #[inline]
87    pub unsafe fn UnbindWaylandDisplayWL(
88        &self,
89        dpy: types::EGLDisplay,
90        display: *mut __gl_imports::raw::c_void,
91    ) -> types::EGLBoolean {
92        __gl_imports::mem::transmute::<
93            _,
94            extern "system" fn(
95                types::EGLDisplay,
96                *mut __gl_imports::raw::c_void,
97            ) -> types::EGLBoolean,
98        >(wayland_storage::UNBIND_WAYLAND_DISPLAY_WL.f)(dpy, display)
99    }
100
101    #[allow(non_snake_case, unused_variables, dead_code)]
102    #[inline]
103    pub unsafe fn QueryWaylandBufferWL(
104        &self,
105        dpy: types::EGLDisplay,
106        buffer: *mut __gl_imports::raw::c_void,
107        attribute: types::EGLint,
108        value: *mut types::EGLint,
109    ) -> types::EGLBoolean {
110        __gl_imports::mem::transmute::<
111            _,
112            extern "system" fn(
113                types::EGLDisplay,
114                *mut __gl_imports::raw::c_void,
115                types::EGLint,
116                *mut types::EGLint,
117            ) -> types::EGLBoolean,
118        >(wayland_storage::QUERY_WAYLAND_BUFFER_WL.f)(dpy, buffer, attribute, value)
119    }
120}
121
122// Extension: EGL_WL_create_wayland_buffer_from_image
123//
124
125#[allow(non_snake_case)]
126pub mod CreateWaylandBufferFromImageWL {
127    use super::__gl_imports::raw;
128    use super::{metaloadfn, wayland_storage, FnPtr};
129
130    #[inline]
131    #[allow(dead_code)]
132    pub fn is_loaded() -> bool {
133        unsafe { wayland_storage::CREATE_WAYLAND_BUFFER_FROM_IMAGE_WL.is_loaded }
134    }
135
136    #[allow(dead_code)]
137    pub fn load_with<F>(mut loadfn: F)
138    where
139        F: FnMut(&'static str) -> *const raw::c_void,
140    {
141        unsafe {
142            wayland_storage::CREATE_WAYLAND_BUFFER_FROM_IMAGE_WL =
143                FnPtr::new(metaloadfn(&mut loadfn, "eglCreateWaylandBufferFromImageWL", &[]))
144        }
145    }
146}
147
148// Extension: EGL_WL_bind_wayland_display
149//
150
151// Accepted as <target> in eglCreateImageKHR.
152pub const WAYLAND_BUFFER_WL: c_uint = 0x31D5;
153// Accepted in the <attrib_list> parameter of eglCreateImageKHR.
154pub const WAYLAND_PLANE_WL: c_uint = 0x31D6;
155// Possible values for EGL_TEXTURE_FORMAT.
156pub const TEXTURE_Y_U_V_WL: i32 = 0x31D7;
157pub const TEXTURE_Y_UV_WL: i32 = 0x31D8;
158pub const TEXTURE_Y_XUXV_WL: i32 = 0x31D9;
159pub const TEXTURE_EXTERNAL_WL: i32 = 0x31DA;
160pub const WAYLAND_Y_INVERTED_WL: i32 = 0x31DB;
161
162#[allow(non_snake_case)]
163pub mod BindWaylandDisplayWL {
164    use super::__gl_imports::raw;
165    use super::{metaloadfn, wayland_storage, FnPtr};
166
167    #[inline]
168    #[allow(dead_code)]
169    pub fn is_loaded() -> bool {
170        unsafe { wayland_storage::BIND_WAYLAND_DISPLAY_WL.is_loaded }
171    }
172
173    #[allow(dead_code)]
174    pub fn load_with<F>(mut loadfn: F)
175    where
176        F: FnMut(&'static str) -> *const raw::c_void,
177    {
178        unsafe {
179            wayland_storage::BIND_WAYLAND_DISPLAY_WL =
180                FnPtr::new(metaloadfn(&mut loadfn, "eglBindWaylandDisplayWL", &[]))
181        }
182    }
183}
184
185#[allow(non_snake_case)]
186pub mod UnbindWaylandDisplayWL {
187    use super::__gl_imports::raw;
188    use super::{metaloadfn, wayland_storage, FnPtr};
189
190    #[inline]
191    #[allow(dead_code)]
192    pub fn is_loaded() -> bool {
193        unsafe { wayland_storage::UNBIND_WAYLAND_DISPLAY_WL.is_loaded }
194    }
195
196    #[allow(dead_code)]
197    pub fn load_with<F>(mut loadfn: F)
198    where
199        F: FnMut(&'static str) -> *const raw::c_void,
200    {
201        unsafe {
202            wayland_storage::UNBIND_WAYLAND_DISPLAY_WL =
203                FnPtr::new(metaloadfn(&mut loadfn, "eglUnbindWaylandDisplayWL", &[]))
204        }
205    }
206}
207
208#[allow(non_snake_case)]
209pub mod QueryWaylandBufferWL {
210    use super::__gl_imports::raw;
211    use super::{metaloadfn, wayland_storage, FnPtr};
212
213    #[inline]
214    #[allow(dead_code)]
215    pub fn is_loaded() -> bool {
216        unsafe { wayland_storage::QUERY_WAYLAND_BUFFER_WL.is_loaded }
217    }
218
219    #[allow(dead_code)]
220    pub fn load_with<F>(mut loadfn: F)
221    where
222        F: FnMut(&'static str) -> *const raw::c_void,
223    {
224        unsafe {
225            wayland_storage::QUERY_WAYLAND_BUFFER_WL =
226                FnPtr::new(metaloadfn(&mut loadfn, "eglQueryWaylandBufferWL", &[]))
227        }
228    }
229}
230
231/// OpenGL function loader.
232///
233/// This is based on the loader generated by `gl_generator`.
234#[inline(never)]
235fn metaloadfn(
236    loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::raw::c_void,
237    symbol: &'static str,
238    fallbacks: &[&'static str],
239) -> *const __gl_imports::raw::c_void {
240    let mut ptr = loadfn(symbol);
241    if ptr.is_null() {
242        for &sym in fallbacks {
243            ptr = loadfn(sym);
244            if !ptr.is_null() {
245                break;
246            }
247        }
248    }
249    ptr
250}