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 the windows-static-egl Cargo feature #998

Closed
Closed
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
@@ -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)

Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "glutin"
version = "0.13.0"
version = "0.13.1"
authors = ["The glutin contributors, Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "Cross-platform OpenGL context provider."
keywords = ["windowing", "opengl"]
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ build: false

test_script:
- cargo test --verbose
- cargo build --features windows-static-egl --example windows_static_egl
20 changes: 20 additions & 0 deletions examples/windows_static_egl.rs
Original file line number Diff line number Diff line change
@@ -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();
}
12 changes: 7 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
//!
//! # Features
//!
//! This crate has two Cargo features: `window` and `headless`.
//! This crate has one Cargo feature: `windows-static-egl`.
//!
//! - `window` allows you to create regular windows and enables the `WindowBuilder` object.
//! - `headless` allows you to do headless rendering, and enables
//! the `HeadlessRendererBuilder` object.
//! 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:
//!
//! By default only `window` is enabled.
//! ```ignore
//! fn eglGetProcAddress(name: *const c_char) -> *const c_void;
//! ```

#[cfg(target_os = "windows")]
#[macro_use]
Expand Down
23 changes: 21 additions & 2 deletions src/platform/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,28 @@ pub enum RawHandle {
struct EglWrapper(Egl);
unsafe impl Sync for EglWrapper {}

#[cfg(feature = "windows-static-egl")]
fn static_egl() -> Option<EglWrapper> {
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<EglWrapper> {
None
}

lazy_static! {
// An EGL implementation available on the system.
static ref EGL: Option<EglWrapper> = {
static ref EGL: Option<EglWrapper> = 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"
Expand All @@ -56,7 +75,7 @@ lazy_static! {
}

None
};
});
}

/// The Win32 implementation of the main `Context` object.
Expand Down