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
/*! Rust FFI to [Sokol] headers for [Rokol] ([API](https://docs.rs/rokol/latest/rokol/)) Last update: Dec 3, 2020 ([commit]). Sokol header declaration diffs can be seen on [GitHub][Rokol]. [Sokol]: https://github.com/floooh/sokol [Rokol]: https://github.com/toyboot4e/rokol [commit]: https://github.com/floooh/sokol/commit/5fbb6a25501e5478674ca0600a7539033592d749 # impl Default Generated with [`bindgen`], implementing [`Default`] trait ([`Bindgen::derive_default(true)`][derive]). NOTE: Sokol [considers] zero-initizialized structures to be in default state. It means [`Default::default`] is ensured to make sense! [`bindgen`]: https://docs.rs/bindgen/latest/bindgen [derive]: https://docs.rs/bindgen/0.56.0/bindgen/struct.Builder.html#method.derive_default [considers]: https://floooh.github.io/2017/08/06/sokol-api-update.html */ // TODO: Do not use `include!` so that we get goto support in Emacs // https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.module_raw_lines #[cfg(feature = "impl-app")] pub mod app; #[cfg(feature = "impl-gfx")] pub mod gfx; #[cfg(all(feature = "impl-app", feature = "impl-gfx"))] pub mod glue { //! FFI to [`sokol_glue.h`](https://github.com/floooh/sokol/blob/master/sokol_glue.h) // there's only one function so let's write it manually extern "C" { pub fn sapp_sgcontext() -> crate::gfx::sg_context_desc; } } // #[cfg(test)] // mod test { // /// Just to make sure we link to `sokol` // fn link_test() { // unsafe { // let mut desc: crate::gfx::sg_desc = Default::default(); // desc.context = crate::glue::sapp_sgcontext(); // crate::gfx::sg_setup(&desc); // } // } // } #[cfg(feature = "impl-gfx")] mod gfx_impls { use super::*; use gfx::sg_color; impl From<[f32; 4]> for sg_color { fn from(xs: [f32; 4]) -> sg_color { sg_color { r: xs[0], g: xs[1], b: xs[2], a: xs[3], } } } impl From<[&f32; 4]> for sg_color { fn from(xs: [&f32; 4]) -> sg_color { sg_color { r: *xs[0], g: *xs[1], b: *xs[2], a: *xs[3], } } } impl From<&[u8]> for gfx::sg_range { // WARNING: This is VERY UNSAFE since the slice may be a temporary value fn from(x: &[u8]) -> gfx::sg_range { gfx::sg_range { ptr: x.as_ptr() as *const _, size: x.len() as _, } } } }