From c557763010a8976680f37609ca10e666ff849cd9 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:18:38 +1100 Subject: metal triangle! --- src/mem.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'src/mem.c') diff --git a/src/mem.c b/src/mem.c index e69de29..ba122d7 100644 --- a/src/mem.c +++ b/src/mem.c @@ -0,0 +1,89 @@ +#include + +void_pool void_pool_create(void* storage, const char* debug_label, u64 capacity, u64 entry_size) { + size_t memory_requirements = capacity * entry_size; + // void* backing_buf = arena_alloc(a, memory_requirements); + + assert(entry_size >= sizeof(void_pool_header)); // TODO: create my own assert with error message + + void_pool pool = { .capacity = capacity, + .entry_size = entry_size, + .count = 0, + .backing_buffer = storage, + .free_list_head = NULL, + .debug_label = debug_label }; + + void_pool_free_all(&pool); + + return pool; +} + +void void_pool_free_all(void_pool* pool) { + // set all entries to be free + for (u64 i = 0; i < pool->capacity; i++) { + void* ptr = &pool->backing_buffer[i * pool->entry_size]; + void_pool_header* free_node = + (void_pool_header*)ptr; // we reuse the actual entry itself to hold the header + if (i == (pool->capacity - 1)) { + // if the last one we make its next pointer NULL indicating its full + free_node->next = NULL; + } + free_node->next = pool->free_list_head; + // now the head points to this entry + pool->free_list_head = free_node; + } +} + +void* void_pool_get(void_pool* pool, u32 raw_handle) { + // An handle is an index into the array essentially + void* ptr = pool->backing_buffer + (raw_handle * pool->entry_size); + return ptr; +} + +void* void_pool_alloc(void_pool* pool, u32* out_raw_handle) { + // get the next free node + if (pool->count == pool->capacity) { + // WARN("Pool is full!"); + return NULL; + } + if (pool->free_list_head == NULL) { + // ERROR("%s Pool is full (head = null)", pool->debug_label); + return NULL; + } + void_pool_header* free_node = pool->free_list_head; + + // What index does this become? + uintptr_t start = (uintptr_t)pool->backing_buffer; + uintptr_t cur = (uintptr_t)free_node; + // TRACE("%ld %ld ", start, cur); + assert(cur > start); + u32 index = (u32)((cur - start) / pool->entry_size); + /* printf("Index %d\n", index); */ + if (out_raw_handle != NULL) { + *out_raw_handle = index; + } + + pool->free_list_head = free_node->next; + + memset(free_node, 0, pool->entry_size); + pool->count++; + return (void*)free_node; +} + +void void_pool_dealloc(void_pool* pool, u32 raw_handle) { + // push free node back onto the free list + void* ptr = void_pool_get(pool, raw_handle); + void_pool_header* freed_node = (void_pool_header*)ptr; + + freed_node->next = pool->free_list_head; + pool->free_list_head = freed_node; + + pool->count--; +} + +u32 void_pool_insert(void_pool* pool, void* item) { + u32 raw_handle; + void* item_dest = void_pool_alloc(pool, &raw_handle); + memcpy(item_dest, item, pool->entry_size); + return raw_handle; +} -- cgit v1.2.3-70-g09d2 From 5234133f2d55dc7f24eaa63b86e3952decaaba91 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Fri, 18 Oct 2024 00:23:30 +1100 Subject: chore: format --- .clang-format | 2 +- Makefile | 11 +++++++ examples/triangle.c | 11 +++---- src/core.c | 16 ++++------ src/geometry.c | 87 ++++++++++++++++++++++++++--------------------------- src/log.c | 4 +-- src/maths.c | 4 +-- src/mem.c | 3 +- 8 files changed, 67 insertions(+), 71 deletions(-) (limited to 'src/mem.c') diff --git a/.clang-format b/.clang-format index 059381e..404bcb1 100644 --- a/.clang-format +++ b/.clang-format @@ -1,7 +1,7 @@ --- Language: Cpp BasedOnStyle: Google -ColumnLimit: 100 +ColumnLimit: 120 Cpp11BracedListStyle: false # {.x = 1.0, .y = 2.0} -> { .x = 1.0, .y = 2.0 } IncludeBlocks: Preserve # sort each block of include statements instead of all DerivePointerAlignment: false diff --git a/Makefile b/Makefile index 46890cd..b4cf4d9 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ EXAMPLES_DIR := examples SRCS := $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/**/*.c) OBJS := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRCS)) +# Format-able files +FORMAT_FILES := include/celeritas.h $(SRC_DIR)/*.c $(EXAMPLES_DIR)/*.c + # Shader files METAL_SHADERS := $(wildcard $(SHADER_DIR)/*.metal) METAL_AIR_FILES := $(patsubst $(SHADER_DIR)/%.metal,$(SHADER_OUT_DIR)/%.air,$(METAL_SHADERS)) @@ -85,6 +88,14 @@ cube: $(EXAMPLES_DIR)/cube.c $(SHARED_LIB) $(SHADER_OUT_DIR)/cube.air $(METAL_LI $(CC) $(CFLAGS) $(EXAMPLES_DIR)/cube.c -L$(BUILD_DIR) -lceleritas $(LDFLAGS) -o $(BUILD_DIR)/cube.bin MTL_DEBUG_LAYER=1 build/cube.bin +.PHONY: format +format: + clang-format -i $(FORMAT_FILES) + +.PHONY: tidy +tidy: + clang-tidy $(SRCS) $(EXAMPLES_DIR)/*.c -- $(CFLAGS) + .PHONY: clean clean: rm -rf $(BUILD_DIR) diff --git a/examples/triangle.c b/examples/triangle.c index e5cf92d..7770fd1 100644 --- a/examples/triangle.c +++ b/examples/triangle.c @@ -16,13 +16,10 @@ typedef struct VertexData { } VertexData; VertexData squareVertices[] = { - {{-0.5, -0.5, 0.5, 1.0f}, {0.0f, 0.0f}, 0.0, 0.0}, - {{-0.5, 0.5, 0.5, 1.0f}, {0.0f, 1.0f}, 0.0, 0.0}, - {{ 0.5, 0.5, 0.5, 1.0f}, {1.0f, 1.0f}, 0.0, 0.0}, - {{-0.5, -0.5, 0.5, 1.0f}, {0.0f, 0.0f}, 0.0, 0.0}, - {{ 0.5, 0.5, 0.5, 1.0f}, {1.0f, 1.0f}, 0.0, 0.0}, - {{ 0.5, -0.5, 0.5, 1.0f}, {1.0f, 0.0f}, 0.0, 0.0} - }; + { { -0.5, -0.5, 0.5, 1.0f }, { 0.0f, 0.0f }, 0.0, 0.0 }, { { -0.5, 0.5, 0.5, 1.0f }, { 0.0f, 1.0f }, 0.0, 0.0 }, + { { 0.5, 0.5, 0.5, 1.0f }, { 1.0f, 1.0f }, 0.0, 0.0 }, { { -0.5, -0.5, 0.5, 1.0f }, { 0.0f, 0.0f }, 0.0, 0.0 }, + { { 0.5, 0.5, 0.5, 1.0f }, { 1.0f, 1.0f }, 0.0, 0.0 }, { { 0.5, -0.5, 0.5, 1.0f }, { 1.0f, 0.0f }, 0.0, 0.0 } +}; pipeline_handle draw_pipeline; buf_handle tri_vert_buffer; diff --git a/src/core.c b/src/core.c index 9359a6b..0cbaa09 100644 --- a/src/core.c +++ b/src/core.c @@ -6,7 +6,7 @@ NAMESPACED_LOGGER(core); -core g_core = {0}; +core g_core = { 0 }; #ifdef GPU_METAL static const char* gapi = "Metal"; @@ -43,16 +43,12 @@ void core_shutdown() { glfwTerminate(); } -bool app_should_exit() { - return glfwWindowShouldClose(g_core.window) || g_core.should_exit; -} +bool app_should_exit() { return glfwWindowShouldClose(g_core.window) || g_core.should_exit; } void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { - if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { - g_core.should_exit = true; - } + if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { + g_core.should_exit = true; + } } -void resize_callback(GLFWwindow* window, int width, int height) { - ral_backend_resize_framebuffer(width, height); -} \ No newline at end of file +void resize_callback(GLFWwindow* window, int width, int height) { ral_backend_resize_framebuffer(width, height); } \ No newline at end of file diff --git a/src/geometry.c b/src/geometry.c index d9b0aee..05414d3 100644 --- a/src/geometry.c +++ b/src/geometry.c @@ -10,11 +10,11 @@ typedef struct static_3d_vert { vertex_desc static_3d_vertex_format() { vertex_desc desc; desc.label = "Static 3D Vertex"; - desc.attributes[0] = ATTR_F32x4; // position - desc.attributes[1] = ATTR_F32x4; // normal - desc.attributes[2] = ATTR_F32x2; // tex coord + desc.attributes[0] = ATTR_F32x4; // position + desc.attributes[1] = ATTR_F32x4; // normal + desc.attributes[2] = ATTR_F32x2; // tex coord desc.attribute_count = 3; - desc.padding = 16; // 16 bytes padding + desc.padding = 16; // 16 bytes padding return desc; } @@ -32,57 +32,54 @@ geometry geo_cuboid(f32 x_scale, f32 y_scale, f32 z_scale) { // allocate the data static_3d_vert* vertices = malloc(36 * 64); - vertices[0] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = (v3tov4(VEC3_NEG_Z)), .uv = {0, 0}}; - vertices[1] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = {0, 1} }; - vertices[2] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = {0, 0} }; - vertices[3] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_NEG_Z), .uv = {1, 0} }; - vertices[4] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Z), .uv = {1, 1} }; - vertices[5] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = {0, 1} }; + vertices[0] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = (v3tov4(VEC3_NEG_Z)), .uv = { 0, 0 } }; + vertices[1] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = { 0, 1 } }; + vertices[2] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = { 0, 0 } }; + vertices[3] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_NEG_Z), .uv = { 1, 0 } }; + vertices[4] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Z), .uv = { 1, 1 } }; + vertices[5] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = { 0, 1 } }; // front faces - vertices[6] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_Z), .uv = {0, 1} }; - vertices[7] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Z), .uv = {1, 0} }; - vertices[8] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_Z), .uv = {0, 0} }; - vertices[9] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_Z), .uv = {0, 1} }; - vertices[10] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_Z), .uv = {1, 1} }; - vertices[11] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Z), .uv = {1, 0} }; + vertices[6] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_Z), .uv = { 0, 1 } }; + vertices[7] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Z), .uv = { 1, 0 } }; + vertices[8] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_Z), .uv = { 0, 0 } }; + vertices[9] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_Z), .uv = { 0, 1 } }; + vertices[10] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_Z), .uv = { 1, 1 } }; + vertices[11] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Z), .uv = { 1, 0 } }; // top faces - vertices[12] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = {0, 0} }; - vertices[13] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = {0, 1} }; - vertices[14] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = {1, 1} }; - vertices[15] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = {0, 0} }; - vertices[16] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = {1, 1} }; - vertices[17] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = {1, 0} }; + vertices[12] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = { 0, 0 } }; + vertices[13] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = { 0, 1 } }; + vertices[14] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = { 1, 1 } }; + vertices[15] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = { 0, 0 } }; + vertices[16] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = { 1, 1 } }; + vertices[17] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = { 1, 0 } }; // bottom faces - vertices[18] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = {0, 1} }; - vertices[19] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = {1, 1} }; - vertices[20] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = {0, 1} }; - vertices[21] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = {0, 1} }; - vertices[22] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = {1, 1} }; - vertices[23] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = {0, 1} }; + vertices[18] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 0, 1 } }; + vertices[19] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 1, 1 } }; + vertices[20] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 0, 1 } }; + vertices[21] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 0, 1 } }; + vertices[22] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 1, 1 } }; + vertices[23] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 0, 1 } }; // right faces - vertices[24] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = {0, 0} }; - vertices[25] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = {1, 1} }; - vertices[26] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = {1, 0} }; - vertices[27] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = {1, 1} }; - vertices[28] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = {0, 0} }; - vertices[29] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = {0, 1} }; + vertices[24] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 0, 0 } }; + vertices[25] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 1, 1 } }; + vertices[26] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 1, 0 } }; + vertices[27] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 1, 1 } }; + vertices[28] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 0, 0 } }; + vertices[29] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 0, 1 } }; // left faces - vertices[30] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} }; - vertices[31] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} }; - vertices[32] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} }; - vertices[33] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} }; - vertices[34] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} }; - vertices[35] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} }; + vertices[30] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } }; + vertices[31] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } }; + vertices[32] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } }; + vertices[33] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } }; + vertices[34] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } }; + vertices[35] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } }; - return (geometry) { - .vertex_format = static_3d_vertex_format(), - .vertex_data = vertices, - .has_indices = false, - .indices = NULL + return (geometry){ + .vertex_format = static_3d_vertex_format(), .vertex_data = vertices, .has_indices = false, .indices = NULL }; } \ No newline at end of file diff --git a/src/log.c b/src/log.c index 1083f29..66ffe2d 100644 --- a/src/log.c +++ b/src/log.c @@ -1,8 +1,6 @@ #include -static const char* log_level_strings[] = { - "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE" -}; +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]; diff --git a/src/maths.c b/src/maths.c index 40223c6..fbfcd72 100644 --- a/src/maths.c +++ b/src/maths.c @@ -4,9 +4,7 @@ vec3 vec3_create(f32 x, f32 y, f32 z) { return (vec3){ x, y, z }; } vec4 vec4_create(f32 x, f32 y, f32 z, f32 w) { return (vec4){ x, y, z, w }; } -mat4 mat4_ident() { - return (mat4){ .data = { 1.0, 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.0 } }; -} +mat4 mat4_ident() { return (mat4){ .data = { 1.0, 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.0 } }; } mat4 mat4_mult(mat4 lhs, mat4 rhs) { mat4 out_matrix = mat4_ident(); diff --git a/src/mem.c b/src/mem.c index ba122d7..dd8acda 100644 --- a/src/mem.c +++ b/src/mem.c @@ -22,8 +22,7 @@ void void_pool_free_all(void_pool* pool) { // set all entries to be free for (u64 i = 0; i < pool->capacity; i++) { void* ptr = &pool->backing_buffer[i * pool->entry_size]; - void_pool_header* free_node = - (void_pool_header*)ptr; // we reuse the actual entry itself to hold the header + void_pool_header* free_node = (void_pool_header*)ptr; // we reuse the actual entry itself to hold the header if (i == (pool->capacity - 1)) { // if the last one we make its next pointer NULL indicating its full free_node->next = NULL; -- cgit v1.2.3-70-g09d2 From f5190745aed65b231e380fa3f25fce46d220dcbc Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Fri, 18 Oct 2024 12:55:02 +1100 Subject: removing some outdated docs files --- TODO.md | 4 +- archive/xmake.lua | 205 ++++++++++++++++++++++++++++++++++ bindgen/rust/celeritas-sys/src/lib.rs | 43 +++---- docs/getting-started.md | 7 -- docs/index.md | 2 +- docs/project-layout.md | 32 ------ include/celeritas.h | 95 ++++++++++++---- src/camera.c | 15 +++ src/mem.c | 2 +- src/scene.c | 26 +++++ xmake.lua | 205 ---------------------------------- 11 files changed, 347 insertions(+), 289 deletions(-) create mode 100644 archive/xmake.lua delete mode 100644 docs/getting-started.md delete mode 100644 docs/project-layout.md create mode 100644 src/camera.c create mode 100644 src/scene.c delete mode 100644 xmake.lua (limited to 'src/mem.c') diff --git a/TODO.md b/TODO.md index aa01249..00fb831 100644 --- a/TODO.md +++ b/TODO.md @@ -4,9 +4,9 @@ - ~~compile shared lib~~ - compile and run tests - compile example -- [ ] Consolidate down to a handful of examples +- [x] Consolidate down to a handful of examples - [x] Get rid of doxygen - [ ] make format - [ ] Move to Vulkan-first rendering -- [ ] Build in pipeline (needs vulkan) +- [ ] Build in CI pipeline (needs vulkan) - [ ] Incorporate vma \ No newline at end of file diff --git a/archive/xmake.lua b/archive/xmake.lua new file mode 100644 index 0000000..3c05a70 --- /dev/null +++ b/archive/xmake.lua @@ -0,0 +1,205 @@ +-- set_project("celeritas") +-- set_version("0.1.0") +-- set_config("cc", "clang") + +-- add_rules("mode.debug", "mode.release") -- we have two modes: debug & release + +-- -- -Wall : base set of warnings +-- -- -Wextra : additional warnings not covered by -Wall +-- -- -Wundef : undefined macros +-- -- -Wdouble-promotion : catch implicit converion of float to double +-- add_cflags("-Wall", "-Wextra", "-Wundef", "-Wdouble-promotion") + +-- if is_mode("debug") then +-- add_cflags("-g") -- Add debug symbols in debug mode +-- add_defines("CDEBUG") +-- elseif is_mode("release") then +-- add_defines("CRELEASE") +-- end + +-- -- Platform defines and system packages +-- if is_plat("linux") then +-- add_defines("CEL_PLATFORM_LINUX") +-- add_syslinks("dl", "X11", "pthread") --, "vulkan") +-- elseif is_plat("windows") then +-- add_defines("CEL_PLATFORM_WINDOWS") +-- add_syslinks("user32", "gdi32", "kernel32", "shell32") +-- -- add_requires("vulkansdk", { system = true }) +-- -- add_links("pthreadVC2-w64") +-- elseif is_plat("macosx") then +-- add_defines("CEL_PLATFORM_MAC") +-- add_frameworks("Cocoa", "IOKit", "CoreVideo", "OpenGL") +-- add_frameworks("Foundation", "Metal", "QuartzCore") +-- set_runenv("MTL_DEBUG_LAYER", "1") +-- add_requires("vulkansdk", { system = true }) +-- -- add_syslinks("GL") +-- end + +-- -- Compile GLFW from source +-- package("local_glfw") +-- add_deps("cmake") +-- set_sourcedir(path.join(os.scriptdir(), "deps/glfw-3.3.8")) +-- on_install(function(package) +-- local configs = {} +-- -- NOTE(omni): Keeping these around as comments in case we need to modify glfw flags +-- -- table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) +-- -- table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) +-- import("package.tools.cmake").install(package, configs) +-- end) +-- on_test(function(package) +-- -- assert(package:has_cfuncs("add", {includes = "foo.h"})) +-- end) +-- package_end() + +-- add_requires("local_glfw") + +-- local core_sources = { +-- "deps/glad/src/glad.c", +-- "src/*.c", +-- "src/core/*.c", +-- "src/logos/*.c", +-- "src/maths/*.c", +-- "src/platform/*.c", +-- "src/ral/*.c", +-- "src/ral/backends/opengl/*.c", +-- "src/render/*.c", +-- "src/resources/*.c", +-- "src/std/*.c", +-- "src/std/containers/*.c", +-- "src/systems/*.c", +-- } + +-- local unity_sources = { +-- "deps/Unity/src/unity.c", +-- "deps/Unity/extras/fixture/src/unity_fixture.c", +-- "deps/Unity/extras/memory/src/unity_memory.c", +-- } + +-- rule("compile_glsl_vert_shaders") +-- set_extensions(".vert") +-- on_buildcmd_file(function(target, batchcmds, sourcefile, opt) +-- local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".vert.spv") + +-- print("Compiling shader: %s to %s", sourcefile, targetfile) +-- batchcmds:vrunv('glslc', { sourcefile, "-o", targetfile }) +-- -- batchcmds:add_depfiles(sourcefile) +-- end) + +-- rule("compile_glsl_frag_shaders") +-- set_extensions(".frag") +-- on_buildcmd_file(function(target, batchcmds, sourcefile, opt) +-- local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".frag.spv") + +-- print("Compiling shader: %s to %s", sourcefile, targetfile) +-- batchcmds:vrunv('glslc', { sourcefile, "-o", targetfile }) +-- -- batchcmds:add_depfiles(sourcefile) +-- end) +-- -- TODO: Metal shaders compilation + +-- -- common configuration for both static and shared libraries +-- target("core_config") +-- set_kind("static") -- kind is required but you can ignore it since it's just for common settings +-- add_packages("local_glfw") +-- add_defines("CEL_REND_BACKEND_OPENGL") +-- add_includedirs("deps/cgltf", { public = true }) +-- add_includedirs("deps/glfw-3.3.8/include/GLFW", { public = true }) +-- add_includedirs("deps/glad/include", { public = true }) +-- add_includedirs("deps/stb_image", { public = true }) +-- add_includedirs("deps/stb_image_write", { public = true }) +-- add_includedirs("deps/stb_truetype", { public = true }) +-- add_includedirs("include/", { public = true }) +-- add_includedirs("src/", { public = true }) +-- add_includedirs("src/core", { public = true }) +-- add_includedirs("src/logos/", { public = true }) +-- add_includedirs("src/maths/", { public = true }) +-- add_includedirs("src/platform/", { public = true }) +-- add_includedirs("src/ral", { public = true }) +-- add_includedirs("src/ral/backends/opengl", { public = true }) +-- add_includedirs("src/render", { public = true }) +-- add_includedirs("src/ral/backends/vulkan", { public = true }) +-- add_includedirs("src/resources/", { public = true }) +-- add_includedirs("src/std/", { public = true }) +-- add_includedirs("src/std/containers", { public = true }) +-- add_includedirs("src/systems/", { public = true }) +-- add_files("src/empty.c") -- for some reason we need this on Mac so it doesnt call 'ar' with no files and error +-- -- add_rules("compile_glsl_vert_shaders") +-- -- add_rules("compile_glsl_frag_shaders") +-- -- add_files("assets/shaders/*.frag") +-- if is_plat("windows") then +-- -- add_includedirs("$(env VULKAN_SDK)/Include", { public = true }) +-- -- add_linkdirs("$(env VULKAN_SDK)/Lib", { public = true }) +-- -- add_links("vulkan-1") +-- end +-- if is_plat("macosx") then +-- -- add_files("src/renderer/backends/metal/*.m") +-- -- add_files("src/ral/backends/vulkan/*.c") +-- end +-- set_default(false) -- prevents standalone building of this target + +-- target("core_static") +-- set_kind("static") +-- add_deps("core_config") -- inherit common configurations +-- set_policy("build.merge_archive", true) +-- add_files(core_sources) +-- -- Link against static CRT +-- if is_plat("windows") then +-- add_links("libcmt", "legacy_stdio_definitions") -- for release builds +-- add_links("libcmtd", "legacy_stdio_definitions") -- for debug builds +-- end + +-- target("core_shared") +-- set_kind("shared") +-- add_deps("core_config") -- inherit common configurations +-- add_files(core_sources) +-- -- Link against dynamic CRT +-- if is_plat("windows") then +-- add_links("msvcrt", "legacy_stdio_definitions") -- for release builds +-- add_links("msvcrtd", "legacy_stdio_definitions") -- for debug builds +-- end + +-- -- target("main_loop") +-- -- set_kind("binary") +-- -- set_group("examples") +-- -- add_deps("core_static") +-- -- add_files("examples/main_loop/ex_main_loop.c") +-- -- set_rundir("$(projectdir)") + +-- -- target("tri") +-- -- set_kind("binary") +-- -- set_group("examples") +-- -- add_deps("core_static") +-- -- add_files("examples/triangle/ex_triangle.c") +-- -- set_rundir("$(projectdir)") +-- -- if is_plat("macosx") then +-- -- before_build(function (target) +-- -- print("build metal shaders lib") +-- -- os.exec("mkdir -p build/shaders") +-- -- os.exec("xcrun -sdk macosx metal -c assets/shaders/triangle.metal -o build/shaders/gfx.air") +-- -- os.exec("xcrun -sdk macosx metallib build/shaders/gfx.air -o build/gfx.metallib") +-- -- end) +-- -- end + +-- target("skinned") +-- set_kind("binary") +-- set_group("examples") +-- add_deps("core_shared") +-- add_files("examples/skinned_animation/ex_skinned_animation.c") +-- set_rundir("$(projectdir)") + +-- target("game") +-- set_kind("binary") +-- set_group("examples") +-- add_deps("core_static") +-- add_files("examples/game_demo/game_demo.c") +-- set_rundir("$(projectdir)") + +-- target("pool_tests") +-- set_kind("binary") +-- set_group("tests") +-- add_deps("core_static") +-- add_files(unity_sources) +-- add_includedirs("deps/Unity/src", {public = true}) +-- add_includedirs("deps/Unity/extras/fixture/src", {public = true}) +-- add_includedirs("deps/Unity/extras/memory/src", {public = true}) +-- add_files("tests/pool_tests.c") +-- add_files("tests/pool_test_runner.c") diff --git a/bindgen/rust/celeritas-sys/src/lib.rs b/bindgen/rust/celeritas-sys/src/lib.rs index 3d877a4..5b65f5e 100644 --- a/bindgen/rust/celeritas-sys/src/lib.rs +++ b/bindgen/rust/celeritas-sys/src/lib.rs @@ -6,28 +6,29 @@ use serde::{Deserialize, Serialize}; include!(concat!(env!("OUT_DIR"), "/bindings.rs")); -// // --- Conversions -// pub mod conversions { -// use crate::{Mat4, Vec3, Vec4}; +// --- Conversions +pub mod conversions { + use crate::{mat4, vec3, vec4}; -// impl From for glam::Vec3 { -// fn from(v: Vec3) -> Self { -// Self { -// x: v.x, -// y: v.y, -// z: v.z, -// } -// } -// } -// impl From for Vec3 { -// fn from(v: glam::Vec3) -> Self { -// Self { -// x: v.x, -// y: v.y, -// z: v.z, -// } -// } -// } + impl From for glam::Vec3 { + fn from(v: vec3) -> Self { + Self { + x: v.x, + y: v.y, + z: v.z, + } + } + } + impl From for vec3 { + fn from(v: glam::Vec3) -> Self { + Self { + x: v.x, + y: v.y, + z: v.z, + } + } + } +} // impl From for glam::Vec4 { // fn from(v: Vec4) -> Self { diff --git a/docs/getting-started.md b/docs/getting-started.md deleted file mode 100644 index 0baf21c..0000000 --- a/docs/getting-started.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: Getting up and running ---- - -The main build tool we use is [xmake](https://xmake.io/#/getting_started) so installing that is the main prerequisite. - -Once that is installed you *should* be able to simply run `xmake build` in the top-level directory. \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index fd5b8f6..fb3b6e2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -20,7 +20,7 @@ Celeritas is the original Latin word for celerity that the English is derived fr ## Feature Set -[See here (README)](https://github.com/omnisci3nce/celeritas-core/blob/winter-cleaning/README.md#todo) +[See here (README)](https://github.com/omnisci3nce/celeritas-core/blob/masterREADME.md#goals) ## Getting started diff --git a/docs/project-layout.md b/docs/project-layout.md deleted file mode 100644 index 9a33e8f..0000000 --- a/docs/project-layout.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: Project Structure ---- - -``` -assets/ - shaders and bundled assets for examples (must be licensed open) -bindgen/ - bindings generation -deps/ - third-party dependencies -docs/ - these docs you're reading now that get built with mkdocs -src/ - core/ - core game engine facilities - logos/ - - maths/ - platform/ - ral/ - render/ - resources/ - std/ - systems/ - ui/ -``` - - -#### Core - -Core holds specifically functionality vital to making games or 3D applications. Contrast this with `std` which contains -code that could form the base layer of almost any software out there. - -#### Std - -Data structures, algorithms, memory management, etc - all code here forms a foundation for everything above it and can conceivably -be reused in non-game applications. \ No newline at end of file diff --git a/include/celeritas.h b/include/celeritas.h index 51a9a3d..6b8a673 100644 --- a/include/celeritas.h +++ b/include/celeritas.h @@ -1,5 +1,13 @@ #pragma once +/* + Common abbreviations: + buf = buffer + tex = texture + desc = description + idx = index +*/ + // Standard library includes #include #include @@ -407,7 +415,7 @@ typedef struct shader_function { shader_stage stage; } shader_function; -typedef enum cull_mode { CULL_BACK_FACE, CULL_FRONT_FACE } cull_mode; +typedef enum cull_mode { Cull_BackFace, Cull_FrontFace } cull_mode; typedef struct gfx_pipeline_desc { const char* label; @@ -476,9 +484,9 @@ typedef struct u32_darray u32_darray; // --- Base Renderer types -DEFINE_HANDLE(MeshHandle); -DEFINE_HANDLE(MaterialHandle); -DEFINE_HANDLE(ModelHandle); +DEFINE_HANDLE(mesh_handle); +DEFINE_HANDLE(material_handle); +DEFINE_HANDLE(model_handle); typedef struct geometry { vertex_desc vertex_format; @@ -487,17 +495,30 @@ typedef struct geometry { u32_darray* indices; } geometry; +typedef u32 joint_idx; +typedef struct armature { +} armature; + +/** @brief Mesh data that has been uploaded to GPU and is ready to be rendered each frame + Gets stored in a pool */ typedef struct mesh { buf_handle vertex_buffer; buf_handle index_buffer; - MaterialHandle material; - geometry geometry; - // bool is_skinned; // false = its static - // Armature armature; - // bool is_uploaded; // has the data been uploaded to the GPU + // todo: material? + geometry geo; // the originating mesh data + const armature* skinning_data; } mesh; -// --- Render primitives +typedef struct draw_mesh_cmd { + mesh_handle mesh; + mat4 transform; + vec3 bounding_sphere_center; + f32 bounding_sphere_radius; + const armature* skinning_data; // NULL = static mesh + bool cast_shadows; +} draw_mesh_cmd; + +// --- Geometry/Mesh primitives geometry geo_plane(f32 x_scale, f32 z_scale, u32 tiling_u, u32 tiling_v); geometry geo_cuboid(f32 x_scale, f32 y_scale, f32 z_scale); @@ -505,31 +526,33 @@ geometry geo_cylinder(f32 radius, f32 height, u32 resolution); geometry geo_cone(f32 radius, f32 height, u32 resolution); geometry geo_uv_sphere(f32 radius, u32 north_south_lines, u32 east_west_lines); geometry geo_ico_sphere(f32 radius, f32 n_subdivisions); +void geo_scale_uniform(geometry* geo, f32 scale); +void geo_scale_xyz(geometry* geo, vec3 scale_xyz); // --- Renderer // void renderer_init(renderer* rend); // void renderer_shutdown(renderer* rend); -// --- Scene / Transform Hierarchy - -// --- Gameplay - typedef struct camera { vec3 position; - quat orientation; + // TODO: move to using a quaternion for the camera's orientation - need to update + // how the view transformation matrix is calculated + vec3 forwards; + vec3 up; f32 fov; } camera; -mat4 camera_view_proj(camera); - -// --- Reference Renderer +/** @brief calculates the view and projection matrices for a camera */ +mat4 camera_view_proj(camera camera, f32 lens_height, f32 lens_width, mat4* out_view, mat4* out_proj); // TODO: Filament PBR model -// --- Game and model data +// --- Scene / Transform Hierarchy -DEFINE_HANDLE(model_handle); +// --- Gameplay + +// --- Game and model data typedef struct model { } model; @@ -538,8 +561,40 @@ model_handle model_load_from_gltf(const char* path); // --- Animation +typedef enum keyframe_kind { Keyframe_Rotation, Keyframe_Translation, Keyframe_Scale, Keyframe_Weights } keyframe_kind; + +const char* keyframe_kind_strings[4] = { "ROTATION", "TRANSLATION", "SCALE", "WEIGHTS" }; + +typedef union keyframe { + quat rotation; + vec3 translation; + vec3 scale; + f32 weights[4]; +} keyframe; + +typedef struct keyframes { + keyframe_kind kind; + keyframe* values; + size_t n_frames; +} keyframes; + +typedef enum interpolation { + Interpolation_Step, + Interpolation_Linear, + Interpolation_Cubic +} interpolation; + +typedef struct animation_spline { + f32* timestamps; + size_t n_timestamps; + keyframes frames; +} animation_spline; + // Compute shader approach so we only need one kind of vertex format +// --- Input + + // --- Collisions // --- Physics diff --git a/src/camera.c b/src/camera.c new file mode 100644 index 0000000..79f9c19 --- /dev/null +++ b/src/camera.c @@ -0,0 +1,15 @@ +#include + +mat4 camera_view_proj(camera camera, f32 lens_height, f32 lens_width, mat4* out_view, mat4* out_proj) { + mat4 projection_matrix = mat4_perspective(camera.fov, lens_width / lens_height, 0.1, 1000.0); + // TODO: store near/far on camera rather than hard-coding here. + + vec3 camera_direction = vec3_add(camera.position, camera.forwards); + mat4 view_matrix = mat4_look_at(camera.position, camera_direction, camera.up); + if (out_view) + *out_view = view_matrix; + if (out_proj) + *out_proj = projection_matrix; + + return mat4_mult(view_matrix, projection_matrix); +} \ No newline at end of file diff --git a/src/mem.c b/src/mem.c index dd8acda..2649db5 100644 --- a/src/mem.c +++ b/src/mem.c @@ -1,7 +1,7 @@ #include void_pool void_pool_create(void* storage, const char* debug_label, u64 capacity, u64 entry_size) { - size_t memory_requirements = capacity * entry_size; + size_t _memory_requirements = capacity * entry_size; // void* backing_buf = arena_alloc(a, memory_requirements); assert(entry_size >= sizeof(void_pool_header)); // TODO: create my own assert with error message diff --git a/src/scene.c b/src/scene.c new file mode 100644 index 0000000..fa4d9b5 --- /dev/null +++ b/src/scene.c @@ -0,0 +1,26 @@ +/** + * @file scene.c + * @author your name (you@domain.com) + * @brief + * @version 0.1 + * @date 2024-10-18 + * + * @copyright Copyright (c) 2024 + * + */ +#include + +// Retained mode scene tree that handles performant transform propagation, and allows systems, or other languages via bindings, to +// manipulate rendering/scene data without *owning* said data. + +typedef struct scene_tree_node { + const char* label; +} scene_tree_node; + +DEFINE_HANDLE(scene_node_handle); +TYPED_POOL(scene_tree_node, scene_node); + +typedef struct render_scene_tree { +} render_scene_tree; + +// What kind of operations and mutations can we perform on the tree? diff --git a/xmake.lua b/xmake.lua deleted file mode 100644 index 3c05a70..0000000 --- a/xmake.lua +++ /dev/null @@ -1,205 +0,0 @@ --- set_project("celeritas") --- set_version("0.1.0") --- set_config("cc", "clang") - --- add_rules("mode.debug", "mode.release") -- we have two modes: debug & release - --- -- -Wall : base set of warnings --- -- -Wextra : additional warnings not covered by -Wall --- -- -Wundef : undefined macros --- -- -Wdouble-promotion : catch implicit converion of float to double --- add_cflags("-Wall", "-Wextra", "-Wundef", "-Wdouble-promotion") - --- if is_mode("debug") then --- add_cflags("-g") -- Add debug symbols in debug mode --- add_defines("CDEBUG") --- elseif is_mode("release") then --- add_defines("CRELEASE") --- end - --- -- Platform defines and system packages --- if is_plat("linux") then --- add_defines("CEL_PLATFORM_LINUX") --- add_syslinks("dl", "X11", "pthread") --, "vulkan") --- elseif is_plat("windows") then --- add_defines("CEL_PLATFORM_WINDOWS") --- add_syslinks("user32", "gdi32", "kernel32", "shell32") --- -- add_requires("vulkansdk", { system = true }) --- -- add_links("pthreadVC2-w64") --- elseif is_plat("macosx") then --- add_defines("CEL_PLATFORM_MAC") --- add_frameworks("Cocoa", "IOKit", "CoreVideo", "OpenGL") --- add_frameworks("Foundation", "Metal", "QuartzCore") --- set_runenv("MTL_DEBUG_LAYER", "1") --- add_requires("vulkansdk", { system = true }) --- -- add_syslinks("GL") --- end - --- -- Compile GLFW from source --- package("local_glfw") --- add_deps("cmake") --- set_sourcedir(path.join(os.scriptdir(), "deps/glfw-3.3.8")) --- on_install(function(package) --- local configs = {} --- -- NOTE(omni): Keeping these around as comments in case we need to modify glfw flags --- -- table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) --- -- table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) --- import("package.tools.cmake").install(package, configs) --- end) --- on_test(function(package) --- -- assert(package:has_cfuncs("add", {includes = "foo.h"})) --- end) --- package_end() - --- add_requires("local_glfw") - --- local core_sources = { --- "deps/glad/src/glad.c", --- "src/*.c", --- "src/core/*.c", --- "src/logos/*.c", --- "src/maths/*.c", --- "src/platform/*.c", --- "src/ral/*.c", --- "src/ral/backends/opengl/*.c", --- "src/render/*.c", --- "src/resources/*.c", --- "src/std/*.c", --- "src/std/containers/*.c", --- "src/systems/*.c", --- } - --- local unity_sources = { --- "deps/Unity/src/unity.c", --- "deps/Unity/extras/fixture/src/unity_fixture.c", --- "deps/Unity/extras/memory/src/unity_memory.c", --- } - --- rule("compile_glsl_vert_shaders") --- set_extensions(".vert") --- on_buildcmd_file(function(target, batchcmds, sourcefile, opt) --- local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".vert.spv") - --- print("Compiling shader: %s to %s", sourcefile, targetfile) --- batchcmds:vrunv('glslc', { sourcefile, "-o", targetfile }) --- -- batchcmds:add_depfiles(sourcefile) --- end) - --- rule("compile_glsl_frag_shaders") --- set_extensions(".frag") --- on_buildcmd_file(function(target, batchcmds, sourcefile, opt) --- local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".frag.spv") - --- print("Compiling shader: %s to %s", sourcefile, targetfile) --- batchcmds:vrunv('glslc', { sourcefile, "-o", targetfile }) --- -- batchcmds:add_depfiles(sourcefile) --- end) --- -- TODO: Metal shaders compilation - --- -- common configuration for both static and shared libraries --- target("core_config") --- set_kind("static") -- kind is required but you can ignore it since it's just for common settings --- add_packages("local_glfw") --- add_defines("CEL_REND_BACKEND_OPENGL") --- add_includedirs("deps/cgltf", { public = true }) --- add_includedirs("deps/glfw-3.3.8/include/GLFW", { public = true }) --- add_includedirs("deps/glad/include", { public = true }) --- add_includedirs("deps/stb_image", { public = true }) --- add_includedirs("deps/stb_image_write", { public = true }) --- add_includedirs("deps/stb_truetype", { public = true }) --- add_includedirs("include/", { public = true }) --- add_includedirs("src/", { public = true }) --- add_includedirs("src/core", { public = true }) --- add_includedirs("src/logos/", { public = true }) --- add_includedirs("src/maths/", { public = true }) --- add_includedirs("src/platform/", { public = true }) --- add_includedirs("src/ral", { public = true }) --- add_includedirs("src/ral/backends/opengl", { public = true }) --- add_includedirs("src/render", { public = true }) --- add_includedirs("src/ral/backends/vulkan", { public = true }) --- add_includedirs("src/resources/", { public = true }) --- add_includedirs("src/std/", { public = true }) --- add_includedirs("src/std/containers", { public = true }) --- add_includedirs("src/systems/", { public = true }) --- add_files("src/empty.c") -- for some reason we need this on Mac so it doesnt call 'ar' with no files and error --- -- add_rules("compile_glsl_vert_shaders") --- -- add_rules("compile_glsl_frag_shaders") --- -- add_files("assets/shaders/*.frag") --- if is_plat("windows") then --- -- add_includedirs("$(env VULKAN_SDK)/Include", { public = true }) --- -- add_linkdirs("$(env VULKAN_SDK)/Lib", { public = true }) --- -- add_links("vulkan-1") --- end --- if is_plat("macosx") then --- -- add_files("src/renderer/backends/metal/*.m") --- -- add_files("src/ral/backends/vulkan/*.c") --- end --- set_default(false) -- prevents standalone building of this target - --- target("core_static") --- set_kind("static") --- add_deps("core_config") -- inherit common configurations --- set_policy("build.merge_archive", true) --- add_files(core_sources) --- -- Link against static CRT --- if is_plat("windows") then --- add_links("libcmt", "legacy_stdio_definitions") -- for release builds --- add_links("libcmtd", "legacy_stdio_definitions") -- for debug builds --- end - --- target("core_shared") --- set_kind("shared") --- add_deps("core_config") -- inherit common configurations --- add_files(core_sources) --- -- Link against dynamic CRT --- if is_plat("windows") then --- add_links("msvcrt", "legacy_stdio_definitions") -- for release builds --- add_links("msvcrtd", "legacy_stdio_definitions") -- for debug builds --- end - --- -- target("main_loop") --- -- set_kind("binary") --- -- set_group("examples") --- -- add_deps("core_static") --- -- add_files("examples/main_loop/ex_main_loop.c") --- -- set_rundir("$(projectdir)") - --- -- target("tri") --- -- set_kind("binary") --- -- set_group("examples") --- -- add_deps("core_static") --- -- add_files("examples/triangle/ex_triangle.c") --- -- set_rundir("$(projectdir)") --- -- if is_plat("macosx") then --- -- before_build(function (target) --- -- print("build metal shaders lib") --- -- os.exec("mkdir -p build/shaders") --- -- os.exec("xcrun -sdk macosx metal -c assets/shaders/triangle.metal -o build/shaders/gfx.air") --- -- os.exec("xcrun -sdk macosx metallib build/shaders/gfx.air -o build/gfx.metallib") --- -- end) --- -- end - --- target("skinned") --- set_kind("binary") --- set_group("examples") --- add_deps("core_shared") --- add_files("examples/skinned_animation/ex_skinned_animation.c") --- set_rundir("$(projectdir)") - --- target("game") --- set_kind("binary") --- set_group("examples") --- add_deps("core_static") --- add_files("examples/game_demo/game_demo.c") --- set_rundir("$(projectdir)") - --- target("pool_tests") --- set_kind("binary") --- set_group("tests") --- add_deps("core_static") --- add_files(unity_sources) --- add_includedirs("deps/Unity/src", {public = true}) --- add_includedirs("deps/Unity/extras/fixture/src", {public = true}) --- add_includedirs("deps/Unity/extras/memory/src", {public = true}) --- add_files("tests/pool_tests.c") --- add_files("tests/pool_test_runner.c") -- cgit v1.2.3-70-g09d2