From c9b1b91b8cb7e43c0908c04afaefb8e49e0f2b35 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 27 Jul 2015 09:52:51 +0200 Subject: Load the EGL library in platform/windows --- src/platform/windows/mod.rs | 69 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) (limited to 'src/platform') diff --git a/src/platform/windows/mod.rs b/src/platform/windows/mod.rs index b33b8ee..c062dfc 100644 --- a/src/platform/windows/mod.rs +++ b/src/platform/windows/mod.rs @@ -1,6 +1,8 @@ #![cfg(target_os = "windows")] -pub use api::win32::*; +pub use api::win32; +pub use api::win32::{MonitorID, get_available_monitors, get_primary_monitor}; +pub use api::win32::{WindowProxy, PollEventsIterator, WaitEventsIterator}; use libc; @@ -11,13 +13,74 @@ use CreationError; use PixelFormat; use GlContext; +use api::egl::ffi::egl::Egl; + +use std::ffi::CString; +use std::ops::{Deref, DerefMut}; +use kernel32; + +/// Stupid wrapper because `*const libc::c_void` doesn't implement `Sync`. +struct EglWrapper(Egl); +unsafe impl Sync for EglWrapper {} + +lazy_static! { + // An EGL implementation available on the system. + static ref EGL: Option = { + // the ATI drivers provide an EGL implementation in their DLLs + let dll_name = if cfg!(target_pointer_width = "64") { + b"atio6axx.dll\0" + } else { + b"atioglxx.dll\0" + }; + + let dll = unsafe { kernel32::LoadLibraryA(dll_name.as_ptr() as *const _) }; + + if !dll.is_null() { + let egl = Egl::load_with(|name| { + let name = CString::new(name).unwrap(); + unsafe { kernel32::GetProcAddress(dll, name.as_ptr()) as *const _ } + }); + + Some(EglWrapper(egl)) + + } else { + None + } + }; +} + + +/// The Win32 implementation of the main `Window` object. +pub struct Window(win32::Window); + +impl Window { + /// See the docs in the crate root file. + pub fn new(builder: BuilderAttribs) -> Result { + win32::Window::new(builder, EGL.as_ref().map(|w| &w.0)).map(|w| Window(w)) + } +} + +impl Deref for Window { + type Target = win32::Window; + + fn deref(&self) -> &win32::Window { + &self.0 + } +} + +impl DerefMut for Window { + fn deref_mut(&mut self) -> &mut win32::Window { + &mut self.0 + } +} + /// -pub struct HeadlessContext(Window); +pub struct HeadlessContext(win32::Window); impl HeadlessContext { pub fn new(mut builder: BuilderAttribs) -> Result { builder.visible = false; - Window::new(builder).map(|w| HeadlessContext(w)) + win32::Window::new(builder, EGL.as_ref().map(|w| &w.0)).map(|w| HeadlessContext(w)) } } -- cgit v1.2.3