diff options
Diffstat (limited to 'bindgen/rust/celeritas-sys')
-rw-r--r-- | bindgen/rust/celeritas-sys/Cargo.toml | 3 | ||||
-rw-r--r-- | bindgen/rust/celeritas-sys/build.rs | 5 | ||||
-rw-r--r-- | bindgen/rust/celeritas-sys/src/lib.rs | 101 |
3 files changed, 100 insertions, 9 deletions
diff --git a/bindgen/rust/celeritas-sys/Cargo.toml b/bindgen/rust/celeritas-sys/Cargo.toml index 0b52e3c..51837a1 100644 --- a/bindgen/rust/celeritas-sys/Cargo.toml +++ b/bindgen/rust/celeritas-sys/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +glam = { version = "0.28.0", features = ["approx", "serde"] } serde = { version = "1.0.204", features = ["derive"] } [build-dependencies] @@ -13,4 +14,4 @@ bindgen = "0.69.4" egui = "0.27.1" egui_glfw = { git = "https://github.com/omnisci3nce/egui_glfw.git", rev = "67b432695433feb59761f3ae984b966ca3da31db" } gl = "0.14.0" -serde_json = "1.0.120"
\ No newline at end of file +serde_json = "1.0.120" diff --git a/bindgen/rust/celeritas-sys/build.rs b/bindgen/rust/celeritas-sys/build.rs index 38009bd..924a98c 100644 --- a/bindgen/rust/celeritas-sys/build.rs +++ b/bindgen/rust/celeritas-sys/build.rs @@ -32,8 +32,9 @@ fn main() { // Tell cargo to look for shared libraries in the specified directory // TODO: we need to look based on OS // 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(); + + let static_lib_path = + "/Users/josh/code/CodenameVentus/deps/celeritas-core/build/macosx/arm64/debug".to_string(); // let static_lib_path = std::env::var("CELERITAS_CORE_LIB") // .unwrap_or("../../../build/macosx/arm64/debug".to_string()); diff --git a/bindgen/rust/celeritas-sys/src/lib.rs b/bindgen/rust/celeritas-sys/src/lib.rs index c5939fd..e6f62ad 100644 --- a/bindgen/rust/celeritas-sys/src/lib.rs +++ b/bindgen/rust/celeritas-sys/src/lib.rs @@ -2,23 +2,112 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] +use std::ffi::c_void; + use serde::{Deserialize, Serialize}; include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +// --- Conversions +pub mod conversions { + use crate::{Mat4, Vec3, Vec4}; + + impl From<Vec3> for glam::Vec3 { + fn from(v: Vec3) -> Self { + Self { + x: v.x, + y: v.y, + z: v.z, + } + } + } + impl From<glam::Vec3> for Vec3 { + fn from(v: glam::Vec3) -> Self { + Self { + x: v.x, + y: v.y, + z: v.z, + } + } + } + + impl From<Vec4> for glam::Vec4 { + fn from(v: Vec4) -> Self { + Self::new(v.x, v.y, v.z, v.w) + } + } + impl From<glam::Vec4> for Vec4 { + fn from(v: glam::Vec4) -> Self { + Vec4 { + x: v.x, + y: v.y, + z: v.z, + w: v.w, + } + } + } + + impl From<Mat4> for glam::Mat4 { + fn from(m: Mat4) -> Self { + Self { + x_axis: glam::Vec4::new(m.data[0], m.data[1], m.data[2], m.data[3]), + y_axis: glam::Vec4::new(m.data[4], m.data[5], m.data[6], m.data[7]), + z_axis: glam::Vec4::new(m.data[8], m.data[9], m.data[10], m.data[11]), + w_axis: glam::Vec4::new(m.data[12], m.data[13], m.data[14], m.data[15]), + } + } + } + impl From<glam::Mat4> for Mat4 { + fn from(m: glam::Mat4) -> Self { + let mut slf = Self { data: [0.0; 16] }; + m.write_cols_to_slice(&mut slf.data); + slf + } + } +} + +impl Transform { + #[inline] + pub fn identity() -> Self { + Self { + position: Vec3 { + x: 0., + y: 0., + z: 0., + }, + rotation: Vec4 { + x: 0., + y: 0., + z: 0., + w: 1.0, + }, + scale: 1., + is_dirty: true, + } + } +} impl Default for ShaderBinding { fn default() -> Self { - Self { label: todo!(), - kind: ShaderBindingKind_BINDING_COUNT, - vis: ShaderVisibility_VISIBILITY_VERTEX, - data: todo!() + Self { + label: "static".as_ptr() as *const _, + kind: ShaderBindingKind_BINDING_COUNT, + vis: ShaderVisibility_VISIBILITY_VERTEX, + data: ShaderBinding__bindgen_ty_1 { + bytes: ShaderBinding__bindgen_ty_1__bindgen_ty_1 { + size: 0, + data: std::ptr::null_mut(), + }, + }, } } } impl Default for ShaderDataLayout { fn default() -> Self { - Self { bindings: [ShaderBinding::default(); 8], binding_count: 0 } + Self { + bindings: [ShaderBinding::default(); 8], + binding_count: 0, + } } -}
\ No newline at end of file +} |