summaryrefslogtreecommitdiff
path: root/bindgen
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-27 17:49:33 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-27 17:49:33 +1000
commit02fe2c010857e6c3734b3a354c4119f799947fc6 (patch)
treef6286df45e678929e4998dbfe9d770c58228fedd /bindgen
parentfb1778cb1c853f7fa48afffd256612eac6f387c8 (diff)
misc bindgen crate cleanup
Diffstat (limited to 'bindgen')
-rw-r--r--bindgen/rust/celeritas-sys/build.rs4
-rw-r--r--bindgen/rust/celeritas-sys/examples/gui_test.rs283
-rw-r--r--bindgen/rust/celeritas-sys/src/egui_utils.rs72
-rw-r--r--bindgen/rust/celeritas-sys/src/lib.rs2
-rw-r--r--bindgen/rust/examples/scene.rs192
-rw-r--r--bindgen/rust/src/lib.rs2
-rw-r--r--bindgen/rust/src/prelude.rs2
7 files changed, 110 insertions, 447 deletions
diff --git a/bindgen/rust/celeritas-sys/build.rs b/bindgen/rust/celeritas-sys/build.rs
index f7bf741..9eaa44f 100644
--- a/bindgen/rust/celeritas-sys/build.rs
+++ b/bindgen/rust/celeritas-sys/build.rs
@@ -3,7 +3,7 @@ use std::path::PathBuf;
use bindgen::callbacks::ParseCallbacks;
-const serializable_types: &[&'static str] = &[
+const SERIALIZABLE_TYPES: &[&'static str] = &[
"Vec2",
"Vec3",
"Vec4",
@@ -17,7 +17,7 @@ const serializable_types: &[&'static str] = &[
struct DeriveSerialize;
impl ParseCallbacks for DeriveSerialize {
fn add_derives(&self, info: &bindgen::callbacks::DeriveInfo<'_>) -> Vec<String> {
- if (serializable_types.contains(&info.name)) {
+ if SERIALIZABLE_TYPES.contains(&info.name) {
vec!["Serialize".to_string(), "Deserialize".to_string()]
} else {
vec![]
diff --git a/bindgen/rust/celeritas-sys/examples/gui_test.rs b/bindgen/rust/celeritas-sys/examples/gui_test.rs
deleted file mode 100644
index ddd8b86..0000000
--- a/bindgen/rust/celeritas-sys/examples/gui_test.rs
+++ /dev/null
@@ -1,283 +0,0 @@
-// // #![windows_subsystem = "windows"] // to turn off console.
-
-// use std::ptr;
-// use std::{ffi::CString, ptr::addr_of_mut};
-
-// use celeritas::*;
-// use egui::DragValue;
-// use egui_overlay::{EguiOverlay, OverlayApp};
-// use egui_render_three_d::ThreeDBackend;
-// use egui_window_glfw_passthrough::glfw::Context;
-// use egui_window_glfw_passthrough::{GlfwBackend, GlfwConfig};
-
-// fn main() {
-// // use tracing_subscriber::{fmt, prelude::*, EnvFilter};
-// // if RUST_LOG is not set, we will use the following filters
-// // tracing_subscriber::registry()
-// // .with(fmt::layer())
-// // .with(
-// // EnvFilter::try_from_default_env()
-// // .unwrap_or(EnvFilter::new("debug,wgpu=warn,naga=warn")),
-// // )
-// // .init();
-
-// unsafe {
-// // let p: *mut GLFWwindow = ptr::null_mut();
-// // Core_Bringup(p);
-
-// // let core = get_global_core();
-// // let glfw_window_ptr = Core_GetGlfwWindowPtr(core);
-
-// let mut glfw_backend = GlfwBackend::new(GlfwConfig {
-// // this closure will be called before creating a window
-// glfw_callback: Box::new(|gtx| {
-// // some defualt hints. it is empty atm, but in future we might add some convenience hints to it.
-// (egui_window_glfw_passthrough::GlfwConfig::default().glfw_callback)(gtx);
-// // scale the window size based on monitor scale. as 800x600 looks too small on a 4k screen, compared to a hd screen in absolute pixel sizes.
-// gtx.window_hint(
-// egui_window_glfw_passthrough::glfw::WindowHint::ScaleToMonitor(true),
-// );
-// }),
-// opengl_window: Some(true), // macos doesn't support opengl.
-// transparent_window: Some(false),
-// window_title: "Celeritas egui".into(),
-// ..Default::default()
-// });
-
-// // always on top
-// // glfw_backend.window.set_floating(true);
-// // disable borders/titlebar
-// // glfw_backend.window.set_decorated(false);
-
-// let latest_size = glfw_backend.window.get_framebuffer_size();
-// let latest_size = [latest_size.0 as _, latest_size.1 as _];
-
-// let default_gfx_backend = {
-// ThreeDBackend::new(
-// egui_render_three_d::ThreeDConfig {
-// ..Default::default()
-// },
-// |s| glfw_backend.get_proc_address(s),
-// latest_size,
-// )
-// };
-
-// let glfw_window_ptr = glfw_backend.window.window_ptr();
-// unsafe {
-// // Cast the window pointer to the expected type
-// let window_ptr = glfw_window_ptr as *mut crate::GLFWwindow;
-// Core_Bringup(window_ptr);
-// };
-
-// // cam pos: 18.871811 10.658584 11.643305 cam frontL -0.644326 -0.209243 -0.735569
-// let camera_pos = Vec3 {
-// x: 18.9,
-// y: 10.6,
-// z: 11.6,
-// };
-// let camera_front = Vec3 {
-// x: -0.6,
-// y: -0.2,
-// z: -0.7,
-// };
-// let camera = Camera_Create(
-// camera_pos,
-// camera_front,
-// Vec3 {
-// x: 0.0,
-// y: 1.0,
-// z: 0.0,
-// },
-// 45.0,
-// );
-// SetCamera(camera);
-
-// let mut cube_geo = Geo_CreateCuboid(f32x3 {
-// x: 2.0,
-// y: 2.0,
-// z: 2.0,
-// });
-// let mut crate_mesh = Mesh_Create(addr_of_mut!(cube_geo), false);
-// let albedo_map = TextureLoadFromFile(
-// CString::new("assets/demo/crate/Wood_Crate_001_basecolor.jpg")
-// .unwrap()
-// .as_ptr() as *const i8,
-// );
-// let roughness_map = TextureLoadFromFile(
-// CString::new("assets/demo/crate/Wood_Crate_001_roughness.jpg")
-// .unwrap()
-// .as_ptr() as *const i8,
-// );
-// let normal_map = TextureLoadFromFile(
-// CString::new("assets/demo/crate/Wood_Crate_001_normal.jpg")
-// .unwrap()
-// .as_ptr() as *const i8,
-// );
-// let ao_map = TextureLoadFromFile(
-// CString::new("assets/demo/crate/Wood_Crate_001_ambientOcclusion.jpg")
-// .unwrap()
-// .as_ptr() as *const i8,
-// );
-// let name: [i8; 64] = [0; 64];
-// let mut crate_mat = Material {
-// name: name,
-// kind: 0,
-// param_albedo: Vec3 {
-// x: 0.0,
-// y: 0.0,
-// z: 0.0,
-// },
-// param_metallic: 0.0,
-// param_roughness: 0.0,
-// param_ao: 0.0,
-// pbr_albedo_map: albedo_map,
-// pbr_normal_map: normal_map,
-// metal_roughness_combined: true,
-// pbr_metallic_map: TextureHandle { raw: 99999 },
-// pbr_roughness_map: roughness_map,
-// pbr_ao_map: ao_map,
-// };
-// let crate_renderent = RenderEnt {
-// mesh: addr_of_mut!(crate_mesh),
-// material: addr_of_mut!(crate_mat),
-// affine: mat4_ident(),
-// casts_shadows: true,
-// };
-// let mut render_ents: [RenderEnt; 1] = [crate_renderent];
-
-// let world_state = HelloWorld {
-// frame: 0,
-// render_entities: render_ents,
-// };
-
-// let overlap_app = OverlayApp {
-// user_data: world_state,
-// egui_context: Default::default(),
-// default_gfx_backend,
-// glfw_backend,
-// };
-
-// overlap_app.enter_event_loop();
-
-// // celeritas::egui_utils::start(HelloWorld { frame: 0});
-// }
-// }
-
-// pub struct HelloWorld {
-// pub frame: u64,
-// pub render_entities: [RenderEnt; 1],
-// }
-// impl EguiOverlay for HelloWorld {
-// fn gui_run(
-// &mut self,
-// egui_context: &egui::Context,
-// _default_gfx_backend: &mut ThreeDBackend,
-// glfw_backend: &mut egui_window_glfw_passthrough::GlfwBackend,
-// ) {
-// unsafe {
-// // Frame_Begin();
-// // Render_RenderEntities(
-// // self.render_entities.as_mut_ptr(),
-// // self.render_entities.len(),
-// // );
-// // Frame_End();
-// }
-
-// // just some controls to show how you can use glfw_backend
-// egui::Window::new("controls").show(egui_context, |ui| {
-// ui.set_width(300.0);
-// self.frame += 1;
-// ui.label(format!("current frame number: {}", self.frame));
-// // sometimes, you want to see the borders to understand where the overlay is.
-// let mut borders = glfw_backend.window.is_decorated();
-// if ui.checkbox(&mut borders, "window borders").changed() {
-// glfw_backend.window.set_decorated(borders);
-// }
-
-// ui.label(format!(
-// "pixels_per_virtual_unit: {}",
-// glfw_backend.physical_pixels_per_virtual_unit
-// ));
-// ui.label(format!("window scale: {}", glfw_backend.scale));
-// ui.label(format!("cursor pos x: {}", glfw_backend.cursor_pos[0]));
-// ui.label(format!("cursor pos y: {}", glfw_backend.cursor_pos[1]));
-
-// ui.label(format!(
-// "passthrough: {}",
-// glfw_backend.window.is_mouse_passthrough()
-// ));
-// // how to change size.
-// // WARNING: don't use drag value, because window size changing while dragging ui messes things up.
-// let mut size = glfw_backend.window_size_logical;
-// let mut changed = false;
-// ui.horizontal(|ui| {
-// ui.label("width: ");
-// ui.add_enabled(false, DragValue::new(&mut size[0]));
-// if ui.button("inc").clicked() {
-// size[0] += 10.0;
-// changed = true;
-// }
-// if ui.button("dec").clicked() {
-// size[0] -= 10.0;
-// changed = true;
-// }
-// });
-// ui.horizontal(|ui| {
-// ui.label("height: ");
-// ui.add_enabled(false, DragValue::new(&mut size[1]));
-// if ui.button("inc").clicked() {
-// size[1] += 10.0;
-// changed = true;
-// }
-// if ui.button("dec").clicked() {
-// size[1] -= 10.0;
-// changed = true;
-// }
-// });
-// if changed {
-// glfw_backend.set_window_size(size);
-// }
-// // how to change size.
-// // WARNING: don't use drag value, because window size changing while dragging ui messes things up.
-// let mut pos = glfw_backend.window_position;
-// let mut changed = false;
-// ui.horizontal(|ui| {
-// ui.label("x: ");
-// ui.add_enabled(false, DragValue::new(&mut pos[0]));
-// if ui.button("inc").clicked() {
-// pos[0] += 10;
-// changed = true;
-// }
-// if ui.button("dec").clicked() {
-// pos[0] -= 10;
-// changed = true;
-// }
-// });
-// ui.horizontal(|ui| {
-// ui.label("y: ");
-// ui.add_enabled(false, DragValue::new(&mut pos[1]));
-// if ui.button("inc").clicked() {
-// pos[1] += 10;
-// changed = true;
-// }
-// if ui.button("dec").clicked() {
-// pos[1] -= 10;
-// changed = true;
-// }
-// });
-// if changed {
-// glfw_backend.window.set_pos(pos[0], pos[1]);
-// }
-// });
-
-// // here you decide if you want to be passthrough or not.
-// if egui_context.wants_pointer_input() || egui_context.wants_keyboard_input() {
-// // we need input, so we need the window to be NOT passthrough
-// glfw_backend.set_passthrough(false);
-// } else {
-// // we don't care about input, so the window can be passthrough now
-// glfw_backend.set_passthrough(true)
-// }
-// egui_context.request_repaint();
-// }
-// }
diff --git a/bindgen/rust/celeritas-sys/src/egui_utils.rs b/bindgen/rust/celeritas-sys/src/egui_utils.rs
deleted file mode 100644
index 5432d81..0000000
--- a/bindgen/rust/celeritas-sys/src/egui_utils.rs
+++ /dev/null
@@ -1,72 +0,0 @@
-// use egui_overlay::{EguiOverlay, OverlayApp};
-// use egui_render_three_d::ThreeDBackend;
-// use egui_window_glfw_passthrough::glfw::Context;
-// use egui_window_glfw_passthrough::{GlfwBackend, GlfwConfig};
-
-// use crate::Core_Bringup;
-
-// // struct CustomEguiOverlay {
-// // backend:
-// // }
-
-// fn init() {
-// let mut glfw_backend = GlfwBackend::new(GlfwConfig::default());
-// let mut glfw_window_ptr = glfw_backend.window.window_ptr();
-
-// unsafe {
-// // Cast the window pointer to the expected type
-// let window_ptr = glfw_window_ptr as *mut crate::GLFWwindow;
-// Core_Bringup(window_ptr);
-// };
-// }
-
-// /// After implementing [`EguiOverlay`], just call this function with your app data
-// pub fn start<T: EguiOverlay + 'static>(user_data: T) {
-// let mut glfw_backend = GlfwBackend::new(GlfwConfig {
-// // this closure will be called before creating a window
-// glfw_callback: Box::new(|gtx| {
-// // some defualt hints. it is empty atm, but in future we might add some convenience hints to it.
-// (egui_window_glfw_passthrough::GlfwConfig::default().glfw_callback)(gtx);
-// // scale the window size based on monitor scale. as 800x600 looks too small on a 4k screen, compared to a hd screen in absolute pixel sizes.
-// gtx.window_hint(egui_window_glfw_passthrough::glfw::WindowHint::ScaleToMonitor(true));
-// }),
-// opengl_window: Some(true), // macos doesn't support opengl.
-// transparent_window: Some(false),
-// window_title: "Celeritas egui".into(),
-// ..Default::default()
-// });
-
-// // always on top
-// // glfw_backend.window.set_floating(true);
-// // disable borders/titlebar
-// // glfw_backend.window.set_decorated(false);
-
-// let latest_size = glfw_backend.window.get_framebuffer_size();
-// let latest_size = [latest_size.0 as _, latest_size.1 as _];
-
-// let default_gfx_backend = {
-// ThreeDBackend::new(
-// egui_render_three_d::ThreeDConfig {
-// ..Default::default()
-// },
-// |s| glfw_backend.get_proc_address(s),
-// latest_size,
-// )
-// };
-
-// let glfw_window_ptr = glfw_backend.window.window_ptr();
-// unsafe {
-// // Cast the window pointer to the expected type
-// let window_ptr = glfw_window_ptr as *mut crate::GLFWwindow;
-// Core_Bringup(window_ptr);
-// };
-
-// let overlap_app = OverlayApp {
-// user_data,
-// egui_context: Default::default(),
-// default_gfx_backend,
-// glfw_backend,
-// };
-
-// overlap_app.enter_event_loop();
-// }
diff --git a/bindgen/rust/celeritas-sys/src/lib.rs b/bindgen/rust/celeritas-sys/src/lib.rs
index d0a863e..3a96f59 100644
--- a/bindgen/rust/celeritas-sys/src/lib.rs
+++ b/bindgen/rust/celeritas-sys/src/lib.rs
@@ -4,6 +4,4 @@
use serde::{Deserialize, Serialize};
-pub mod egui_utils;
-
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
diff --git a/bindgen/rust/examples/scene.rs b/bindgen/rust/examples/scene.rs
index b411ffc..ba6b9ef 100644
--- a/bindgen/rust/examples/scene.rs
+++ b/bindgen/rust/examples/scene.rs
@@ -1,97 +1,117 @@
-use std::{ffi::CString, path::Path, ptr::addr_of_mut};
+use std::path::Path;
use celeritas::{ffi::*, SerializableScene};
fn main() {
unsafe {
- let camera_pos = Vec3 {
- x: 18.9,
- y: 10.6,
- z: 11.6,
- };
- let camera_front = Vec3 {
- x: -0.6,
- y: -0.2,
- z: -0.7,
- };
- let mut camera = Camera_Create(
- camera_pos,
- camera_front,
- Vec3 {
- x: 0.0,
- y: 1.0,
- z: 0.0,
- },
- 45.0,
- );
- SetCamera(camera);
+ let camera_pos = Vec3 {
+ x: 18.9,
+ y: 10.6,
+ z: 11.6,
+ };
+ let camera_front = Vec3 {
+ x: -0.6,
+ y: -0.2,
+ z: -0.7,
+ };
+ let camera = Camera_Create(
+ camera_pos,
+ camera_front,
+ Vec3 {
+ x: 0.0,
+ y: 1.0,
+ z: 0.0,
+ },
+ 45.0,
+ );
+ SetCamera(camera);
- let mut cube_geo = Geo_CreateCuboid(f32x3 {
- x: 2.0,
- y: 2.0,
- z: 2.0,
- });
+ let cube_geo = Geo_CreateCuboid(f32x3 {
+ x: 2.0,
+ y: 2.0,
+ z: 2.0,
+ });
- let scene = SerializableScene {
- sun: DirectionalLight { direction: Vec3 { x: 0.0, y: 1.0, z: 0.0 },
- ambient: Vec3 { x: 1.0, y: 1.0, z: 1.0 }, diffuse: Vec3 { x: 1.0, y: 1.0, z: 1.0 }, specular: Vec3 { x: 0.0, y: 0.0, z: 0.0 } },
- point_lights: [None, None, None, None],
- camera_orientation: (camera_pos, camera_front),
- models: vec![],
- };
+ let scene = SerializableScene {
+ sun: DirectionalLight {
+ direction: Vec3 {
+ x: 0.0,
+ y: 1.0,
+ z: 0.0,
+ },
+ ambient: Vec3 {
+ x: 1.0,
+ y: 1.0,
+ z: 1.0,
+ },
+ diffuse: Vec3 {
+ x: 1.0,
+ y: 1.0,
+ z: 1.0,
+ },
+ specular: Vec3 {
+ x: 0.0,
+ y: 0.0,
+ z: 0.0,
+ },
+ },
+ point_lights: [None, None, None, None],
+ camera_orientation: (camera_pos, camera_front),
+ models: vec![],
+ };
- let scene_path = Path::new("default_scene.json");
- scene.store_to_file(scene_path);
+ let scene_path = Path::new("default_scene.json");
+ scene.store_to_file(scene_path);
- let rehydrated_scene = SerializableScene::load_from_file(scene_path);
- dbg!(&rehydrated_scene);
+ let rehydrated_scene = SerializableScene::load_from_file(scene_path);
+ dbg!(&rehydrated_scene);
- // let mut crate_mesh = Mesh_Create(addr_of_mut!(cube_geo), false);
- // let albedo_map = TextureLoadFromFile(
- // CString::new("assets/demo/crate/Wood_Crate_001_basecolor.jpg")
- // .unwrap()
- // .as_ptr() as *const i8,
- // );
- // let roughness_map = TextureLoadFromFile(
- // CString::new("assets/demo/crate/Wood_Crate_001_roughness.jpg")
- // .unwrap()
- // .as_ptr() as *const i8,
- // );
- // let normal_map = TextureLoadFromFile(
- // CString::new("assets/demo/crate/Wood_Crate_001_normal.jpg")
- // .unwrap()
- // .as_ptr() as *const i8,
- // );
- // let ao_map = TextureLoadFromFile(
- // CString::new("assets/demo/crate/Wood_Crate_001_ambientOcclusion.jpg")
- // .unwrap()
- // .as_ptr() as *const i8,
- // );
- // let name: [i8; 64] = [0; 64];
- // let mut crate_mat = Material {
- // name: name,
- // kind: 0,
- // param_albedo: Vec3 {
- // x: 0.0,
- // y: 0.0,
- // z: 0.0,
- // },
- // param_metallic: 0.0,
- // param_roughness: 0.0,
- // param_ao: 0.0,
- // pbr_albedo_map: albedo_map,
- // pbr_normal_map: normal_map,
- // metal_roughness_combined: true,
- // pbr_metallic_map: TextureHandle { raw: 99999 },
- // pbr_roughness_map: roughness_map,
- // pbr_ao_map: ao_map,
- // };
- // let crate_renderent = RenderEnt {
- // mesh: addr_of_mut!(crate_mesh),
- // material: addr_of_mut!(crate_mat),
- // affine: mat4_ident(),
- // casts_shadows: true,
- // };
- // let mut render_ents: [RenderEnt; 1] = [crate_renderent];
-}
+ // let mut crate_mesh = Mesh_Create(addr_of_mut!(cube_geo), false);
+ // let albedo_map = TextureLoadFromFile(
+ // CString::new("assets/demo/crate/Wood_Crate_001_basecolor.jpg")
+ // .unwrap()
+ // .as_ptr() as *const i8,
+ // );
+ // let roughness_map = TextureLoadFromFile(
+ // CString::new("assets/demo/crate/Wood_Crate_001_roughness.jpg")
+ // .unwrap()
+ // .as_ptr() as *const i8,
+ // );
+ // let normal_map = TextureLoadFromFile(
+ // CString::new("assets/demo/crate/Wood_Crate_001_normal.jpg")
+ // .unwrap()
+ // .as_ptr() as *const i8,
+ // );
+ // let ao_map = TextureLoadFromFile(
+ // CString::new("assets/demo/crate/Wood_Crate_001_ambientOcclusion.jpg")
+ // .unwrap()
+ // .as_ptr() as *const i8,
+ // );
+ // let name: [i8; 64] = [0; 64];
+ // let mut crate_mat = Material {
+ // name: name,
+ // kind: 0,
+ // param_albedo: Vec3 {
+ // x: 0.0,
+ // y: 0.0,
+ // z: 0.0,
+ // },
+ // param_metallic: 0.0,
+ // param_roughness: 0.0,
+ // param_ao: 0.0,
+ // pbr_albedo_map: albedo_map,
+ // pbr_normal_map: normal_map,
+ // metal_roughness_combined: true,
+ // pbr_metallic_map: TextureHandle { raw: 99999 },
+ // pbr_roughness_map: roughness_map,
+ // pbr_ao_map: ao_map,
+ // };
+ // let crate_renderent = RenderEnt {
+ // mesh: addr_of_mut!(crate_mesh),
+ // material: addr_of_mut!(crate_mat),
+ // affine: mat4_ident(),
+ // casts_shadows: true,
+ // };
+ // let mut render_ents: [RenderEnt; 1] = [crate_renderent];
+ }
}
diff --git a/bindgen/rust/src/lib.rs b/bindgen/rust/src/lib.rs
index fc8b921..6f25752 100644
--- a/bindgen/rust/src/lib.rs
+++ b/bindgen/rust/src/lib.rs
@@ -36,7 +36,7 @@ impl SerializableScene {
pub fn store_to_file(&self, filepath: &Path) {
let mut file = File::create(filepath).expect("creation failed");
let json = serde_json::to_string(&self).expect("serialize failed");
- file.write(&json.as_bytes()).expect("writing failed");
+ file.write(json.as_bytes()).expect("writing failed");
}
/// TODO: docs
pub fn load_from_file(filepath: &Path) -> Self {
diff --git a/bindgen/rust/src/prelude.rs b/bindgen/rust/src/prelude.rs
index 480986a..097239a 100644
--- a/bindgen/rust/src/prelude.rs
+++ b/bindgen/rust/src/prelude.rs
@@ -1,4 +1,4 @@
+pub use celeritas_sys::Mat4;
pub use celeritas_sys::Vec2;
pub use celeritas_sys::Vec3;
pub use celeritas_sys::Vec4;
-pub use celeritas_sys::Mat4; \ No newline at end of file