summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-10-05 17:44:50 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-10-05 17:44:50 +1000
commit8ce117f0b3fd4ceeb1d7058dde8793e4421ec076 (patch)
treeafb228582dbceb6d9271b0dbd365223119f59d35
parent2c1a7d7f293c26d631e15cf4cbec542ac50994aa (diff)
trying to get rust bindgen working
-rw-r--r--Makefile21
-rw-r--r--archive/src/maths/maths_types.h48
-rw-r--r--bindgen/rust/celeritas-sys/build.rs7
-rw-r--r--bindgen/rust/src/lib.rs8
-rw-r--r--bindgen/rust/src/prelude.rs24
-rw-r--r--examples/triangle.c8
-rw-r--r--include/celeritas.h77
-rw-r--r--src/core.c10
-rw-r--r--src/log.c7
9 files changed, 136 insertions, 74 deletions
diff --git a/Makefile b/Makefile
index 0fbc7f2..7c50323 100644
--- a/Makefile
+++ b/Makefile
@@ -3,12 +3,16 @@ INCLUDES := -I./include -Ideps/glfw-3.3.8/include/GLFW
CFLAGS := -Wall -Wextra -O2 $(INCLUDES)
LDFLAGS := -lglfw
+# Detect OS
+UNAME_S := $(shell uname -s)
+
# Directories
SRC_DIR := src
BUILD_DIR := build
OBJ_DIR := $(BUILD_DIR)/objs
SHADER_DIR := assets/shaders
SHADER_OUT_DIR := $(BUILD_DIR)/shaders
+EXAMPLES_DIR := examples
# Source files
SRCS := $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/**/*.c)
@@ -16,7 +20,14 @@ OBJS := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRCS))
# Library outputs
STATIC_LIB := $(BUILD_DIR)/libceleritas.a
-SHARED_LIB := $(BUILD_DIR)/libceleritas.so
+ifeq ($(UNAME_S),Darwin)
+ SHARED_LIB := $(BUILD_DIR)/libceleritas.dylib
+ SHARED_FLAGS := -dynamiclib
+ LDFLAGS += -framework Foundation -framework CoreFoundation -framework CoreGraphics -framework AppKit
+else
+ SHARED_LIB := $(BUILD_DIR)/libceleritas.so
+ SHARED_FLAGS := -shared
+endif
## Makefile notes
# $@ - target of current rule
@@ -29,7 +40,7 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(SHARED_LIB): $(OBJS)
@mkdir -p $(BUILD_DIR)
- $(CC) -shared -o $@ $^ $(LDFLAGS)
+ $(CC) $(SHARED_FLAGS) -o $@ $^ $(LDFLAGS)
$(STATIC_LIB): $(OBJS)
@mkdir -p $(BUILD_DIR)
@@ -42,6 +53,12 @@ static: $(STATIC_LIB)
.PHONY: all
all: shared static
+.PHONY: triangle
+triangle: build/triangle.bin
+
+build/triangle.bin: $(EXAMPLES_DIR)/triangle.c $(STATIC_LIB)
+ @mkdir -p $(BUILD_DIR)
+ $(CC) $(CFLAGS) $< -o $@ -L$(BUILD_DIR) -lceleritas $(LDFLAGS)
.PHONY: clean
clean:
diff --git a/archive/src/maths/maths_types.h b/archive/src/maths/maths_types.h
index e1dff9c..c0ab8e0 100644
--- a/archive/src/maths/maths_types.h
+++ b/archive/src/maths/maths_types.h
@@ -11,16 +11,7 @@
// --- Types
-/** @brief 2D Vector */
-typedef struct Vec2 {
- f32 x, y;
-} Vec2;
-/** @brief 4x4 Matrix */
-typedef struct Mat4 {
- // TODO: use this format for more readable code: vec4 x_axis, y_axis, z_axis, w_axis;
- f32 data[16];
-} Mat4;
/** @brief Three dimensional bounding box */
typedef struct Bbox_3D {
@@ -31,13 +22,7 @@ typedef struct Bbox_3D {
/** @brief 3D Axis-aligned bounding box */
typedef Bbox_3D Aabb_3D;
-/** @brief 3D affine transformation */
-typedef struct Transform {
- Vec3 position;
- Quat rotation;
- Vec3 scale;
- bool is_dirty;
-} Transform;
+
typedef struct Vec4i {
i32 x, y, z, w;
@@ -46,34 +31,3 @@ typedef struct Vec4i {
typedef struct Vec4u {
u32 x, y, z, w;
} Vec4u;
-
-// --- Some other types
-typedef struct u32x3 {
- union {
- struct {
- u32 x;
- u32 y;
- u32 z;
- };
- struct {
- u32 r;
- u32 g;
- u32 b;
- };
- };
-} u32x3;
-#define u32x3(x, y, z) ((u32x3){ x, y, z })
-
-typedef struct u32x2 {
- u32 x;
- u32 y;
-} u32x2;
-#define u32x2(x, y) ((u32x2){ x, y })
-
-// Type aliass
-
-typedef struct Vec2 f32x2;
-#define f32x2(x, y) ((f32x2){ x, y })
-
-typedef struct Vec3 f32x3;
-#define f32x3(x, y, z) ((f32x3){ x, y, z })
diff --git a/bindgen/rust/celeritas-sys/build.rs b/bindgen/rust/celeritas-sys/build.rs
index 24b1d85..e8c54bd 100644
--- a/bindgen/rust/celeritas-sys/build.rs
+++ b/bindgen/rust/celeritas-sys/build.rs
@@ -46,15 +46,14 @@ fn main() {
// TODO: we need to look based on OS
// Tell cargo to look for shared libraries in the specified directory
- let static_lib_path = "/home/joshua/repos/cel-core3/build".to_string();
+ let static_lib_path = "/Users/josh/code/CodenameVentus/deps/cel-core/build".to_string();
// let static_lib_path = std::env::var("CELERITAS_CORE_LIB")
// .unwrap_or("../../../build/macosx/arm64/debug".to_string());
println!("cargo:rustc-link-search={static_lib_path}");
- // Tell cargo to tell rustc to link the system bzip2
- // shared library.
- println!("cargo:rustc-link-lib=dylib=celeritas");
+ // Tell cargo to tell rustc to link the necc. libraries
+ println!("cargo:rustc-link-lib=celeritas");
println!("cargo:rustc-link-lib=glfw");
// The bindgen::Builder is the main entry point
diff --git a/bindgen/rust/src/lib.rs b/bindgen/rust/src/lib.rs
index 66c99a2..ce3326c 100644
--- a/bindgen/rust/src/lib.rs
+++ b/bindgen/rust/src/lib.rs
@@ -4,14 +4,14 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
pub use celeritas_sys as ffi;
-use glam::Vec3;
+// use glam::Vec3;
/// Commonly used types
pub mod prelude;
-pub mod ral;
-pub mod resources;
-pub mod shader;
+// pub mod ral;
+// pub mod resources;
+// pub mod shader;
// use std::{
// ffi::CString,
diff --git a/bindgen/rust/src/prelude.rs b/bindgen/rust/src/prelude.rs
index 74cc400..90a5df5 100644
--- a/bindgen/rust/src/prelude.rs
+++ b/bindgen/rust/src/prelude.rs
@@ -1,18 +1,20 @@
-// /// --- maths types
-// pub use celeritas_sys::Mat4;
-// pub use celeritas_sys::Vec2;
-// pub use celeritas_sys::Vec3;
-// pub use celeritas_sys::Vec4;
+/// --- maths types
+pub use celeritas_sys::Vec2;
+pub use celeritas_sys::Vec3;
+pub use celeritas_sys::Vec4;
+pub use celeritas_sys::Quat;
+pub use celeritas_sys::Mat4;
+pub use celeritas_sys::Transform;
// // --- handles
-// pub use celeritas_sys::BufferHandle;
-// pub use celeritas_sys::MaterialHandle;
-// pub use celeritas_sys::MeshHandle;
-// pub use celeritas_sys::ModelHandle;
-// pub use celeritas_sys::PipelineHandle;
+pub use celeritas_sys::BufHandle;
+pub use celeritas_sys::TexHandle;
+pub use celeritas_sys::MaterialHandle;
+pub use celeritas_sys::MeshHandle;
+pub use celeritas_sys::ModelHandle;
+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/examples/triangle.c b/examples/triangle.c
index caa427d..1c81d38 100644
--- a/examples/triangle.c
+++ b/examples/triangle.c
@@ -1 +1,9 @@
// Example demonstrating basic RAL usage by rendering a triangle
+
+#include <celeritas.h>
+
+int main() {
+ Core_Bringup("Celeritas Example: Triangle", NULL);
+
+ return 0;
+}
diff --git a/include/celeritas.h b/include/celeritas.h
index b8b0a93..2e0bd28 100644
--- a/include/celeritas.h
+++ b/include/celeritas.h
@@ -1,6 +1,7 @@
#pragma once
// Standard library includes
+#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -82,9 +83,10 @@ struct Core {
};
extern Core g_core; /** @brief global `Core` that other files can use */
-void Core_Bringup(const char* window_name);
+void Core_Bringup(const char* window_name, struct GLFWwindow* optional_window);
void Core_Shutdown();
-bool should_exit();
+void Core_ResizeViewport(int width, int height);
+bool AppShouldExit();
// --- Memory facilities: Allocators, helpers
@@ -95,7 +97,55 @@ bool should_exit();
// --- Logging
-// TODO: Namespaced logger
+// Log levels
+typedef enum LogLevel {
+ LOG_LEVEL_FATAL = 0,
+ LOG_LEVEL_ERROR = 1,
+ LOG_LEVEL_WARN = 2,
+ LOG_LEVEL_INFO = 3,
+ LOG_LEVEL_DEBUG = 4,
+ LOG_LEVEL_TRACE = 5,
+} LogLevel;
+
+void log_output(char* module, LogLevel level, const char* msg, ...);
+
+#define NAMESPACED_LOGGER(module) \
+ static inline void FATAL(const char* msg, ...) { \
+ va_list args; \
+ va_start(args, msg); \
+ log_output(#module, LOG_LEVEL_FATAL, msg, args); \
+ va_end(args); \
+ } \
+ static inline void ERROR(const char* msg, ...) { \
+ va_list args; \
+ va_start(args, msg); \
+ log_output(#module, LOG_LEVEL_FATAL, msg, args); \
+ va_end(args); \
+ } \
+ static inline void WARN(const char* msg, ...) { \
+ va_list args; \
+ va_start(args, msg); \
+ log_output(#module, LOG_LEVEL_FATAL, msg, args); \
+ va_end(args); \
+ } \
+ static inline void INFO(const char* msg, ...) { \
+ va_list args; \
+ va_start(args, msg); \
+ log_output(#module, LOG_LEVEL_FATAL, msg, args); \
+ va_end(args); \
+ } \
+ static inline void DEBUG(const char* msg, ...) { \
+ va_list args; \
+ va_start(args, msg); \
+ log_output(#module, LOG_LEVEL_FATAL, msg, args); \
+ va_end(args); \
+ } \
+ static inline void TRACE(const char* msg, ...) { \
+ va_list args; \
+ va_start(args, msg); \
+ log_output(#module, LOG_LEVEL_FATAL, msg, args); \
+ va_end(args); \
+ }
// --- Maths
@@ -104,6 +154,11 @@ bool should_exit();
#define HALF_PI 1.57079632679489661923
#define TAU (2.0 * PI)
+/** @brief 2D Vector */
+typedef struct Vec2 {
+ f32 x, y;
+} Vec2;
+
/** @brief 3D Vector */
typedef struct Vec3 {
f32 x, y, z;
@@ -117,6 +172,20 @@ typedef struct Vec4 {
/** @brief Quaternion */
typedef Vec4 Quat;
+/** @brief 4x4 Matrix */
+typedef struct Mat4 {
+ // TODO: use this format for more readable code: vec4 x_axis, y_axis, z_axis, w_axis;
+ f32 data[16];
+} Mat4;
+
+/** @brief 3D affine transformation */
+typedef struct Transform {
+ Vec3 position;
+ Quat rotation;
+ Vec3 scale;
+ bool is_dirty;
+} Transform;
+
inlined Vec3 Vec3_Create(f32 x, f32 y, f32 z);
inlined Vec3 Vec3_Add(Vec3 u, Vec3 v);
inlined Vec3 Vec3_Sub(Vec3 u, Vec3 v);
@@ -292,3 +361,5 @@ typedef struct Camera {
// --- Physics
// --- Platform
+
+// --- Audio
diff --git a/src/core.c b/src/core.c
index 88979bb..79b9d6e 100644
--- a/src/core.c
+++ b/src/core.c
@@ -2,10 +2,14 @@
#include <celeritas.h>
-void Core_Bringup(const char* window_name) {
+NAMESPACED_LOGGER(core);
+
+void Core_Bringup(const char* window_name, struct GLFWwindow* optional_window) {
// INFO("Initiate Core bringup");
- printf("Initiate core bringup\n");
+ INFO("Initiate Core bringup");
- printf("Create GLFW window\n");
+ INFO("Create GLFW window");
}
void Core_Shutdown() {}
+
+bool AppShouldExit() { return true; }
diff --git a/src/log.c b/src/log.c
index e69de29..f0dfd87 100644
--- a/src/log.c
+++ b/src/log.c
@@ -0,0 +1,7 @@
+#include <celeritas.h>
+
+void log_output(char* module, LogLevel level, const char* message, ...) {
+ char out_msg[4096];
+
+ printf("Msg: %s\n", message);
+}