diff options
author | tomaka <pierre.krieger1708@gmail.com> | 2015-01-25 12:56:15 +0100 |
---|---|---|
committer | tomaka <pierre.krieger1708@gmail.com> | 2015-01-25 12:56:15 +0100 |
commit | f8c66ff2a9979c9107221833d46d8841e8a90127 (patch) | |
tree | 6941107e1bbc096d49edf56e797aeb696c35cdc4 /src/x11/window/mod.rs | |
parent | a2e03e7c15de276cd0f59955f92e959918f836e8 (diff) | |
parent | b05ef16d817af85d175d60422591d90fe3ec4218 (diff) | |
download | glutin-f8c66ff2a9979c9107221833d46d8841e8a90127.tar.gz glutin-f8c66ff2a9979c9107221833d46d8841e8a90127.zip |
Merge pull request #220 from tomaka/x11-vsync
Implement vsync for x11 and add vsync example
Diffstat (limited to 'src/x11/window/mod.rs')
-rw-r--r-- | src/x11/window/mod.rs | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs index 91419e2..efdc759 100644 --- a/src/x11/window/mod.rs +++ b/src/x11/window/mod.rs @@ -303,7 +303,7 @@ impl Window { // creating GL context - let context = unsafe { + let (context, extra_functions) = unsafe { let mut attributes = Vec::new(); if builder.gl_version.is_some() { @@ -350,9 +350,52 @@ impl Window { return Err(OsError(format!("GL context creation failed"))); } - context + (context, extra_functions) }; + // vsync + if builder.vsync { + unsafe { ffi::glx::MakeCurrent(display, window, context) }; + + if extra_functions.SwapIntervalEXT.is_loaded() { + // this should be the most common extension + unsafe { + extra_functions.SwapIntervalEXT(display as *mut _, window, 1); + } + + // checking that it worked + if builder.strict { + let mut swap = unsafe { mem::uninitialized() }; + unsafe { + ffi::glx::QueryDrawable(display, window, + ffi::glx_extra::SWAP_INTERVAL_EXT as i32, + &mut swap); + } + + if swap != 1 { + return Err(OsError(format!("Couldn't setup vsync: expected \ + interval `1` but got `{}`", swap))); + } + } + + // GLX_MESA_swap_control is not official + /*} else if extra_functions.SwapIntervalMESA.is_loaded() { + unsafe { + extra_functions.SwapIntervalMESA(1); + }*/ + + } else if extra_functions.SwapIntervalSGI.is_loaded() { + unsafe { + extra_functions.SwapIntervalSGI(1); + } + + } else if builder.strict { + return Err(OsError(format!("Couldn't find any available vsync extension"))); + } + + unsafe { ffi::glx::MakeCurrent(display, 0, ptr::null()) }; + } + // creating the window object let window = Window { x: Arc::new(XWindow { |