diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-08-10 02:59:59 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-08-10 02:59:59 +1000 |
commit | dcb9f65b25e59edb21c9c3cac7b32d70ca19eb72 (patch) | |
tree | ce99b01a070c57ecc6f3f4073b8298608706f9a0 /bindgen | |
parent | a0592bdb9966b204373bc4a258da47a603c70969 (diff) |
wip
Diffstat (limited to 'bindgen')
-rw-r--r-- | bindgen/rust/Cargo.lock | 30 | ||||
-rw-r--r-- | bindgen/rust/Cargo.toml | 1 | ||||
-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 | ||||
-rw-r--r-- | bindgen/rust/src/lib.rs | 39 | ||||
-rw-r--r-- | bindgen/rust/src/prelude.rs | 3 | ||||
-rw-r--r-- | bindgen/rust/src/ral.rs | 15 | ||||
-rw-r--r-- | bindgen/rust/src/resources.rs | 10 |
9 files changed, 193 insertions, 14 deletions
diff --git a/bindgen/rust/Cargo.lock b/bindgen/rust/Cargo.lock index 3d17b7a..06717c7 100644 --- a/bindgen/rust/Cargo.lock +++ b/bindgen/rust/Cargo.lock @@ -40,6 +40,15 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -107,6 +116,7 @@ dependencies = [ "egui", "egui_glfw", "gl", + "glam", "heapless", "serde", "serde_json", @@ -118,6 +128,7 @@ name = "celeritas-sys" version = "0.1.0" dependencies = [ "bindgen", + "glam", "serde", ] @@ -327,6 +338,16 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -529,6 +550,15 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/bindgen/rust/Cargo.toml b/bindgen/rust/Cargo.toml index 001a815..5841fac 100644 --- a/bindgen/rust/Cargo.toml +++ b/bindgen/rust/Cargo.toml @@ -11,6 +11,7 @@ serde_json = "1.0.120" egui = "0.27.1" egui_glfw = { git = "https://github.com/omnisci3nce/egui_glfw.git", rev = "67b432695433feb59761f3ae984b966ca3da31db" } gl = "0.14.0" +glam = { version = "0.28.0", features = ["approx", "serde"] } thiserror = "1.0.63" bitflags = "2.6.0" heapless = "0.8.0" 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 +} diff --git a/bindgen/rust/src/lib.rs b/bindgen/rust/src/lib.rs index e2a1ff3..a20a9e8 100644 --- a/bindgen/rust/src/lib.rs +++ b/bindgen/rust/src/lib.rs @@ -9,15 +9,19 @@ pub use celeritas_sys as ffi; pub mod prelude; pub mod ral; +pub mod resources; pub mod shader; use std::{ + ffi::CString, fs::{self, File}, io::Write, path::Path, }; -use celeritas_sys::{DirectionalLight, PointLight, Transform, Vec3}; +use celeritas_sys::{ + Core_Bringup, Core_Shutdown, DirectionalLight, PointLight, RenderEnt, Transform, Vec3, +}; use serde::{Deserialize, Serialize}; /// Wrapper around a string that is the path to a gltf model **relative** to the configured @@ -65,3 +69,36 @@ pub enum Light { Directional(ffi::DirectionalLight), // Spot(ffi::Spotlight) } + +pub struct Core { + _window_name: CString, +} +impl Core { + pub fn init(window_name: &str, window: Option<*mut ffi::GLFWwindow>) -> Self { + let name = CString::new(window_name).unwrap(); + let window_ptr = window.unwrap_or(std::ptr::null_mut()); + unsafe { Core_Bringup(name.as_ptr() as *const _, window_ptr) }; + Self { _window_name: name } + } +} + +impl Drop for Core { + fn drop(&mut self) { + unsafe { Core_Shutdown() } + } +} + +// pub struct Renderable { +// pub mesh: MeshHandle, +// pub material: MaterialHandle, +// pub affine: Mat4, +// pub bounding_box: Bbox_3D, +// pub flags: RenderEntityFlags, +// } + +bitflags::bitflags! { + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + pub struct RenderableFlags : u32 { + + } +} diff --git a/bindgen/rust/src/prelude.rs b/bindgen/rust/src/prelude.rs index b78f364..37ad68b 100644 --- a/bindgen/rust/src/prelude.rs +++ b/bindgen/rust/src/prelude.rs @@ -13,3 +13,6 @@ pub use celeritas_sys::PipelineHandle; pub use celeritas_sys::PipelineLayoutHandle; pub use celeritas_sys::RenderpassHandle; pub use celeritas_sys::TextureHandle; + +// --- conversions +pub use celeritas_sys::conversions; diff --git a/bindgen/rust/src/ral.rs b/bindgen/rust/src/ral.rs index 4943f9e..078121b 100644 --- a/bindgen/rust/src/ral.rs +++ b/bindgen/rust/src/ral.rs @@ -5,10 +5,11 @@ use std::ffi::c_void; use celeritas_sys::{ BufferHandle, GPU_CmdEncoder, GPU_CmdEncoder_BeginRender, GPU_CmdEncoder_EndRender, GPU_EncodeBindShaderData, GPU_GetDefaultEncoder, GPU_GetDefaultRenderpass, - GPU_GraphicsPipeline_Create, GraphicsPipelineDesc, ShaderBindingKind_BINDING_BYTES, - ShaderBinding__bindgen_ty_1, ShaderBinding__bindgen_ty_1__bindgen_ty_1, - ShaderVisibility_VISIBILITY_COMPUTE, ShaderVisibility_VISIBILITY_FRAGMENT, - ShaderVisibility_VISIBILITY_VERTEX, TextureHandle, MAX_SHADER_DATA_LAYOUTS, + GPU_GraphicsPipeline_Create, GPU_Pipeline, GraphicsPipelineDesc, + ShaderBindingKind_BINDING_BYTES, ShaderBinding__bindgen_ty_1, + ShaderBinding__bindgen_ty_1__bindgen_ty_1, ShaderVisibility_VISIBILITY_COMPUTE, + ShaderVisibility_VISIBILITY_FRAGMENT, ShaderVisibility_VISIBILITY_VERTEX, TextureHandle, + MAX_SHADER_DATA_LAYOUTS, }; use thiserror::Error; @@ -106,6 +107,12 @@ impl PipelineBuilder { } } +impl Pipeline { + pub fn raw_ptr(&self) -> *mut GPU_Pipeline { + self.0 + } +} + /// pub trait ShaderData { /// diff --git a/bindgen/rust/src/resources.rs b/bindgen/rust/src/resources.rs new file mode 100644 index 0000000..89cf6d7 --- /dev/null +++ b/bindgen/rust/src/resources.rs @@ -0,0 +1,10 @@ +use std::{ffi::CString, path::Path}; + +use celeritas_sys::{ModelHandle, ModelLoad, ModelLoad_gltf}; + +/// Load a gltf from disk +pub fn model_load_gltf(path: &str) -> Option<ModelHandle> { + let path_str = CString::new(path).unwrap(); + let handle = unsafe { ModelLoad_gltf(path_str.as_ptr() as *const _, false) }; + Some(handle) +} |