summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-10-17 15:54:22 +1100
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-10-17 15:54:22 +1100
commit16afbddeada7161e931dc261d3404bb5bbc1743d (patch)
treee75db4d668c6a9ebfd07e4dd4d1fdabb66a95896
parentff96a533014174d0857872f86f1536a06089f3d2 (diff)
add .m on mac. log INFO and module name
-rw-r--r--Makefile11
-rw-r--r--examples/triangle.c6
-rw-r--r--include/celeritas.h66
-rw-r--r--src/backend_mtl.c0
-rw-r--r--src/backend_mtl.m22
-rw-r--r--src/core.c6
-rw-r--r--src/log.c6
-rw-r--r--src/ral.c5
8 files changed, 102 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 7c50323..9689dae 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,11 @@ CFLAGS := -Wall -Wextra -O2 $(INCLUDES)
LDFLAGS := -lglfw
# Detect OS
-UNAME_S := $(shell uname -s)
+ifeq ($(OS),Windows_NT)
+ DETECTED_OS := Windows
+else
+ DETECTED_OS := $(shell uname -s)
+endif
# Directories
SRC_DIR := src
@@ -18,6 +22,11 @@ EXAMPLES_DIR := examples
SRCS := $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/**/*.c)
OBJS := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRCS))
+# Add Metal backend written in Objective C only on Mac platform
+ifeq ($(DETECTED_OS),Darwin)
+ SRCS += $(SRC_DIR)/backend_mtl.m
+endif
+
# Library outputs
STATIC_LIB := $(BUILD_DIR)/libceleritas.a
ifeq ($(UNAME_S),Darwin)
diff --git a/examples/triangle.c b/examples/triangle.c
index 1c81d38..83da5e4 100644
--- a/examples/triangle.c
+++ b/examples/triangle.c
@@ -3,7 +3,11 @@
#include <celeritas.h>
int main() {
- Core_Bringup("Celeritas Example: Triangle", NULL);
+ core_bringup("Celeritas Example: Triangle", NULL);
+
+ while (!app_should_exit()) {
+ //
+ }
return 0;
}
diff --git a/include/celeritas.h b/include/celeritas.h
index 6645dc6..0437e15 100644
--- a/include/celeritas.h
+++ b/include/celeritas.h
@@ -60,7 +60,7 @@ _Static_assert(sizeof(ptrdiff_t) == 8, "type ptrdiff_t should be 8 bytes");
// Platform informs renderer backend (unless user overrides)
#if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_WINDOWS)
#define GPU_VULKAN 1
-#elif defined(CEL_PLATFORM_MAC)
+#else
#define GPU_METAL 1
#endif
@@ -88,10 +88,45 @@ void core_shutdown();
void core_resize_viewport(int width, int height);
bool app_should_exit();
+// --- Error handling
+
+// global error handling
+#define CEL_OK 0
+extern int g_last_error;
+
+/** @brief get last global status value */
+int cel_check_status();
+void _cel_push_error(int error_code);
+
// --- Memory facilities: Allocators, helpers
// TODO: Arenas
-// TODO: Pool allocator
+
+// Pool
+typedef struct void_pool_header void_pool_header; // TODO: change name of this
+struct void_pool_header {
+ void_pool_header* next;
+};
+
+typedef struct void_pool {
+ u64 capacity;
+ u64 entry_size;
+ u64 count;
+ void* backing_buffer;
+ void_pool_header* free_list_head;
+ const char* debug_label;
+} void_pool;
+
+void_pool void_pool_create(void* storage, const char* debug_label, u64 capacity, u64 entry_size);
+void void_pool_free_all(void_pool* pool);
+bool void_pool_is_empty(void_pool* pool);
+bool void_pool_is_full(void_pool* pool);
+void* void_pool_get(void_pool* pool, u32 raw_handle);
+void* void_pool_alloc(void_pool* pool, u32* out_raw_handle);
+void void_pool_dealloc(void_pool* pool, u32 raw_handle);
+u32 void_pool_insert(void_pool* pool, void* item);
+
+// TODO: Typed pool
// --- Strings
@@ -119,31 +154,31 @@ void log_output(char* module, loglevel level, const char* msg, ...);
static inline void ERROR(const char* msg, ...) { \
va_list args; \
va_start(args, msg); \
- log_output(#module, LOG_LEVEL_FATAL, msg, args); \
+ log_output(#module, LOG_LEVEL_ERROR, 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); \
+ log_output(#module, LOG_LEVEL_WARN, 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); \
+ log_output(#module, LOG_LEVEL_INFO, 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); \
+ log_output(#module, LOG_LEVEL_DEBUG, 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); \
+ log_output(#module, LOG_LEVEL_TRACE, msg, args); \
va_end(args); \
}
@@ -203,10 +238,13 @@ DEFINE_HANDLE(pipeline_handle);
#define MAX_SHADER_BINDINGS 16
// Backend-specific structs
+typedef struct gpu_device gpu_device;
typedef struct gpu_swapchain gpu_swapchain;
typedef struct gpu_compute_pipeline gpu_compute_pipeline;
typedef struct gpu_gfx_pipeline gpu_gfx_pipeline;
typedef struct gpu_encoder gpu_encoder; // Command encoder
+typedef struct gpu_buffer gpu_buffer;
+typedef struct gpu_texture gpu_texture;
// NOTE: Can we just use Storage buffer for everything?
// typedef enum gpu_buf_type {} gpu_buf_type;
@@ -347,16 +385,26 @@ geometry geo_ico_sphere(f32 radius, f32 n_subdivisions);
// --- Gameplay
-typedef struct Camera {
+typedef struct camera {
vec3 position;
quat orientation;
f32 fov;
-} Camera;
+} camera;
// --- Reference Renderer
// TODO: Filament PBR model
+// --- Game and model data
+
+DEFINE_HANDLE(model_handle);
+
+typedef struct model {
+
+} model;
+
+model_handle model_load_from_gltf(const char* path);
+
// --- Animation
// --- Collisions
diff --git a/src/backend_mtl.c b/src/backend_mtl.c
deleted file mode 100644
index e69de29..0000000
--- a/src/backend_mtl.c
+++ /dev/null
diff --git a/src/backend_mtl.m b/src/backend_mtl.m
new file mode 100644
index 0000000..9a99e14
--- /dev/null
+++ b/src/backend_mtl.m
@@ -0,0 +1,22 @@
+#define GPU_METAL 1
+
+#ifdef GPU_METAL
+#include <celeritas.h>
+
+// Obj-C imports
+#import <Foundation/Foundation.h>
+#import <Metal/Metal.h>
+#import <MetalKit/MetalKit.h>
+#import <QuartzCore/CAMetalLayer.h>
+
+// --- RAL types
+struct gpu_device {
+ id<MTLDevice> id;
+};
+
+struct gpu_swapchain {
+ int width, height;
+ CAMetalLayer* swapchain;
+};
+
+#endif \ No newline at end of file
diff --git a/src/core.c b/src/core.c
index 79b9d6e..0c3c5ea 100644
--- a/src/core.c
+++ b/src/core.c
@@ -4,12 +4,12 @@
NAMESPACED_LOGGER(core);
-void Core_Bringup(const char* window_name, struct GLFWwindow* optional_window) {
+void core_bringup(const char* window_name, struct GLFWwindow* optional_window) {
// INFO("Initiate Core bringup");
INFO("Initiate Core bringup");
INFO("Create GLFW window");
}
-void Core_Shutdown() {}
+void core_shutdown() {}
-bool AppShouldExit() { return true; }
+bool app_should_exit() { return false; }
diff --git a/src/log.c b/src/log.c
index 2a75201..5a6ca5c 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,7 +1,11 @@
#include <celeritas.h>
+static const char* log_level_strings[] = {
+ "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"
+};
+
void log_output(char* module, loglevel level, const char* message, ...) {
char out_msg[4096];
- printf("Msg: %s\n", message);
+ printf("[%s] %s Msg: %s\n", module, log_level_strings[level], message);
}
diff --git a/src/ral.c b/src/ral.c
index 45d202b..e69de29 100644
--- a/src/ral.c
+++ b/src/ral.c
@@ -1,5 +0,0 @@
-#ifdef GPU_VULKAN
-
-#elif GPU_METAL
-
-#endif \ No newline at end of file