diff --git a/CHANGELOG.md b/CHANGELOG.md index 4de13ca47a..bd039fe34c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Bump MSRV from `1.65` to `1.70`. - Bump `windows-sys` from `0.48.0` to `0.52.0`. - Expose `Egl` and `Glx` raw API functions on `Egl` and `Glx` displays. +- Add `GLUTIN_WGL_OPENGL_DLL` environment variable to change OpenGL provider name with WGL. # Version 0.31.3 diff --git a/glutin/src/api/wgl/display.rs b/glutin/src/api/wgl/display.rs index ac14a4387a..1446938266 100644 --- a/glutin/src/api/wgl/display.rs +++ b/glutin/src/api/wgl/display.rs @@ -1,10 +1,11 @@ //! WGL display initialization and extension loading. +use std::borrow::Cow; use std::collections::HashSet; use std::ffi::{self, CStr, OsStr}; -use std::fmt; use std::os::windows::ffi::OsStrExt; use std::sync::Arc; +use std::{env, fmt}; use glutin_wgl_sys::wgl; use raw_window_handle::{RawDisplayHandle, RawWindowHandle}; @@ -24,6 +25,9 @@ use super::context::NotCurrentContext; use super::surface::Surface; use super::WglExtra; +/// The name of the OpenGL DLL to use. +pub(crate) static GLUTIN_WGL_OPENGL_DLL_ENV: &str = "GLUTIN_WGL_OPENGL_DLL"; + /// A WGL display. #[derive(Debug, Clone)] pub struct Display { @@ -37,6 +41,9 @@ impl Display { /// passed the OpenGL will be limited to what it can do, though, basic /// operations could still be performed. /// + /// You can alter OpenGL DLL name by setting `GLUTIN_WGL_OPENGL_DLL` + /// environment variable. The default one is `opengl32.dll`. + /// /// # Safety /// /// The `native_window` must point to the valid platform window and have @@ -49,8 +56,10 @@ impl Display { return Err(ErrorKind::NotSupported("provided native display is not supported").into()); } - let name = - OsStr::new("opengl32.dll").encode_wide().chain(Some(0).into_iter()).collect::>(); + let dll_name: Cow<'_, str> = env::var(GLUTIN_WGL_OPENGL_DLL_ENV) + .map(Into::into) + .unwrap_or_else(|_| Cow::Borrowed("opengl32.dll")); + let name = OsStr::new(dll_name.as_ref()).encode_wide().chain(Some(0)).collect::>(); let lib_opengl32 = unsafe { dll_loader::LoadLibraryW(name.as_ptr()) }; if lib_opengl32 == 0 { return Err(ErrorKind::NotFound.into()); diff --git a/glutin/src/api/wgl/mod.rs b/glutin/src/api/wgl/mod.rs index 9548ecb1fb..9fd7ec3777 100644 --- a/glutin/src/api/wgl/mod.rs +++ b/glutin/src/api/wgl/mod.rs @@ -74,8 +74,7 @@ unsafe fn load_extra_functions( class }; - let class_name = - OsStr::new("WglDummy Window").encode_wide().chain(Some(0).into_iter()).collect::>(); + let class_name = OsStr::new("WglDummy Window").encode_wide().chain(Some(0)).collect::>(); class.cbSize = mem::size_of::() as _; class.lpszClassName = class_name.as_ptr(); @@ -89,8 +88,7 @@ unsafe fn load_extra_functions( // This dummy window should match the real one enough to get the same OpenGL // driver. - let title = - OsStr::new("dummy window").encode_wide().chain(Some(0).into_iter()).collect::>(); + let title = OsStr::new("dummy window").encode_wide().chain(Some(0)).collect::>(); let ex_style = wm::WS_EX_APPWINDOW; let style = wm::WS_POPUP | wm::WS_CLIPSIBLINGS | wm::WS_CLIPCHILDREN; diff --git a/glutin/src/lib.rs b/glutin/src/lib.rs index 5fa6481bbb..a40ace33ac 100644 --- a/glutin/src/lib.rs +++ b/glutin/src/lib.rs @@ -9,6 +9,10 @@ //! The initialization starts by loading and connecting to the platform's //! graphics Api when creating a [`display`]. This object is used to create all //! the OpenGL objects, such as [`config`], [`context`], and [`surface`]. +//! +//! ## Environment variables +//! +//! `GLUTIN_WGL_OPENGL_DLL` - change the name of the OpenGL DLL to load. #![deny(rust_2018_idioms)] #![deny(rustdoc::broken_intra_doc_links)]