From ac23d3114cf40628098d9e5574cb059aa0f22aee Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sat, 11 Apr 2015 23:30:17 -0400 Subject: [PATCH] Implemented get_pixel_format for X11 --- Cargo.toml | 2 +- build.rs | 2 ++ src/x11/window/mod.rs | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 16fe474f..41141089 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "glutin" -version = "0.0.23" +version = "0.0.24" authors = ["tomaka "] description = "Cross-plaform OpenGL context provider." keywords = ["windowing", "opengl"] diff --git a/build.rs b/build.rs index 1824a7a4..ca955743 100644 --- a/build.rs +++ b/build.rs @@ -52,6 +52,8 @@ fn main() { khronos_api::GLX_XML, vec![ "GLX_ARB_create_context".to_string(), + "GLX_ARB_framebuffer_sRGB".to_string(), + "GLX_EXT_framebuffer_sRGB".to_string(), "GLX_EXT_swap_control".to_string(), "GLX_SGI_swap_control".to_string() ], diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs index db24312c..83f8a190 100644 --- a/src/x11/window/mod.rs +++ b/src/x11/window/mod.rs @@ -281,6 +281,7 @@ pub struct Window { is_closed: AtomicBool, wm_delete_window: ffi::Atom, current_size: Cell<(libc::c_int, libc::c_int)>, + pixel_format: PixelFormat, /// Events that have been retreived with XLib but not dispatched with iterators yet pending_events: Mutex>, cursor_state: Mutex, @@ -328,6 +329,11 @@ impl Window { visual_attributes.push(val as libc::c_int); } + if let Some(val) = builder.srgb { + visual_attributes.push(ffi::glx_extra::FRAMEBUFFER_SRGB_CAPABLE_ARB as libc::c_int); + visual_attributes.push(if val {1} else {0}); + } + visual_attributes.push(0); let mut num_fb: libc::c_int = mem::uninitialized(); @@ -378,6 +384,31 @@ impl Window { vi_copy }; + // querying the chosen pixel format + let pixel_format = { + let get_attrib = |attrib: libc::c_int| -> i32 { + let mut value = 0; + unsafe { ffi::glx::GetFBConfigAttrib(display, fb_config, attrib, &mut value); } + value + }; + + PixelFormat { + hardware_accelerated: true, + red_bits: get_attrib(ffi::GLX_RED_SIZE) as u8, + green_bits: get_attrib(ffi::GLX_GREEN_SIZE) as u8, + blue_bits: get_attrib(ffi::GLX_BLUE_SIZE) as u8, + alpha_bits: get_attrib(ffi::GLX_ALPHA_SIZE) as u8, + depth_bits: get_attrib(ffi::GLX_DEPTH_SIZE) as u8, + stencil_bits: get_attrib(ffi::GLX_STENCIL_SIZE) as u8, + stereoscopy: get_attrib(ffi::GLX_STEREO) != 0, + double_buffer: get_attrib(ffi::GLX_DOUBLEBUFFER) != 0, + multisampling: if get_attrib(ffi::glx::SAMPLE_BUFFERS as libc::c_int) != 0 { + Some(get_attrib(ffi::glx::SAMPLES as libc::c_int) as u16) + }else { None }, + srgb: get_attrib(ffi::glx_extra::FRAMEBUFFER_SRGB_CAPABLE_ARB as libc::c_int) != 0, + } + }; + // getting the root window let root = unsafe { ffi::XDefaultRootWindow(display) }; @@ -600,6 +631,7 @@ impl Window { is_closed: AtomicBool::new(false), wm_delete_window: wm_delete_window, current_size: Cell::new((0, 0)), + pixel_format: pixel_format, pending_events: Mutex::new(VecDeque::new()), cursor_state: Mutex::new(CursorState::Normal), }; @@ -734,7 +766,7 @@ impl Window { } pub fn get_pixel_format(&self) -> PixelFormat { - unimplemented!(); + self.pixel_format.clone() } pub fn set_window_resize_callback(&mut self, _: Option) {