mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
Merge pull request #344 from tomaka/gles-win32
Add support for GLES on Win32
This commit is contained in:
commit
aa97fac6ff
8
build.rs
8
build.rs
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue