summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bindgen/rust/Cargo.lock30
-rw-r--r--bindgen/rust/Cargo.toml1
-rw-r--r--bindgen/rust/celeritas-sys/Cargo.toml3
-rw-r--r--bindgen/rust/celeritas-sys/build.rs5
-rw-r--r--bindgen/rust/celeritas-sys/src/lib.rs101
-rw-r--r--bindgen/rust/src/lib.rs39
-rw-r--r--bindgen/rust/src/prelude.rs3
-rw-r--r--bindgen/rust/src/ral.rs15
-rw-r--r--bindgen/rust/src/resources.rs10
-rw-r--r--examples/game_demo/game_demo.c11
-rw-r--r--src/core/core.c6
-rw-r--r--src/core/core.h2
-rw-r--r--src/maths/primitives.c2
-rw-r--r--src/new_render/render.c8
-rw-r--r--src/new_render/render.h6
-rw-r--r--src/ral/backends/opengl/backend_opengl.c4
-rw-r--r--src/resources/gltf.c5
17 files changed, 223 insertions, 28 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)
+}
diff --git a/examples/game_demo/game_demo.c b/examples/game_demo/game_demo.c
index 88c95bf..bc43d15 100644
--- a/examples/game_demo/game_demo.c
+++ b/examples/game_demo/game_demo.c
@@ -26,7 +26,7 @@ static const char* faces[6] = { "assets/skybox/right.jpg", "assets/skybox/left.j
"assets/skybox/front.jpg", "assets/skybox/back.jpg" };
int main() {
- Core_Bringup(NULL);
+ Core_Bringup("Celeritas: Game Demo", NULL);
// TODO: Load humanoid model + weapon
// TODO: Animate it with WASD keys
@@ -76,7 +76,8 @@ int main() {
MaterialHandle crate_mat_handle = Material_pool_insert(Render_GetMaterialPool(), &crate_mat);
// ModelHandle cube_handle = ModelLoad_gltf("assets/models/gltf/Cube/glTF/Cube.gltf", false);
ModelHandle cube_handle =
- ModelLoad_gltf("assets/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf", false);
+ // ModelLoad_gltf("assets/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf", false);
+ ModelLoad_gltf("../../assets/prototyper/prototyper_m.gltf", false);
RenderEnt_darray* render_entities = RenderEnt_darray_new(1);
@@ -99,14 +100,16 @@ int main() {
// BEGIN Draw calls
RenderEnt_darray_clear(render_entities); // we re-extract every frame
Quat rot = quat_from_axis_angle(VEC3_X, -HALF_PI, true);
- ModelExtractRenderEnts(render_entities, cube_handle, mat4_rotation(rot),
+ // Mat4 affine = mat4_rotation(rot);
+ Mat4 affine = mat4_ident();
+ ModelExtractRenderEnts(render_entities, cube_handle, affine,
REND_ENT_CASTS_SHADOWS);
// Shadow_Run(entities, entity_count);
if (draw_debug) {
// draw the player model with shadows
- // Render_RenderEntities(render_entities->data, render_entities->len);
+ Render_RenderEntities(render_entities->data, render_entities->len);
// Render_DrawTerrain();
Skybox_Draw(&skybox, cam);
} else {
diff --git a/src/core/core.c b/src/core/core.c
index bb30ced..12aa33f 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -20,11 +20,11 @@ Core g_core; /** @brief global `Core` that other files can use */
/** @brief Gets the global `Core` singleton */
inline Core* GetCore() { return &g_core; }
-void Core_Bringup(struct GLFWwindow* optional_window) {
+void Core_Bringup(const char* window_name, struct GLFWwindow* optional_window) {
INFO("Initiate Core bringup");
memset(&g_core, 0, sizeof(Core));
- RendererConfig conf = { .window_name = { "Celeritas Engine Core" },
+ RendererConfig conf = { .window_name = window_name,
.scr_width = SCR_WIDTH,
.scr_height = SCR_HEIGHT,
.clear_colour = (Vec3){ .08, .08, .1 } };
@@ -80,4 +80,4 @@ GLFWwindow* Core_GetGlfwWindowPtr(Core* core) { return g_core.window; }
struct Renderer* Core_GetRenderer(Core* core) { return core->renderer; }
-Model* Model_Get(ModelHandle h) { return Model_pool_get(&g_core.models, h); } \ No newline at end of file
+Model* Model_Get(ModelHandle h) { return Model_pool_get(&g_core.models, h); }
diff --git a/src/core/core.h b/src/core/core.h
index 86f5b01..4e7ff03 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -32,7 +32,7 @@ Core* get_global_core();
@param [in] optional_window - Leave NULL if you want Celeritas to instantiate its own window with
GLFW, if you want to provide the glfw window then pass it in here.
*/
-void Core_Bringup(GLFWwindow* optional_window);
+void Core_Bringup(const char* window_name, GLFWwindow* optional_window);
void Core_Shutdown();
bool ShouldExit();
diff --git a/src/maths/primitives.c b/src/maths/primitives.c
index ceae260..4a4d55f 100644
--- a/src/maths/primitives.c
+++ b/src/maths/primitives.c
@@ -144,7 +144,7 @@ Vec3 spherical_to_cartesian_coords(f32 rho, f32 theta, f32 phi) {
return vec3(x, y, z);
}
-Geometry geo_create_uvsphere(f32 radius, u32 north_south_lines, u32 east_west_lines) {
+Geometry Geo_CreateUVsphere(f32 radius, u32 north_south_lines, u32 east_west_lines) {
assert(east_west_lines >= 3); // sphere will be degenerate and look gacked without at least 3
assert(north_south_lines >= 3);
diff --git a/src/new_render/render.c b/src/new_render/render.c
index fd5e1c2..c180597 100644
--- a/src/new_render/render.c
+++ b/src/new_render/render.c
@@ -284,6 +284,12 @@ void Geometry_Destroy(Geometry* geometry) {
Vertex_darray_free(geometry->vertices);
}
}
+PUB MeshHandle Mesh_Insert(Mesh* mesh) {
+ return Mesh_pool_insert(Render_GetMeshPool(), mesh);
+}
+PUB MaterialHandle Material_Insert(Material* material) {
+ return Material_pool_insert(Render_GetMaterialPool(), material);
+}
size_t ModelExtractRenderEnts(RenderEnt_darray* entities, ModelHandle model_handle, Mat4 affine,
RenderEntityFlags flags) {
@@ -348,4 +354,4 @@ Material_pool* Render_GetMaterialPool() {
void Render_SetRenderMode(RenderMode mode) {
Renderer* ren = Core_GetRenderer(&g_core);
ren->render_mode = mode;
-} \ No newline at end of file
+}
diff --git a/src/new_render/render.h b/src/new_render/render.h
index 8f3ac2a..7fbc0a7 100644
--- a/src/new_render/render.h
+++ b/src/new_render/render.h
@@ -13,7 +13,7 @@
typedef struct Renderer Renderer;
typedef struct GLFWwindow GLFWwindow;
typedef struct RendererConfig {
- char window_name[256];
+ const char* window_name;
u32 scr_width, scr_height;
Vec3 clear_colour;
} RendererConfig;
@@ -62,6 +62,8 @@ PUB ModelHandle ModelLoad(const char* debug_name, const char* filepath);
PUB Mesh Mesh_Create(Geometry* geometry, bool free_on_upload);
PUB void Mesh_Delete(Mesh* mesh);
void Geometry_Destroy(Geometry* geometry);
+MeshHandle Mesh_Insert(Mesh* mesh);
+MaterialHandle Material_Insert(Material* material);
/** @brief gets render entities from a model and pushes them into a dynamic array for rendering */
size_t ModelExtractRenderEnts(RenderEnt_darray* entities, ModelHandle model_handle, Mat4 affine, RenderEntityFlags flags);
@@ -92,4 +94,4 @@ Mesh_pool* Render_GetMeshPool();
Material_pool* Render_GetMaterialPool();
// --- Setters
-void Render_SetRenderMode(RenderMode mode); \ No newline at end of file
+void Render_SetRenderMode(RenderMode mode);
diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c
index 6ebe4e6..5e08cf3 100644
--- a/src/ral/backends/opengl/backend_opengl.c
+++ b/src/ral/backends/opengl/backend_opengl.c
@@ -419,11 +419,11 @@ void GPU_EncodeDrawIndexed(GPU_CmdEncoder* encoder, u64 index_count) {
bool GPU_Backend_BeginFrame() {
glViewport(0, 0, context.swapchain.dimensions.x * 2, context.swapchain.dimensions.y * 2);
- glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
+ glClearColor(0.8f, 0.8f, 0.8f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
return true;
}
void GPU_Backend_EndFrame() { glfwSwapBuffers(context.window); }
-#endif \ No newline at end of file
+#endif
diff --git a/src/resources/gltf.c b/src/resources/gltf.c
index 91816d8..ce6a83b 100644
--- a/src/resources/gltf.c
+++ b/src/resources/gltf.c
@@ -554,11 +554,14 @@ size_t GLTF_LoadMaterials(cgltf_data *data, Str8 relative_path, Material_darray
} else {
our_material.albedo_map = Render_GetWhiteTexture();
WARN("GLTF model has no albedo map");
+ our_material.base_colour = vec3_create(pbr.base_color_factor[0],pbr.base_color_factor[1], pbr.base_color_factor[2]);
}
// -- metallic
cgltf_texture_view metal_rough_tex_view = pbr.metallic_roughness_texture;
// bool has_metal_
+ printf("Metal factor: %f\n", pbr.metallic_factor);
+ printf("Roughness factor: %f\n", pbr.roughness_factor);
if (metal_rough_tex_view.texture != NULL) {
char metal_rough_map_path[1024];
snprintf(metal_rough_map_path, sizeof(metal_rough_map_path), "%s/%s", relative_path.buf,
@@ -566,6 +569,8 @@ size_t GLTF_LoadMaterials(cgltf_data *data, Str8 relative_path, Material_darray
our_material.metallic_roughness_map = TextureLoadFromFile(metal_rough_map_path);
} else {
WARN("GLTF model has no metal/roughness map");
+ our_material.metallic = pbr.metallic_factor;
+ our_material.roughness = pbr.roughness_factor;
}
cgltf_texture_view normal_tex_view = gltf_material.normal_texture;