summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: fc0400ef7c9d7c090fff5447a79692d04595bc13 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! OpenGL bindings.
#![deny(clippy::all, clippy::pedantic, missing_docs)]

pub use ffi::*;

include!(concat!(env!("OUT_DIR"), "/generated.rs"));

mod ffi
{
    #![allow(
        non_upper_case_globals,
        non_camel_case_types,
        non_snake_case,
        unused,
        missing_docs,
        clippy::unreadable_literal
    )]

    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}

#[cfg(test)]
mod tests
{
    use std::mem::transmute;
    use std::sync::atomic::{AtomicBool, Ordering};

    use super::*;

    #[test]
    fn can_set_and_use_command_function()
    {
        static HAS_CALLED_FUNC: AtomicBool = AtomicBool::new(false);

        extern "C" fn func(x: GLint, y: GLint, width: GLsizei, height: GLsizei)
        {
            assert_eq!(x, 123);
            assert_eq!(y, 9);
            assert_eq!(width, 1920);
            assert_eq!(height, 1080);

            HAS_CALLED_FUNC.store(true, Ordering::Relaxed);
        }

        unsafe {
            functions::glViewport = transmute(func as *const ());
        }

        unsafe {
            Viewport(123, 9, 1920, 1080);
        }

        assert!(HAS_CALLED_FUNC.load(Ordering::Relaxed));
    }

    #[test]
    #[should_panic]
    fn no_set_command_function_ptr_panics()
    {
        unsafe {
            AttachShader(2, 30);
        }
    }
}