From ee1b7fd3bc66501b252ce9e3e5ba89ac9aa54632 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sat, 10 Aug 2024 23:18:22 +1000 Subject: more work on bindings and ral --- bindgen/rust/celeritas-sys/Cargo.lock | 29 +++++++++++++++++++++++++++++ bindgen/rust/celeritas-sys/build.rs | 27 ++++++++++++++++++++------- bindgen/rust/celeritas-sys/src/lib.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 7 deletions(-) (limited to 'bindgen/rust/celeritas-sys') diff --git a/bindgen/rust/celeritas-sys/Cargo.lock b/bindgen/rust/celeritas-sys/Cargo.lock index 89c7407..43ae7fb 100644 --- a/bindgen/rust/celeritas-sys/Cargo.lock +++ b/bindgen/rust/celeritas-sys/Cargo.lock @@ -39,6 +39,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + [[package]] name = "autocfg" version = "1.3.0" @@ -100,6 +109,7 @@ dependencies = [ "egui", "egui_glfw", "gl", + "glam", "serde", "serde_json", ] @@ -309,6 +319,16 @@ dependencies = [ "xml-rs", ] +[[package]] +name = "glam" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "779ae4bf7e8421cf91c0b3b64e7e8b40b862fba4d393f59150042de7c4965a94" +dependencies = [ + "approx", + "serde", +] + [[package]] name = "glfw" version = "0.55.0" @@ -492,6 +512,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "objc" version = "0.2.7" diff --git a/bindgen/rust/celeritas-sys/build.rs b/bindgen/rust/celeritas-sys/build.rs index 9e97034..b356bb0 100644 --- a/bindgen/rust/celeritas-sys/build.rs +++ b/bindgen/rust/celeritas-sys/build.rs @@ -13,16 +13,26 @@ const SERIALIZABLE_TYPES: &[&'static str] = &[ "DirectionalLight", "PointLight", ]; +const EQ_TYPES: &[&'static str] = &[ + "BufferHandle", + "TextureHandle", + "MeshHandle", + "MaterialHandle", + "ModelHandle", +]; #[derive(Debug)] -struct DeriveSerialize; -impl ParseCallbacks for DeriveSerialize { +struct AdditionalDerives; +impl ParseCallbacks for AdditionalDerives { fn add_derives(&self, info: &bindgen::callbacks::DeriveInfo<'_>) -> Vec { + let mut derives = vec![]; if SERIALIZABLE_TYPES.contains(&info.name) { - vec!["Serialize".to_string(), "Deserialize".to_string()] - } else { - vec![] + derives.extend_from_slice(&["Serialize".to_string(), "Deserialize".to_string()]); + } + if EQ_TYPES.contains(&info.name) { + derives.extend_from_slice(&["PartialEq".to_string()]); } + derives } } @@ -34,7 +44,8 @@ fn main() { // println!("cargo:rustc-link-search=../../build/windows/x64/debug"); let static_lib_path = - "/Users/josh/code/CodenameVentus/deps/celeritas-core/build/macosx/arm64/debug".to_string(); + "/Users/josh/code/CodenameVentus/deps/celeritas-core/build/macosx/arm64/release" + .to_string(); // let static_lib_path = std::env::var("CELERITAS_CORE_LIB") // .unwrap_or("../../../build/macosx/arm64/debug".to_string()); @@ -75,8 +86,10 @@ fn main() { .generate_inline_functions(true) // Tell cargo to invalidate the built crate whenever any of the // included header files changed. + .rustified_enum("GPU_TextureType") + .rustified_enum("GPU_TextureFormat") .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) - .parse_callbacks(Box::new(DeriveSerialize)) + .parse_callbacks(Box::new(AdditionalDerives)) // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure. diff --git a/bindgen/rust/celeritas-sys/src/lib.rs b/bindgen/rust/celeritas-sys/src/lib.rs index 780ceff..90a5914 100644 --- a/bindgen/rust/celeritas-sys/src/lib.rs +++ b/bindgen/rust/celeritas-sys/src/lib.rs @@ -87,6 +87,19 @@ impl Transform { } } +impl Vec3 { + pub const ZERO: Self = Vec3 { + x: 0., + y: 0., + z: 0., + }; + pub const ONE: Self = Vec3 { + x: 1., + y: 1., + z: 1., + }; +} + impl Default for ShaderBinding { fn default() -> Self { Self { @@ -139,3 +152,16 @@ impl Default for Camera { camera } } + +// -- fat pointer string type + +impl Str8 { + pub fn from_str(s: &str) -> Self { + let s = s.to_owned(); + let s = s.leak(); // TODO: a better way than just leaking string memory :P + Self { + buf: s.as_mut_ptr(), + len: 0, + } + } +} -- cgit v1.2.3-70-g09d2