-
-
Notifications
You must be signed in to change notification settings - Fork 477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed type of vsync from bool to Option<bool> #1230
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1086,19 +1086,21 @@ impl<'a> ContextPrototype<'a> { | |
|
||
if let Some(surface) = surface { | ||
// VSync defaults to enabled; disable it if it was not requested. | ||
if !self.opengl.vsync { | ||
let _guard = MakeCurrentGuard::new( | ||
self.display, | ||
surface, | ||
surface, | ||
context, | ||
) | ||
.map_err(|err| CreationError::OsError(err))?; | ||
|
||
let egl = EGL.as_ref().unwrap(); | ||
unsafe { | ||
if egl.SwapInterval(self.display, 0) == ffi::egl::FALSE { | ||
panic!("finish_impl: eglSwapInterval failed: 0x{:x}", egl.GetError()); | ||
if let Some(vsync) = self.opengl.vsync { | ||
if !vsync { | ||
let _guard = MakeCurrentGuard::new( | ||
self.display, | ||
surface, | ||
surface, | ||
context, | ||
) | ||
.map_err(|err| CreationError::OsError(err))?; | ||
|
||
let egl = EGL.as_ref().unwrap(); | ||
unsafe { | ||
if egl.SwapInterval(self.display, 0) == ffi::egl::FALSE { | ||
panic!("finish_impl: eglSwapInterval failed: 0x{:x}", egl.GetError()); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -1294,8 +1296,12 @@ where | |
} | ||
|
||
// We're interested in those configs which allow our desired VSync. | ||
let desired_swap_interval = if opengl.vsync { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code as it exists contradicts the prior code. The prior code does not disable vsync when If we don't care about |
||
1 | ||
let desired_swap_interval = if let Some(vsync) = opengl.vsync { | ||
if vsync { | ||
1 | ||
} else { | ||
0 | ||
} | ||
} else { | ||
0 | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -413,51 +413,53 @@ impl<'a> ContextPrototype<'a> { | |
let (extra_functions, context) = self.create_context()?; | ||
|
||
// vsync | ||
if self.opengl.vsync { | ||
let _guard = MakeCurrentGuard::new(&self.xconn, window, context) | ||
.map_err(|err| CreationError::OsError(err))?; | ||
|
||
if check_ext(&self.extensions, "GLX_EXT_swap_control") | ||
&& extra_functions.SwapIntervalEXT.is_loaded() | ||
{ | ||
// this should be the most common extension | ||
unsafe { | ||
extra_functions.SwapIntervalEXT( | ||
self.xconn.display as *mut _, | ||
window, | ||
1, | ||
); | ||
} | ||
if let Some(vsync) = self.opengl.vsync { | ||
if vsync { | ||
let _guard = MakeCurrentGuard::new(&self.xconn, window, context) | ||
.map_err(|err| CreationError::OsError(err))?; | ||
|
||
if check_ext(&self.extensions, "GLX_EXT_swap_control") | ||
&& extra_functions.SwapIntervalEXT.is_loaded() | ||
{ | ||
// this should be the most common extension | ||
unsafe { | ||
extra_functions.SwapIntervalEXT( | ||
self.xconn.display as *mut _, | ||
window, | ||
1, | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: formating? |
||
} | ||
|
||
let mut swap = unsafe { std::mem::zeroed() }; | ||
unsafe { | ||
glx.QueryDrawable( | ||
self.xconn.display as *mut _, | ||
window, | ||
ffi::glx_extra::SWAP_INTERVAL_EXT as i32, | ||
&mut swap, | ||
); | ||
} | ||
let mut swap = unsafe { std::mem::zeroed() }; | ||
unsafe { | ||
glx.QueryDrawable( | ||
self.xconn.display as *mut _, | ||
window, | ||
ffi::glx_extra::SWAP_INTERVAL_EXT as i32, | ||
&mut swap, | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: formating? |
||
} | ||
|
||
if swap != 1 { | ||
return Err(CreationError::OsError(format!("Couldn't setup vsync: expected interval `1` but got `{}`", swap))); | ||
} | ||
} else if check_ext(&self.extensions, "GLX_MESA_swap_control") | ||
&& extra_functions.SwapIntervalMESA.is_loaded() | ||
{ | ||
unsafe { | ||
extra_functions.SwapIntervalMESA(1); | ||
} | ||
} else if check_ext(&self.extensions, "GLX_SGI_swap_control") | ||
&& extra_functions.SwapIntervalSGI.is_loaded() | ||
{ | ||
unsafe { | ||
extra_functions.SwapIntervalSGI(1); | ||
} | ||
} else { | ||
return Err(CreationError::OsError( | ||
"Couldn't find any available vsync extension".to_string(), | ||
)); | ||
if swap != 1 { | ||
return Err(CreationError::OsError(format!("Couldn't setup vsync: expected interval `1` but got `{}`", swap))); | ||
} | ||
} else if check_ext(&self.extensions, "GLX_MESA_swap_control") | ||
&& extra_functions.SwapIntervalMESA.is_loaded() | ||
{ | ||
unsafe { | ||
extra_functions.SwapIntervalMESA(1); | ||
} | ||
} else if check_ext(&self.extensions, "GLX_SGI_swap_control") | ||
&& extra_functions.SwapIntervalSGI.is_loaded() | ||
{ | ||
unsafe { | ||
extra_functions.SwapIntervalSGI(1); | ||
} | ||
} else { | ||
return Err(CreationError::OsError( | ||
"Couldn't find any available vsync extension".to_string(), | ||
)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: formating? |
||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,7 +181,7 @@ impl<'a, T: ContextCurrentState> ContextBuilder<'a, T> { | |
/// | ||
/// By default, vsync is not enabled. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs should be updated to say that |
||
#[inline] | ||
pub fn with_vsync(mut self, vsync: bool) -> Self { | ||
pub fn with_vsync(mut self, vsync: Option<bool>) -> Self { | ||
self.gl_attr.vsync = vsync; | ||
self | ||
} | ||
|
@@ -705,7 +705,7 @@ pub struct GlAttributes<S> { | |
/// screen tearing. | ||
/// | ||
/// The default is `false`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs should be updated to say that |
||
pub vsync: bool, | ||
pub vsync: Option<bool>, | ||
} | ||
|
||
impl<S> GlAttributes<S> { | ||
|
@@ -748,7 +748,7 @@ impl<S> Default for GlAttributes<S> { | |
profile: None, | ||
debug: cfg!(debug_assertions), | ||
robustness: Robustness::NotRobust, | ||
vsync: false, | ||
vsync: Some(false), | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EGL by default has VSync enabled, and you have to explicitly disable it. Hope that makes sense.