From 5c7a328ab90936d085bf4c98b347aceb4f45b187 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sun, 4 Mar 2018 15:06:21 +0100 Subject: [PATCH 1/2] Remove obsolete docs on removed Cargo features --- src/lib.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d2dff34ad9..eb7663ebf5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,16 +20,6 @@ //! //! For contexts that are *not* associated with any particular window, see the HeadlessContext //! type. -//! -//! # Features -//! -//! This crate has two Cargo features: `window` and `headless`. -//! -//! - `window` allows you to create regular windows and enables the `WindowBuilder` object. -//! - `headless` allows you to do headless rendering, and enables -//! the `HeadlessRendererBuilder` object. -//! -//! By default only `window` is enabled. #[cfg(target_os = "windows")] #[macro_use] From dfbab24e398de1e3cde054087f9d34cc2e15ed39 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sun, 4 Mar 2018 16:06:47 +0100 Subject: [PATCH 2/2] Add the `windows-static-egl` Cargo feature This allows using Glutin together with https://crates.io/crates/mozangle --- CHANGELOG.md | 1 + Cargo.toml | 5 ++++- appveyor.yml | 1 + examples/windows_static_egl.rs | 20 ++++++++++++++++++++ src/lib.rs | 12 ++++++++++++ src/platform/windows/mod.rs | 23 +++++++++++++++++++++-- 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 examples/windows_static_egl.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bf9b673cd..f99d1a6288 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased - Fix android activity life cycle +- Add the `windows-static-egl` Cargo feature. (See crate’s doc-comment.) # Version 0.13.0 (2018-02-28) diff --git a/Cargo.toml b/Cargo.toml index ee7073a7c1..b370096a4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "glutin" -version = "0.13.0" +version = "0.13.1" authors = ["The glutin contributors, Pierre Krieger "] description = "Cross-platform OpenGL context provider." keywords = ["windowing", "opengl"] @@ -10,6 +10,9 @@ repository = "https://github.com/tomaka/glutin" documentation = "https://docs.rs/glutin" build = "build.rs" +[features] +windows-static-egl = [] + [dependencies] lazy_static = "1" libc = "0.2" diff --git a/appveyor.yml b/appveyor.yml index 6a1b8dc19c..cbec58805a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,3 +15,4 @@ build: false test_script: - cargo test --verbose + - cargo build --features windows-static-egl --example windows_static_egl diff --git a/examples/windows_static_egl.rs b/examples/windows_static_egl.rs new file mode 100644 index 0000000000..efc0c4794e --- /dev/null +++ b/examples/windows_static_egl.rs @@ -0,0 +1,20 @@ +//! This incomplete example will likely crash at runtime on Windows +//! when the `windows-static-egl` feature is enabled, +//! but it should still compile and link. + +extern crate glutin; + +use std::os::raw::{c_char, c_void}; + +#[allow(non_snake_case)] +#[no_mangle] +pub extern fn eglGetProcAddress(_name: *const c_char) -> *const c_void { + 0 as _ +} + +fn main() { + let events_loop = glutin::EventsLoop::new(); + let window = glutin::WindowBuilder::new().with_title("A fantastic window!"); + let context = glutin::ContextBuilder::new(); + let _gl_window = glutin::GlWindow::new(window, context, &events_loop).unwrap(); +} diff --git a/src/lib.rs b/src/lib.rs index eb7663ebf5..3c723ac5b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,18 @@ //! //! For contexts that are *not* associated with any particular window, see the HeadlessContext //! type. +//! +//! # Features +//! +//! This crate has one Cargo feature: `windows-static-egl`. +//! +//! On Windows, when the `windows-static-egl` feature is enabled, +//! glutin assumes that `libEGL` is statically linked into the program, and uses it. +//! Specifically, it will look for this `extern` symbol: +//! +//! ```ignore +//! fn eglGetProcAddress(name: *const c_char) -> *const c_void; +//! ``` #[cfg(target_os = "windows")] #[macro_use] diff --git a/src/platform/windows/mod.rs b/src/platform/windows/mod.rs index 6dcb60a561..4c0e193bf1 100644 --- a/src/platform/windows/mod.rs +++ b/src/platform/windows/mod.rs @@ -31,9 +31,28 @@ pub enum RawHandle { struct EglWrapper(Egl); unsafe impl Sync for EglWrapper {} +#[cfg(feature = "windows-static-egl")] +fn static_egl() -> Option { + use std::os::raw::{c_char, c_void}; + + extern { + fn eglGetProcAddress(name: *const c_char) -> *const c_void; + } + + Some(EglWrapper(Egl::load_with(|name| { + let name = CString::new(name).unwrap(); + unsafe { eglGetProcAddress(name.as_ptr()) } + }))) +} + +#[cfg(not(feature = "windows-static-egl"))] +fn static_egl() -> Option { + None +} + lazy_static! { // An EGL implementation available on the system. - static ref EGL: Option = { + static ref EGL: Option = static_egl().or_else(|| { // the ATI drivers provide an EGL implementation in their DLLs let ati_dll_name = if cfg!(target_pointer_width = "64") { b"atio6axx.dll\0" @@ -56,7 +75,7 @@ lazy_static! { } None - }; + }); } /// The Win32 implementation of the main `Context` object.