diff options
author | tomaka <pierre.krieger1708@gmail.com> | 2015-04-02 13:22:59 +0200 |
---|---|---|
committer | tomaka <pierre.krieger1708@gmail.com> | 2015-04-02 13:22:59 +0200 |
commit | aa97fac6fffd9f7ffcbfb9e8795e75d6f0d61582 (patch) | |
tree | e5f5196af7e8d5808275a9bb440d4689e96792f1 | |
parent | a1ce4b6616163659c0d6065401b0c89af7919dce (diff) | |
parent | eabfa9e62443e8ad6510dec66b0b950b99b79509 (diff) | |
download | glutin-aa97fac6fffd9f7ffcbfb9e8795e75d6f0d61582.tar.gz glutin-aa97fac6fffd9f7ffcbfb9e8795e75d6f0d61582.zip |
Merge pull request #344 from tomaka/gles-win32
Add support for GLES on Win32
-rw-r--r-- | build.rs | 8 | ||||
-rw-r--r-- | src/win32/init.rs | 39 |
2 files changed, 43 insertions, 4 deletions
@@ -26,9 +26,13 @@ fn main() { khronos_api::WGL_XML, vec![ "WGL_ARB_create_context".to_string(), - "WGL_EXT_swap_control".to_string(), - "WGL_ARB_pixel_format".to_string(), + "WGL_ARB_create_context_profile".to_string(), + "WGL_ARB_extensions_string".to_string(), "WGL_ARB_framebuffer_sRGB".to_string(), + "WGL_ARB_pixel_format".to_string(), + "WGL_EXT_create_context_es2_profile".to_string(), + "WGL_EXT_extensions_string".to_string(), + "WGL_EXT_swap_control".to_string(), ], "1.0", "core", &mut file).unwrap(); } diff --git a/src/win32/init.rs b/src/win32/init.rs index 08fb3b3..d0012e2 100644 --- a/src/win32/init.rs +++ b/src/win32/init.rs @@ -23,7 +23,7 @@ use CursorState; use GlRequest; use PixelFormat; -use std::ffi::CString; +use std::ffi::{CStr, CString}; use std::sync::mpsc::channel; use libc; @@ -344,7 +344,22 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st attributes.push(gl::wgl_extra::CONTEXT_MINOR_VERSION_ARB as libc::c_int); attributes.push(minor as libc::c_int); }, - GlRequest::Specific(_, _) => panic!("Only OpenGL is supported"), + GlRequest::Specific(Api::OpenGlEs, (major, minor)) => { + if is_extension_supported(extra_functions, hdc, + "WGL_EXT_create_context_es2_profile") + { + attributes.push(gl::wgl_extra::CONTEXT_PROFILE_MASK_ARB as libc::c_int); + attributes.push(gl::wgl_extra::CONTEXT_ES2_PROFILE_BIT_EXT as libc::c_int); + } else { + return Err(CreationError::NotSupported); + } + + attributes.push(gl::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int); + attributes.push(major as libc::c_int); + attributes.push(gl::wgl_extra::CONTEXT_MINOR_VERSION_ARB as libc::c_int); + attributes.push(minor as libc::c_int); + }, + GlRequest::Specific(_, _) => return Err(CreationError::NotSupported), GlRequest::GlThenGles { opengl_version: (major, minor), .. } => { attributes.push(gl::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int); attributes.push(major as libc::c_int); @@ -515,3 +530,23 @@ unsafe fn load_opengl32_dll() -> Result<winapi::HMODULE, CreationError> { Ok(lib) } + +unsafe fn is_extension_supported(extra: &gl::wgl_extra::Wgl, hdc: &WindowWrapper, + extension: &str) -> bool +{ + let extensions = if extra.GetExtensionsStringARB.is_loaded() { + let data = extra.GetExtensionsStringARB(hdc.1 as *const _); + let data = CStr::from_ptr(data).to_bytes().to_vec(); + String::from_utf8(data).unwrap() + + } else if extra.GetExtensionsStringEXT.is_loaded() { + let data = extra.GetExtensionsStringEXT(); + let data = CStr::from_ptr(data).to_bytes().to_vec(); + String::from_utf8(data).unwrap() + + } else { + return false; + }; + + extensions.split(" ").find(|&e| e == extension).is_some() +} |