| 1 | //! The purpose of this library is to provide an OpenGL [`context`] for as many |
| 2 | //! platforms as possible, abstracting away the underlying differences without |
| 3 | //! losing access to platform specific extensions. |
| 4 | //! |
| 5 | //! However Glutin doesn't force users into using the cross platform |
| 6 | //! abstractions. When only a particular [`api`] is desired, it can |
| 7 | //! be used directly. |
| 8 | //! |
| 9 | //! The initialization starts by loading and connecting to the platform's |
| 10 | //! graphics Api when creating a [`display`]. This object is used to create all |
| 11 | //! the OpenGL objects, such as [`config`], [`context`], and [`surface`]. |
| 12 | //! |
| 13 | //! ## Environment variables |
| 14 | //! |
| 15 | //! `GLUTIN_WGL_OPENGL_DLL` - change the name of the OpenGL DLL to load. |
| 16 | |
| 17 | #![deny (rust_2018_idioms)] |
| 18 | #![deny (rustdoc::broken_intra_doc_links)] |
| 19 | #![deny (unsafe_op_in_unsafe_fn)] |
| 20 | #![deny (improper_ctypes, improper_ctypes_definitions)] |
| 21 | #![deny (clippy::all)] |
| 22 | #![deny (missing_debug_implementations)] |
| 23 | #![deny (missing_docs)] |
| 24 | #![cfg_attr (clippy, deny(warnings))] |
| 25 | #![cfg_attr (docsrs, feature(doc_auto_cfg))] |
| 26 | |
| 27 | #[cfg (all(not(egl_backend), not(glx_backend), not(wgl_backend), not(cgl_backend)))] |
| 28 | compile_error!("Please select at least one api backend" ); |
| 29 | |
| 30 | pub mod api; |
| 31 | pub mod config; |
| 32 | pub mod context; |
| 33 | pub mod display; |
| 34 | pub mod error; |
| 35 | pub mod platform; |
| 36 | pub mod prelude; |
| 37 | pub mod surface; |
| 38 | |
| 39 | #[cfg (any(egl_backend, glx_backend))] |
| 40 | mod lib_loading; |
| 41 | |
| 42 | pub(crate) mod private { |
| 43 | /// Prevent traits from being implemented downstream, since those are used |
| 44 | /// purely for documentation organization and simplify platform api |
| 45 | /// implementation maintenance. |
| 46 | pub trait Sealed {} |
| 47 | |
| 48 | /// `gl_api_dispatch!(match expr; Enum(foo) => foo.something())` |
| 49 | /// expands to the equivalent of |
| 50 | /// ```ignore |
| 51 | /// match self { |
| 52 | /// Enum::Egl(foo) => foo.something(), |
| 53 | /// Enum::Glx(foo) => foo.something(), |
| 54 | /// Enum::Wgl(foo) => foo.something(), |
| 55 | /// Enum::Cgl(foo) => foo.something(), |
| 56 | /// } |
| 57 | /// ``` |
| 58 | /// The result can be converted to another enum by adding `; as AnotherEnum` |
| 59 | macro_rules! gl_api_dispatch { |
| 60 | ($what:ident; $enum:ident ( $($c1:tt)* ) => $x:expr; as $enum2:ident ) => { |
| 61 | match $what { |
| 62 | #[cfg(egl_backend)] |
| 63 | $enum::Egl($($c1)*) => $enum2::Egl($x), |
| 64 | #[cfg(glx_backend)] |
| 65 | $enum::Glx($($c1)*) => $enum2::Glx($x), |
| 66 | #[cfg(wgl_backend)] |
| 67 | $enum::Wgl($($c1)*) => $enum2::Wgl($x), |
| 68 | #[cfg(cgl_backend)] |
| 69 | $enum::Cgl($($c1)*) => $enum2::Cgl($x), |
| 70 | } |
| 71 | }; |
| 72 | ($what:ident; $enum:ident ( $($c1:tt)* ) => $x:expr) => { |
| 73 | match $what { |
| 74 | #[cfg(egl_backend)] |
| 75 | $enum::Egl($($c1)*) => $x, |
| 76 | #[cfg(glx_backend)] |
| 77 | $enum::Glx($($c1)*) => $x, |
| 78 | #[cfg(wgl_backend)] |
| 79 | $enum::Wgl($($c1)*) => $x, |
| 80 | #[cfg(cgl_backend)] |
| 81 | $enum::Cgl($($c1)*) => $x, |
| 82 | } |
| 83 | }; |
| 84 | } |
| 85 | |
| 86 | pub(crate) use gl_api_dispatch; |
| 87 | } |
| 88 | |