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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
/*!
Wrapper of [Sokol] libraries
[Sokol]: https://github.com/floooh/sokol
# Features (specified in `Cargo.toml`)
Example settings:
```toml
rokol = { features = ["sdl", "impl-gfx", "glcore33", "fontstash"] }
```
* `impl-app`: implements `sokol_app.h` and enables `app` module
* `sdl2`: generates [`glue`] code for `sdl2`
* `impl-gfx`: implements `sokol_gfx.h` and enables `gfx` module
* `glcore33`: uses OpenGL backend
* `metal`: uses Metal backend
* `d3d11`: uses DirectX11 backend
* `fontstash`: implements `fontstash.h` and enables `fons` module
# Tips
* Checkout [The Brain Dump]
* Sokol [considers] zero-initizialized structures to be in default state. It means
[`Default::default`] is ensured to make sense!
* use `bytemuck` to cast types to `&[u8]`.
[The Brain Dump]: https://floooh.github.io/
[considers]: https://floooh.github.io/2017/08/06/sokol-api-update.html
*/
pub use rokol_ffi as ffi;
/// Creates an `enum` from FFI enum type (output of bindgen as a rustified enum)
macro_rules! ffi_enum {
(
$(#[$outer:meta])*
$vis:vis enum $Enum:ident around $Ffi:ty {
$(
$(#[$attr:ident $($args:tt)*])*
$variant:ident = $ffi_variant:ident,
)*
}
$($t:tt)*
) => {
$(#[$outer])*
#[repr(u32)]
$vis enum $Enum {
$(
$(#[$attr $($args)*])*
$variant = <$Ffi>::$ffi_variant as u32,
)*
}
impl $Enum {
pub fn from_ffi(ffi_variant: $Ffi) -> Self {
match ffi_variant {
$(
<$Ffi>::$ffi_variant => Self::$variant,
)*
_ => panic!("Bug: not convered FFI enum!"),
}
}
pub fn to_ffi(self) -> $Ffi {
match self {
$(
<Self>::$variant => <$Ffi>::$ffi_variant,
)*
}
}
}
impl From<$Ffi> for $Enum {
fn from(ffi_variant: $Ffi) -> Self {
Self::from_ffi(ffi_variant)
}
}
impl Into<$Ffi> for $Enum {
fn into(self) -> $Ffi {
Self::to_ffi(self)
}
}
};
}
#[cfg(feature = "impl-app")]
pub mod app;
#[cfg(feature = "impl-gfx")]
pub mod gfx;
#[cfg(feature = "impl-gfx")]
pub mod glue;
#[cfg(all(feature = "impl-gfx", feature = "fontstash"))]
pub mod fons;