Skip to content

Commit 5cfcb76

Browse files
authored
egl: support ANGLE on Windows
Angle provides libEGL.dll, which glutin loads. The only change necessary is to get the platform display via EGL_PLATFORM_ANGLE_ANGLE and treating it as a legacy display. Fixes #1508.
1 parent f5e08a8 commit 5cfcb76

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- **Breaking:** `GlContext` trait is now a part of the `prelude`.
77
- Fixed lock on SwapBuffers with some GLX drivers.
88
- Fixed EGL's `Surface::is_single_buffered` being inversed.
9+
- Added support for EGL on Windows using Angle. This assumes libEGL.dll/libGLESv2.dll present.
910

1011
# Version 0.30.8
1112

glutin/src/api/egl/display.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ impl Display {
241241
let extensions = NO_DISPLAY_EXTENSIONS.get().unwrap();
242242

243243
let mut attrs = Vec::<EGLint>::new();
244+
let mut legacy = false;
244245
let (platform, mut display) = match display {
245246
#[cfg(wayland_platform)]
246247
RawDisplayHandle::Wayland(handle)
@@ -266,6 +267,11 @@ impl Display {
266267
RawDisplayHandle::Gbm(handle) if extensions.contains("EGL_MESA_platform_gbm") => {
267268
(egl::PLATFORM_GBM_MESA, handle.gbm_device)
268269
},
270+
RawDisplayHandle::Windows(..) if extensions.contains("EGL_ANGLE_platform_angle") => {
271+
// Only CreateWindowSurface appears to work with Angle.
272+
legacy = true;
273+
(egl::PLATFORM_ANGLE_ANGLE, egl::DEFAULT_DISPLAY as *mut _)
274+
},
269275
_ => {
270276
return Err(
271277
ErrorKind::NotSupported("provided display handle is not supported").into()
@@ -284,7 +290,17 @@ impl Display {
284290
let display =
285291
unsafe { egl.GetPlatformDisplayEXT(platform, display as *mut _, attrs.as_ptr()) };
286292

287-
Self::check_display_error(display).map(EglDisplay::Ext)
293+
Self::check_display_error(display).map(|display| {
294+
if legacy {
295+
// NOTE: For angle we use the Legacy code path, as that uses CreateWindowSurface
296+
// instead of CreatePlatformWindowSurface*. The latter somehow
297+
// doesn't work, only the former does. But Angle's own example also use the
298+
// former: https://github.com/google/angle/blob/main/util/EGLWindow.cpp#L424
299+
EglDisplay::Legacy(display)
300+
} else {
301+
EglDisplay::Ext(display)
302+
}
303+
})
288304
}
289305

290306
fn get_display(egl: &Egl, display: RawDisplayHandle) -> Result<EglDisplay> {

glutin/src/display.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ pub enum DisplayApiPreference {
426426
///
427427
/// But despite this issues it should be preferred on at least Linux over
428428
/// GLX, given that GLX is phasing away.
429+
///
430+
/// # Platform-specific
431+
///
432+
/// **Windows:** ANGLE can be used if `libEGL.dll` and `libGLESv2.dll` are
433+
/// in the library search path.
429434
#[cfg(egl_backend)]
430435
Egl,
431436

glutin_egl_sys/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ pub mod egl {
3232
pub const PLATFORM_XCB_SCREEN_EXT: super::EGLenum = 0x31DE;
3333
// EGL_EXT_device_query_name
3434
pub const RENDERER_EXT: super::EGLenum = 0x335F;
35+
// EGL_ANGLE_platform_angle - https://chromium.googlesource.com/angle/angle/+/HEAD/extensions/EGL_ANGLE_platform_angle.txt
36+
pub const PLATFORM_ANGLE_ANGLE: super::EGLenum = 0x3202;
37+
pub const PLATFORM_ANGLE_TYPE_ANGLE: super::EGLenum = 0x3203;
38+
pub const PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE: super::EGLenum = 0x3204;
39+
pub const PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE: super::EGLenum = 0x3205;
40+
pub const PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED: super::EGLenum = 0x3451;
41+
pub const PLATFORM_ANGLE_NATIVE_PLATFORM_TYPE_ANGLE: super::EGLenum = 0x348F;
42+
pub const PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE: super::EGLenum = 0x3206;
43+
pub const PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE: super::EGLenum = 0x320A;
44+
pub const PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE: super::EGLenum = 0x345E;
3545
}
3646

3747
pub use self::egl::types::{EGLContext, EGLDisplay};

0 commit comments

Comments
 (0)