diff options
author | Pierre Krieger <pierre.krieger1708@gmail.com> | 2015-02-16 15:55:26 +0100 |
---|---|---|
committer | Pierre Krieger <pierre.krieger1708@gmail.com> | 2015-02-16 15:55:26 +0100 |
commit | 950fd58b77041f4c2e62be1e345df8554a447623 (patch) | |
tree | 625ff3e1edc8a690c66663b75817471689a01ca1 /src/win32 | |
parent | d1bc85c011ae8328936ba7bef9cd8c463e040dd3 (diff) | |
download | glutin-950fd58b77041f4c2e62be1e345df8554a447623.tar.gz glutin-950fd58b77041f4c2e62be1e345df8554a447623.zip |
Implement enumerate_arb_pixel_formats
Diffstat (limited to 'src/win32')
-rw-r--r-- | src/win32/init.rs | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/src/win32/init.rs b/src/win32/init.rs index efb4405..9803e43 100644 --- a/src/win32/init.rs +++ b/src/win32/init.rs @@ -462,6 +462,52 @@ fn enumerate_native_pixel_formats(hdc: winapi::HDC) -> Vec<(PixelFormat, libc::c result } -fn enumerate_arb_pixel_formats(extra: &gl::wgl_extra::Wgl, hdc: winapi::HDC) -> Vec<PixelFormat> { - unimplemented!() +fn enumerate_arb_pixel_formats(extra: &gl::wgl_extra::Wgl, hdc: winapi::HDC) + -> Vec<(PixelFormat, libc::c_int)> +{ + let get_info = |index: u32, attrib: u32| { + let mut value = unsafe { mem::uninitialized() }; + unsafe { extra.GetPixelFormatAttribivARB(hdc as *const libc::c_void, index as libc::c_int, + 0, 1, [attrib as libc::c_int].as_ptr(), + &mut value) }; + value as u32 + }; + + // getting the number of formats + // the `1` is ignored + let num = get_info(1, gl::wgl_extra::NUMBER_PIXEL_FORMATS_ARB); + + let mut result = Vec::new(); + + for index in (0 .. num) { + if get_info(index, gl::wgl_extra::DRAW_TO_WINDOW_ARB) == 0 { + continue; + } + if get_info(index, gl::wgl_extra::SUPPORT_OPENGL_ARB) == 0 { + continue; + } + + if get_info(index, gl::wgl_extra::ACCELERATION_ARB) == gl::wgl_extra::NO_ACCELERATION_ARB { + continue; + } + + if get_info(index, gl::wgl_extra::PIXEL_TYPE_ARB) != gl::wgl_extra::TYPE_RGBA_ARB { + continue; + } + + result.push((PixelFormat { + red_bits: get_info(index, gl::wgl_extra::RED_BITS_ARB) as u8, + green_bits: get_info(index, gl::wgl_extra::GREEN_BITS_ARB) as u8, + blue_bits: get_info(index, gl::wgl_extra::BLUE_BITS_ARB) as u8, + alpha_bits: get_info(index, gl::wgl_extra::ALPHA_BITS_ARB) as u8, + depth_bits: get_info(index, gl::wgl_extra::DEPTH_BITS_ARB) as u8, + stencil_bits: get_info(index, gl::wgl_extra::STENCIL_BITS_ARB) as u8, + stereoscopy: get_info(index, gl::wgl_extra::STEREO_ARB) != 0, + double_buffer: get_info(index, gl::wgl_extra::DOUBLE_BUFFER_ARB) != 0, + multisampling: None, // FIXME: + srgb: false, // FIXME: + }, index as libc::c_int)); + } + + result } |