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