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
use gl_context::GLContextDispatcher;

pub trait NativeGLContextMethods: Sized {
    type Handle;

    fn get_proc_address(&str) -> *const ();

    // These are convenient methods to manage handles
    fn current() -> Option<Self>;
    fn current_handle() -> Option<Self::Handle>;

    fn create_shared(with: Option<&Self::Handle>) -> Result<Self, &'static str>;

    fn create_shared_with_dispatcher(with: Option<&Self::Handle>, _dispatcher: Option<Box<GLContextDispatcher>>)
        -> Result<Self, &'static str> {
        Self::create_shared(with)
    }

    fn create_headless() -> Result<Self, &'static str> {
        Self::create_shared(None)
    }

    fn handle(&self) -> Self::Handle;
    fn is_current(&self) -> bool;
    fn make_current(&self) -> Result<(), &'static str>;
    fn unbind(&self) -> Result<(), &'static str>;

    /// Just a somewhat dirty hack to special-case the handling of context
    /// unbinding on old OSMesa versions.
    fn is_osmesa(&self) -> bool { false }
}

#[cfg(all(target_os="linux", feature="x11"))]
pub mod with_glx;
#[cfg(all(target_os="linux", feature="x11"))]
pub use self::with_glx::{NativeGLContext, NativeGLContextHandle};

#[cfg(feature="osmesa")]
pub mod with_osmesa;
#[cfg(feature="osmesa")]
pub use self::with_osmesa::{OSMesaContext, OSMesaContextHandle};
#[cfg(all(target_os="linux", not(feature="x11")))]
pub use self::with_osmesa::{OSMesaContext as NativeGLContext, OSMesaContextHandle as NativeGLContextHandle};


#[cfg(any(target_os="android", all(target_os="linux", feature = "test_egl_in_linux")))]
pub mod with_egl;
#[cfg(target_os="android")]
pub use self::with_egl::{NativeGLContext, NativeGLContextHandle};

#[cfg(target_os="macos")]
pub mod with_cgl;
#[cfg(target_os="macos")]
pub use self::with_cgl::{NativeGLContext, NativeGLContextHandle};

#[cfg(target_os="windows")]
pub mod with_wgl;
#[cfg(target_os="windows")]
pub use self::with_wgl::{NativeGLContext, NativeGLContextHandle};

#[cfg(not(any(target_os="linux", target_os="android", target_os="macos", target_os="windows")))]
pub mod not_implemented;
#[cfg(not(any(target_os="linux", target_os="android", target_os="macos", target_os="windows")))]
pub use self::not_implemented::{NativeGLContext, NativeGLContextHandle};