Skip to content

Commit

Permalink
egl: support ANGLE on Windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tronical authored and kchibisov committed Aug 6, 2023
1 parent 7d7176f commit 9c8b8bd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- Added support for EGL on Windows using Angle. This assumes libEGL.dll/libGLESv2.dll present.

# Version 0.30.9

- Fixed lock on SwapBuffers with some GLX drivers.
Expand Down
18 changes: 17 additions & 1 deletion glutin/src/api/egl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ impl Display {
let extensions = NO_DISPLAY_EXTENSIONS.get().unwrap();

let mut attrs = Vec::<EGLint>::new();
let mut legacy = false;
let (platform, mut display) = match display {
#[cfg(wayland_platform)]
RawDisplayHandle::Wayland(handle)
Expand All @@ -266,6 +267,11 @@ impl Display {
RawDisplayHandle::Gbm(handle) if extensions.contains("EGL_MESA_platform_gbm") => {
(egl::PLATFORM_GBM_MESA, handle.gbm_device)
},
RawDisplayHandle::Windows(..) if extensions.contains("EGL_ANGLE_platform_angle") => {
// Only CreateWindowSurface appears to work with Angle.
legacy = true;
(egl::PLATFORM_ANGLE_ANGLE, egl::DEFAULT_DISPLAY as *mut _)
},
_ => {
return Err(
ErrorKind::NotSupported("provided display handle is not supported").into()
Expand All @@ -284,7 +290,17 @@ impl Display {
let display =
unsafe { egl.GetPlatformDisplayEXT(platform, display as *mut _, attrs.as_ptr()) };

Self::check_display_error(display).map(EglDisplay::Ext)
Self::check_display_error(display).map(|display| {
if legacy {
// NOTE: For angle we use the Legacy code path, as that uses CreateWindowSurface
// instead of CreatePlatformWindowSurface*. The latter somehow
// doesn't work, only the former does. But Angle's own example also use the
// former: https://github.com/google/angle/blob/main/util/EGLWindow.cpp#L424
EglDisplay::Legacy(display)
} else {
EglDisplay::Ext(display)
}
})
}

fn get_display(egl: &Egl, display: RawDisplayHandle) -> Result<EglDisplay> {
Expand Down
5 changes: 5 additions & 0 deletions glutin/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ pub enum DisplayApiPreference {
///
/// But despite this issues it should be preferred on at least Linux over
/// GLX, given that GLX is phasing away.
///
/// # Platform-specific
///
/// **Windows:** ANGLE can be used if `libEGL.dll` and `libGLESv2.dll` are
/// in the library search path.
#[cfg(egl_backend)]
Egl,

Expand Down
10 changes: 10 additions & 0 deletions glutin_egl_sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ pub mod egl {
pub const PLATFORM_XCB_SCREEN_EXT: super::EGLenum = 0x31DE;
// EGL_EXT_device_query_name
pub const RENDERER_EXT: super::EGLenum = 0x335F;
// EGL_ANGLE_platform_angle - https://chromium.googlesource.com/angle/angle/+/HEAD/extensions/EGL_ANGLE_platform_angle.txt
pub const PLATFORM_ANGLE_ANGLE: super::EGLenum = 0x3202;
pub const PLATFORM_ANGLE_TYPE_ANGLE: super::EGLenum = 0x3203;
pub const PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE: super::EGLenum = 0x3204;
pub const PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE: super::EGLenum = 0x3205;
pub const PLATFORM_ANGLE_DEBUG_LAYERS_ENABLED: super::EGLenum = 0x3451;
pub const PLATFORM_ANGLE_NATIVE_PLATFORM_TYPE_ANGLE: super::EGLenum = 0x348F;
pub const PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE: super::EGLenum = 0x3206;
pub const PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE: super::EGLenum = 0x320A;
pub const PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE: super::EGLenum = 0x345E;
}

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

0 comments on commit 9c8b8bd

Please sign in to comment.