1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use crate::{bind, Result, SdlError};
use super::GlContext;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum IntervalKind {
AdaptiveVerticalSync,
Immediate,
VerticalSync,
}
pub trait BufferExt {
fn set_swap_interval(&self, interval_kind: IntervalKind) -> Result<()>;
fn swap_buffer(&self);
}
impl BufferExt for GlContext<'_> {
fn set_swap_interval(&self, interval_kind: IntervalKind) -> Result<()> {
let ret = unsafe {
bind::SDL_GL_SetSwapInterval(match interval_kind {
IntervalKind::AdaptiveVerticalSync => -1,
IntervalKind::Immediate => 0,
IntervalKind::VerticalSync => 1,
})
};
if ret != 0 {
return Err(SdlError::UnsupportedFeature);
}
Ok(())
}
fn swap_buffer(&self) {
unsafe { bind::SDL_GL_SwapWindow(self.window.as_ptr()) }
}
}