From dcb9f65b25e59edb21c9c3cac7b32d70ca19eb72 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sat, 10 Aug 2024 02:59:59 +1000 Subject: wip --- bindgen/rust/src/lib.rs | 39 ++++++++++++++++++++++++++++++++++++++- bindgen/rust/src/prelude.rs | 3 +++ bindgen/rust/src/ral.rs | 15 +++++++++++---- bindgen/rust/src/resources.rs | 10 ++++++++++ 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 bindgen/rust/src/resources.rs (limited to 'bindgen/rust/src') 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 { + let path_str = CString::new(path).unwrap(); + let handle = unsafe { ModelLoad_gltf(path_str.as_ptr() as *const _, false) }; + Some(handle) +} -- cgit v1.2.3-70-g09d2