Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for creating glutin EGL displays on Windows using Angle #1611

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- **Breaking:** `GlContext` trait is now a part of the `prelude`.
- Fixed lock on SwapBuffers with some GLX drivers.
- Fixed EGL's `Surface::is_single_buffered` being inversed.
- Added support for EGL on Windows using Angle. This assumes libEGL.dll/libGLESv2.dll present.
tronical marked this conversation as resolved.
Show resolved Hide resolved

# Version 0.30.8

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)
tronical marked this conversation as resolved.
Show resolved Hide resolved
} 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 @@ -426,6 +426,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;
tronical marked this conversation as resolved.
Show resolved Hide resolved
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