diff options
41 files changed, 389 insertions, 332 deletions
@@ -41,6 +41,7 @@ All third-party dependencies are licensed under their own license. ## TODO #### Engine += [ ] Embedded assets - shaders, textures, et al (probably will use C23's `#embed`?) - [ ] Shader hot-reloading - [ ] Cross-platform threadpool - Strings @@ -52,6 +53,7 @@ All third-party dependencies are licensed under their own license. - [x] malloc backed - [ ] overcommit address-space backed (`VirtualAlloc` & `mmap`) - [x] Pool allocator (typed) + - [ ] Generational handles - [ ] SoA hot/cold pool allocator (pool for all entities of same type, split into two structs in SoA so we can have hot ,(`VkHandle`and cold `size`, `format` data separated)) #### Scene diff --git a/src/animation.h b/src/animation.h index 4371279..af2018d 100644 --- a/src/animation.h +++ b/src/animation.h @@ -4,8 +4,6 @@ #include "defines.h" #include "maths_types.h" -KITC_DECL_TYPED_ARRAY(f32) - typedef enum Interpolation { INTERPOLATION_LINEAR, INTERPOLATION_COUNT } Interpolation; typedef enum KeyframeKind { @@ -15,58 +13,69 @@ typedef enum KeyframeKind { KEYFRAME_WEIGHTS, } KeyframeKind; -// typedef union keyframe { -// quat rotation; -// vec3 translation; -// vec3 scale; -// float* weights; -// } keyframe; +typedef union Keyframe { + Quat rotation; + Vec3 translation; + Vec3 scale; + f32 weights[4]; +} Keyframe; + +typedef struct Keyframes { + KeyframeKind kind; + Keyframe* values; + size_t count; +} Keyframes; -// typedef struct keyframes { -// keyframe_kind kind; -// keyframe* values; -// size_t count; -// } keyframes; +typedef struct Joint { + char* debug_label; // optional + Mat4 inverse_bind_matrix; + Mat4 local_transform; + Transform transform_components; +} Joint; +#ifndef TYPED_JOINT_ARRAY +KITC_DECL_TYPED_ARRAY(Joint); +#define TYPED_JOINT_ARRAY +#endif -// typedef struct joint { -// char* name; // optional -// transform transform_components; -// mat4 inverse_bind_matrix; -// mat4 local_transform; -// } joint; +typedef struct Armature { + char* label; + Joint_darray* joints; +} Armature; -// typedef struct animation_spline { -// f32* timestamps; -// size_t n_timestamps; -// keyframes values; -// interpolation interpolation; -// } animation_spline; +// NOTE: I think we will need to topologically sort the joints to store them in array if we want to +// do linear array traversal +// when calculating transforms. -// typedef struct animation_sampler { -// int current_index; -// f32 min; -// f32 max; -// animation_spline animation; -// } animation_sampler; +typedef struct AnimationSpline { + f32* timestamps; + size_t n_timestamps; + Keyframes values; + Interpolation interpolation; +} AnimationSpline; -// /** @brief Sample an animation at a given time `t` */ -// keyframe animation_sample(animation_sampler* sampler, f32 t); +typedef struct AnimationSampler { + int current_index; + f32 min; + f32 max; + AnimationSpline animation; +} AnimationSampler; -// typedef struct animation_clip { -// // A clip contains one or more animation curves -// // for now I think we can just enumerate all of the properties (assuming *only* one per type is in -// // a clip) NULL = this property is not animated in this clip -// animation_sampler* rotation; -// animation_sampler* translation; -// animation_sampler* scale; -// animation_sampler* weights; -// } animation_clip; +/** @brief Sample an animation at a given time `t` returning an interpolated keyframe */ +Keyframe Animation_Sample(AnimationSampler* sampler, f32 t); -// typedef struct skinned_animation { -// mat4* joint_matrices; -// size_t n_joints; -// } skinned_animation; +typedef struct AnimationClip { + // A clip contains one or more animation curves + // for now I think we can just enumerate all of the properties (assuming *only* one per type is in + // a clip) NULL = this property is not animated in this clip + AnimationSampler* rotation; + AnimationSampler* translation; + AnimationSampler* scale; + AnimationSampler* weights; +} AnimationClip; -// // void animation_update_joint_matrices(animation_clip* ) +typedef struct SkinnedAnimation { + Mat4* joint_matrices; + size_t n_joints; +} SkinnedAnimation; -// void animation_play(animation_clip* clip); +void animation_play(AnimationClip* clip); diff --git a/src/core/camera.h b/src/core/camera.h index 9709677..7d2c7ed 100644 --- a/src/core/camera.h +++ b/src/core/camera.h @@ -22,12 +22,12 @@ Camera Camera_Create(Vec3 pos, Vec3 front, Vec3 up, f32 fov); * @param out_view optionally stores just the view matrix * @param out_proj optionally stores just the projection matrix * @returns the camera's view projection matrix pre-multiplied -*/ -PUB Mat4 Camera_ViewProj(Camera* c, f32 lens_height, f32 lens_width, Mat4* out_view, Mat4* out_proj); + */ +PUB Mat4 Camera_ViewProj(Camera* c, f32 lens_height, f32 lens_width, Mat4* out_view, + Mat4* out_proj); /** @brief Get 2D camera transform matrix */ -PUB Mat4 Camera_View2D(Camera* c); // TODO: 2D cameras - +PUB Mat4 Camera_View2D(Camera* c); // TODO: 2D cameras // TODO: (HIGH) Basic reusable camera controls /* diff --git a/src/core/core.h b/src/core/core.h index b0f8dbe..ac07c50 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -1,8 +1,8 @@ #pragma once #include "input.h" -#include "render_types.h" #include "mem.h" +#include "render_types.h" #include "scene.h" #include "screenspace.h" #include "terrain.h" @@ -14,11 +14,11 @@ TYPED_POOL(Model, Model) typedef struct GLFWwindow GLFWwindow; typedef struct Core { - const char* app_name; - GLFWwindow* window; - Renderer* renderer; - Input_State input; - Model_pool models; + const char* app_name; + GLFWwindow* window; + Renderer* renderer; + Input_State input; + Model_pool models; } Core; extern Core g_core; diff --git a/src/core/triggers.h b/src/core/triggers.h index a9ced17..a823890 100644 --- a/src/core/triggers.h +++ b/src/core/triggers.h @@ -4,12 +4,12 @@ // Events/signals that get triggered by certain things that happen /* -e.g. +e.g. collider enters volume (collider) collider exits volume (collider) -you could create a custom signal that only triggers when a collider has been inside a volume for 3 seconds -listen for Enter, start timer, if hits 3 -> emit signal. Else, reset state +you could create a custom signal that only triggers when a collider has been inside a volume for 3 +seconds listen for Enter, start timer, if hits 3 -> emit signal. Else, reset state Top-level triggers: level loaded diff --git a/src/core/vfs.h b/src/core/vfs.h new file mode 100644 index 0000000..41033f5 --- /dev/null +++ b/src/core/vfs.h @@ -0,0 +1,38 @@ +#pragma once +#include "defines.h" + +#define MAX_VIRTUAL_FILENAME_LEN 256 + +typedef struct VFS_Pack VFS_Pack; + +const char VFS_OpenErr_DoesNotExist[] = "PATH DOES NOT EXIST"; + +typedef struct VFS_File { + size_t n_bytes; + void* data; +} VFS_File; + +// virtual file open result +typedef struct VFS_FileRes { + bool success; + const char* error_reason; + VFS_File file; +} VFS_FileRes; + +VFS_Pack* VFS_Open(const char* filepath); + +bool VFS_Close(VFS_Pack*); + +VFS_FileRes VFS_VirtualRead(VFS_Pack* vfs, const char* unique_path); + +typedef struct VFS_PackBuilder { + const char* pack_filename; +} VFS_PackBuilder; + +typedef struct VFS_FileEntry { + char filename[MAX_VIRTUAL_FILENAME_LEN]; + size_t offset; + size_t size; +} VFS_FileEntry; + +VFS_PackBuilder VFS_Pack_Create();
\ No newline at end of file diff --git a/src/defines.h b/src/defines.h index a16d68e..689eeca 100644 --- a/src/defines.h +++ b/src/defines.h @@ -42,6 +42,8 @@ _Static_assert(sizeof(ptrdiff_t) == 8, "type ptrdiff_t should be 8 bytes"); #define alignof(x) _Alignof(x) +#define threadlocal _Thread_local + // Wrap a u32 to make a type-safe "handle" or ID #define CORE_DEFINE_HANDLE(name) \ typedef struct name name; \ @@ -49,13 +51,14 @@ _Static_assert(sizeof(ptrdiff_t) == 8, "type ptrdiff_t should be 8 bytes"); u32 raw; \ } -CORE_DEFINE_HANDLE(Handle); // Untyped handle that can be casted to a strongly typed resource handle +CORE_DEFINE_HANDLE( + Handle); // Untyped handle that can be casted to a strongly typed resource handle -#define PUB // For collecting public APIs to expose in an amalgamation header file +#define PUB // For collecting public APIs to expose in an amalgamation header file -#define KB(x) ((size_t) x * 1000) -#define MB(x) ((size_t) x * 1000 * 1000) -#define GB(x) ((size_t) x * 1000 * 1000 * 1000) +#define KB(x) ((size_t)x * 1000) +#define MB(x) ((size_t)x * 1000 * 1000) +#define GB(x) ((size_t)x * 1000 * 1000 * 1000) // NOTE: The below is now handled in xmake.lua // Platform will inform renderer backend (unless user overrides) diff --git a/src/logos/tasks.h b/src/logos/tasks.h index 3e6bd06..2e3dc53 100644 --- a/src/logos/tasks.h +++ b/src/logos/tasks.h @@ -7,54 +7,68 @@ #include "render_types.h" #include "str.h" +typedef enum TaskLifetime { + /** ephemeral tasks must be finished by the end of the frame and thus we use a leak and clear + allocation strategy */ + TASK_EPHEMERAL, + /** multi-frame tasks have a more complex lifetime and must be cleaned up by the caller or in a + separate cleanup callback */ + TASK_MULTIFRAME, + TASK_COUNT +} TaskLifetime; + +typedef enum TaskKind { + TASK_RENDER, + TASK_PHYSICS, + TASK_GAMEPLAY, + TASK_ASSET, + TASK_USERLAND, + TASKKIND_COUNT +} TaskKind; + typedef struct Task { - char* debug_name; - void* params; - bool is_done; + char* debug_name; + void* params; + bool is_done; } Task; // Macro : give Params and Result structs and it creates a function that knows // correct sizes typedef struct Task_ModelLoad_Params { - Str8 filepath; // filepath to the model on disk - } Task_ModelLoad_Params; + Str8 filepath; // filepath to the model on disk +} Task_ModelLoad_Params; typedef struct Task_ModelLoad_Result { - Model model; + Model model; } Task_ModelLoad_Result; // Internally it will allocate data for each -static bool Task_ModelLoad_Typed( - Task_ModelLoad_Params* params, - Task_ModelLoad_Result* result, - tpool_task_start run_task, - tpool_task_on_complete on_success, - tpool_task_on_complete on_failure -) { - threadpool_add_task(pool, , tpool_task_on_complete on_success, tpool_task_on_complete on_fail, bool buffer_result_for_main_thread, void *param_data, u32 param_data_size, u32 result_data_size) +static bool Task_ModelLoad_Typed(Task_ModelLoad_Params* params, Task_ModelLoad_Result* result, + tpool_task_start run_task, tpool_task_on_complete on_success, + tpool_task_on_complete on_failure) { + threadpool_add_task(pool, , tpool_task_on_complete on_success, tpool_task_on_complete on_fail, + bool buffer_result_for_main_thread, void* param_data, u32 param_data_size, + u32 result_data_size) } // do task // success void model_load_success(task_globals* globals, void* result) { - Task_ModelLoad_Result* load_res = result; + Task_ModelLoad_Result* load_res = result; - // push into render -> renderables ? + // push into render -> renderables ? } // fail - // we can define our custom task here that wraps the more verbose function pointers -static Task Task_ModelLoad( - Task_ModelLoad_Params* params, - Task_ModelLoad_Result* result -) { - Task task; - task.debug_name = "Load Model"; - task.params = params; +static Task Task_ModelLoad(Task_ModelLoad_Params* params, Task_ModelLoad_Result* result) { + Task task; + task.debug_name = "Load Model"; + task.params = params; - Task_ModelLoad_Typed(params, result, tpool_task_start run_task, tpool_task_on_complete on_success, tpool_task_on_complete on_failure) + Task_ModelLoad_Typed(params, result, tpool_task_start run_task, tpool_task_on_complete on_success, + tpool_task_on_complete on_failure) - return task; + return task; } diff --git a/src/logos/threadpool.h b/src/logos/threadpool.h index fbe43d6..2cd70fd 100644 --- a/src/logos/threadpool.h +++ b/src/logos/threadpool.h @@ -93,4 +93,4 @@ bool threadpool_add_task(threadpool *pool, tpool_task_start do_task, void threadpool_process_results(threadpool *pool, int num_to_process); -u32 Tpool_GetNumWorkers(); // how many threads are we using
\ No newline at end of file +u32 Tpool_GetNumWorkers(); // how many threads are we using
\ No newline at end of file diff --git a/src/maths/maths.h b/src/maths/maths.h index 930ee0a..3a8f34c 100644 --- a/src/maths/maths.h +++ b/src/maths/maths.h @@ -50,7 +50,9 @@ static inline Vec3 vec3_cross(Vec3 a, Vec3 b) { #define VEC3_Z ((Vec3){ .x = 0.0, .y = 0.0, .z = 1.0 }) #define VEC3_NEG_Z ((Vec3){ .x = 0.0, .y = 0.0, .z = -1.0 }) -static inline void print_vec3(Vec3 v) { printf("{ x: %f, y: %f, z: %f )\n", (f64)v.x, (f64)v.y, (f64)v.z); } +static inline void print_vec3(Vec3 v) { + printf("{ x: %f, y: %f, z: %f )\n", (f64)v.x, (f64)v.y, (f64)v.z); +} // TODO: Dimension 2 static inline Vec2 vec2_create(f32 x, f32 y) { return (Vec2){ x, y }; } @@ -127,7 +129,8 @@ static inline Quat quat_slerp(Quat a, Quat b, f32 percentage) { f64 sin_theta = sin((f64)theta); // compute this value only once f64 sin_theta_0 = sin((f64)theta_0); // compute this value only once - f32 s0 = cos(theta) - (f64)dot * sin_theta / sin_theta_0; // == sin(theta_0 - theta) / sin(theta_0) + f32 s0 = + cos(theta) - (f64)dot * sin_theta / sin_theta_0; // == sin(theta_0 - theta) / sin(theta_0) f32 s1 = sin_theta / sin_theta_0; return (Quat){ (q0.x * s0) + (q1.x * s1), (q0.y * s0) + (q1.y * s1), (q0.z * s0) + (q1.z * s1), diff --git a/src/new_render/immdraw.h b/src/new_render/immdraw.h index 46c5add..add7b76 100644 --- a/src/new_render/immdraw.h +++ b/src/new_render/immdraw.h @@ -7,7 +7,6 @@ #include "maths_types.h" typedef struct Immdraw_Storage { - } Immdraw_Storage; // --- Public API diff --git a/src/new_render/pbr.h b/src/new_render/pbr.h index f3bad4b..914975b 100644 --- a/src/new_render/pbr.h +++ b/src/new_render/pbr.h @@ -5,18 +5,18 @@ #pragma once #include "backend_opengl.h" -#include "defines.h" #include "camera.h" +#include "defines.h" #include "maths_types.h" #include "ral_types.h" #include "render_types.h" // --- Public API typedef struct PBR_Storage { - GPU_Renderpass* pbr_pass; - GPU_Pipeline* pbr_pipeline; + GPU_Renderpass* pbr_pass; + GPU_Pipeline* pbr_pipeline; -} PBR_Storage; // Stores all necessary data and handles +} PBR_Storage; // Stores all necessary data and handles typedef struct PBRMaterialUniforms { Material mat; @@ -25,12 +25,11 @@ typedef struct PBRMaterialUniforms { PUB void PBR_Init(PBR_Storage* storage); // NOTE: For simplicity's sake we will render this pass directly to the default framebuffer -PUB void PBR_Run( - PBR_Storage* storage - // light data - // camera - // geometry - // materials +PUB void PBR_Run(PBR_Storage* storage + // light data + // camera + // geometry + // materials ); typedef struct PBR_Params { @@ -57,12 +56,7 @@ GPU_Renderpass* PBR_RPassCreate(); GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass); -void PBR_Execute( - PBR_Storage* storage, - Camera camera, - TextureHandle shadowmap_tex, - RenderEnt* entities, - size_t entity_count -); +void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_tex, + RenderEnt* entities, size_t entity_count); ShaderDataLayout PBRMaterial_GetLayout(void* data);
\ No newline at end of file diff --git a/src/new_render/render.c b/src/new_render/render.c index bcdeb75..dcaa5a5 100644 --- a/src/new_render/render.c +++ b/src/new_render/render.c @@ -223,6 +223,4 @@ void Geometry_Destroy(Geometry* geometry) { void SetCamera(Camera camera) { g_core.renderer->scene.camera = camera; } void SetMainLight(DirectionalLight light) { g_core.renderer->scene.sun = light; } -arena* GetRenderFrameArena(Renderer* r) { - return &r->frame_arena; -}
\ No newline at end of file +arena* GetRenderFrameArena(Renderer* r) { return &r->frame_arena; }
\ No newline at end of file diff --git a/src/new_render/render.h b/src/new_render/render.h index 0043c6c..13c626d 100644 --- a/src/new_render/render.h +++ b/src/new_render/render.h @@ -11,18 +11,18 @@ typedef struct Renderer Renderer; typedef struct GLFWwindow GLFWwindow; typedef struct RendererConfig { - char window_name[256]; - u32 scr_width, scr_height; - Vec3 clear_colour; + char window_name[256]; + u32 scr_width, scr_height; + Vec3 clear_colour; } RendererConfig; typedef struct RenderFlags { - bool wireframe; + bool wireframe; } RenderFlags; typedef struct RenderCtx { - Mat4 view; - Mat4 projection; + Mat4 view; + Mat4 projection; } RenderCtx; // --- Lifecycle diff --git a/src/new_render/render_frame.c b/src/new_render/render_frame.c index 2dc98b0..9a95259 100644 --- a/src/new_render/render_frame.c +++ b/src/new_render/render_frame.c @@ -6,14 +6,14 @@ #include "mem.h" #include "render.h" - -Cull_Result Frame_Cull(Renderer* ren, RenderEnt *entities, size_t entity_count, Camera *camera) { +Cull_Result Frame_Cull(Renderer* ren, RenderEnt* entities, size_t entity_count, Camera* camera) { // TODO: u32 chunk_count = Tpool_GetNumWorkers(); arena* frame_arena = GetRenderFrameArena(ren); - Cull_Result result = {0}; - result.visible_ent_indices = arena_alloc(frame_arena, sizeof(u32) * entity_count); // make space for if all ents are visible + Cull_Result result = { 0 }; + result.visible_ent_indices = arena_alloc( + frame_arena, sizeof(u32) * entity_count); // make space for if all ents are visible assert((result.n_visible_objects + result.n_culled_objects == entity_count)); return result; diff --git a/src/new_render/render_frame.h b/src/new_render/render_frame.h index 11b24f2..02f7f22 100644 --- a/src/new_render/render_frame.h +++ b/src/new_render/render_frame.h @@ -14,7 +14,7 @@ typedef struct Cull_Result { u64 n_visible_objects; u64 n_culled_objects; - u32* visible_ent_indices; // allocated on frame arena + u32* visible_ent_indices; // allocated on frame arena size_t index_count; } Cull_Result; @@ -24,4 +24,4 @@ typedef void (*ExtractRenderData)(void* world_data); typedef struct Renderer Renderer; /** @brief Produces a smaller set of only those meshes visible in the camera frustum on the CPU */ -Cull_Result Frame_Cull(Renderer* ren, RenderEnt* entities, size_t entity_count, Camera *camera);
\ No newline at end of file +Cull_Result Frame_Cull(Renderer* ren, RenderEnt* entities, size_t entity_count, Camera* camera);
\ No newline at end of file diff --git a/src/new_render/render_scene.h b/src/new_render/render_scene.h index 1e4660a..31dc1c9 100644 --- a/src/new_render/render_scene.h +++ b/src/new_render/render_scene.h @@ -3,15 +3,15 @@ * @brief */ #pragma once +#include "camera.h" #include "defines.h" #include "render_types.h" -#include "camera.h" /** @brief Holds globally bound data for rendering a scene. Typically held by the renderer. * Whenever you call draw functions you can think of this as an implicit parameter. */ typedef struct RenderScene { - Camera camera; - DirectionalLight sun; + Camera camera; + DirectionalLight sun; } RenderScene; // --- Public APIs diff --git a/src/new_render/render_types.h b/src/new_render/render_types.h index 4807559..e0bd76b 100644 --- a/src/new_render/render_types.h +++ b/src/new_render/render_types.h @@ -1,13 +1,13 @@ /** * @file render_types.h * @brief -*/ + */ #pragma once #include "defines.h" +#include "maths.h" #include "maths_types.h" #include "ral.h" -#include "maths.h" #include "ral_types.h" // --- Handles @@ -29,9 +29,9 @@ typedef struct u32_opt { typedef struct Mesh { BufferHandle vertex_buffer; BufferHandle index_buffer; - Geometry geometry; // NULL means it has been freed CPU-side - i32 material_index; // -1 => no material - bool is_uploaded; // has the data been uploaded to the GPU + Geometry geometry; // NULL means it has been freed CPU-side + i32 material_index; // -1 => no material + bool is_uploaded; // has the data been uploaded to the GPU } Mesh; #ifndef TYPED_MESH_ARRAY KITC_DECL_TYPED_ARRAY(Mesh) @@ -39,15 +39,15 @@ KITC_DECL_TYPED_ARRAY(Mesh) #endif typedef struct TextureData { - TextureDesc description; - void* image_data; + TextureDesc description; + void* image_data; } TextureData; // --- Supported materials typedef enum MaterialKind { - MAT_BLINN_PHONG, // NOTE: we're dropping support for this - MAT_PBR, // uses textures for PBR properties - MAT_PBR_PARAMS, // uses float values to represent a surface uniformly + MAT_BLINN_PHONG, // NOTE: we're dropping support for this + MAT_PBR, // uses textures for PBR properties + MAT_PBR_PARAMS, // uses float values to represent a surface uniformly MAT_COUNT } MaterialKind; static const char* material_kind_names[] = { "Blinn Phong", "PBR (Textures)", "PBR (Params)", @@ -107,11 +107,11 @@ typedef struct DirectionalLight { // A renderable 'thing' typedef struct RenderEnt { - Mesh* mesh; - Material* material; - Mat4 affine; // In the future this should be updated by the transform graph - // Bbox_3D bounding_box; - bool casts_shadows; + Mesh* mesh; + Material* material; + Mat4 affine; // In the future this should be updated by the transform graph + // Bbox_3D bounding_box; + bool casts_shadows; } RenderEnt; #ifndef TYPED_RENDERENT_ARRAY diff --git a/src/new_render/shader_layouts.h b/src/new_render/shader_layouts.h index c98f3c5..09cf129 100644 --- a/src/new_render/shader_layouts.h +++ b/src/new_render/shader_layouts.h @@ -15,7 +15,6 @@ typedef struct Binding_Model { /** @brief data that is handy to have in any shader */ typedef struct Binding_Globals { - } Binding_Globals; typedef struct pbr_point_light { @@ -33,45 +32,39 @@ static ShaderDataLayout Binding_Camera_GetLayout(void* data) { Binding_Camera* d = data; bool has_data = data != NULL; - ShaderBinding b1 = { - .label = "Camera", - .kind = BINDING_BYTES, - .data.bytes = { .size = sizeof(Binding_Camera) } - }; + ShaderBinding b1 = { .label = "Camera", + .kind = BINDING_BYTES, + .data.bytes = { .size = sizeof(Binding_Camera) } }; if (has_data) { b1.data.bytes.data = d; } - return (ShaderDataLayout) {.bindings = {b1 }, .binding_count = 1}; + return (ShaderDataLayout){ .bindings = { b1 }, .binding_count = 1 }; } static ShaderDataLayout Binding_Model_GetLayout(void* data) { Binding_Model* d = data; bool has_data = data != NULL; - ShaderBinding b1 = { - .label = "Model", - .kind = BINDING_BYTES, - .vis = VISIBILITY_VERTEX, - .data.bytes = { .size = sizeof(Binding_Model) } - }; + ShaderBinding b1 = { .label = "Model", + .kind = BINDING_BYTES, + .vis = VISIBILITY_VERTEX, + .data.bytes = { .size = sizeof(Binding_Model) } }; if (has_data) { b1.data.bytes.data = d; } - return (ShaderDataLayout) {.bindings = {b1 }, .binding_count = 1}; + return (ShaderDataLayout){ .bindings = { b1 }, .binding_count = 1 }; } static ShaderDataLayout Binding_Lights_GetLayout(void* data) { -Binding_Lights* d = data; + Binding_Lights* d = data; bool has_data = data != NULL; - ShaderBinding b1 = { - .label = "Lights", - .kind = BINDING_BYTES, - .vis = VISIBILITY_FRAGMENT, - .data.bytes = { .size = sizeof(Binding_Lights) } - }; + ShaderBinding b1 = { .label = "Lights", + .kind = BINDING_BYTES, + .vis = VISIBILITY_FRAGMENT, + .data.bytes = { .size = sizeof(Binding_Lights) } }; if (has_data) { b1.data.bytes.data = d; } - return (ShaderDataLayout) {.bindings = {b1 }, .binding_count = 1}; + return (ShaderDataLayout){ .bindings = { b1 }, .binding_count = 1 }; }
\ No newline at end of file diff --git a/src/new_render/shadows.h b/src/new_render/shadows.h index 9e8a6ad..11fce3b 100644 --- a/src/new_render/shadows.h +++ b/src/new_render/shadows.h @@ -1,7 +1,6 @@ /** * @brief Functions for adding shadows to scene rendering. -*/ - + */ #pragma once #include "defines.h" @@ -10,11 +9,11 @@ #include "render_types.h" typedef struct Shadow_Storage { - GPU_Renderpass* shadowmap_pass; - GPU_Pipeline* pipeline; - bool debug_quad_enabled; - TextureHandle depth_texture; - // TODO: Some statistics tracking + GPU_Renderpass* shadowmap_pass; + GPU_Pipeline* pipeline; + bool debug_quad_enabled; + TextureHandle depth_texture; + // TODO: Some statistics tracking } Shadow_Storage; typedef struct ShadowUniforms { @@ -36,7 +35,8 @@ PUB void Shadow_Run(Shadow_Storage* storage, RenderEnt* entities, size_t entity_ PUB Handle Shadow_GetShadowMapTexture(Shadow_Storage* storage); // --- Internal -GPU_Renderpass* Shadow_RPassCreate(); // Creates the render pass -GPU_Pipeline* Shadow_PipelineCreate(GPU_Renderpass* rpass); // Creates the pipeline -void Shadow_ShadowmapExecute(Shadow_Storage* storage, Mat4 light_space_transform, RenderEnt* entities, size_t entity_count); +GPU_Renderpass* Shadow_RPassCreate(); // Creates the render pass +GPU_Pipeline* Shadow_PipelineCreate(GPU_Renderpass* rpass); // Creates the pipeline +void Shadow_ShadowmapExecute(Shadow_Storage* storage, Mat4 light_space_transform, + RenderEnt* entities, size_t entity_count); void Shadow_RenderDebugQuad(); diff --git a/src/new_render/skybox.h b/src/new_render/skybox.h index 71262fd..465d603 100644 --- a/src/new_render/skybox.h +++ b/src/new_render/skybox.h @@ -9,34 +9,31 @@ #include "render_types.h" typedef struct Skybox { - Mesh cube; - TextureHandle texture; - GPU_Pipeline* pipeline; // "shader" + Mesh cube; + TextureHandle texture; + GPU_Pipeline* pipeline; // "shader" } Skybox; -PUB Skybox Skybox_Create(const char** face_paths, int n); // should always pass n = 6 for now +PUB Skybox Skybox_Create(const char** face_paths, int n); // should always pass n = 6 for now PUB void Skybox_Draw(Skybox* skybox, Camera camera); typedef struct SkyboxUniforms { - TextureHandle cubemap; + TextureHandle cubemap; } SkyboxUniforms; static ShaderDataLayout Skybox_GetLayout(void* data) { - SkyboxUniforms* d = (SkyboxUniforms*)data; // cold cast - bool has_data = data != NULL; - - ShaderBinding b1 = { - .label = "cubeMap", - .vis = VISIBILITY_FRAGMENT, - .kind = BINDING_TEXTURE, - }; - - if (has_data) { - b1.data.texture.handle = d->cubemap; - } - return (ShaderDataLayout) { - .bindings = { b1}, - .binding_count = 1 - }; + SkyboxUniforms* d = (SkyboxUniforms*)data; // cold cast + bool has_data = data != NULL; + + ShaderBinding b1 = { + .label = "cubeMap", + .vis = VISIBILITY_FRAGMENT, + .kind = BINDING_TEXTURE, + }; + + if (has_data) { + b1.data.texture.handle = d->cubemap; + } + return (ShaderDataLayout){ .bindings = { b1 }, .binding_count = 1 }; } diff --git a/src/ral/backends/opengl/backend_opengl.h b/src/ral/backends/opengl/backend_opengl.h index f5ab9c8..fd50830 100644 --- a/src/ral/backends/opengl/backend_opengl.h +++ b/src/ral/backends/opengl/backend_opengl.h @@ -11,20 +11,20 @@ #define OPENGL_DEFAULT_FRAMEBUFFER 0 -typedef struct GPU_Swapchain{ +typedef struct GPU_Swapchain { u32x2 dimensions; -}GPU_Swapchain; +} GPU_Swapchain; typedef struct GPU_Device { } GPU_Device; -typedef struct GPU_PipelineLayout{ +typedef struct GPU_PipelineLayout { void *pad; -}GPU_PipelineLayout; +} GPU_PipelineLayout; typedef struct GPU_Pipeline { u32 shader_id; - GPU_Renderpass* renderpass; + GPU_Renderpass *renderpass; VertexDescription vertex_desc; BufferHandle uniform_bindings[MAX_PIPELINE_UNIFORM_BUFFERS]; u32 uniform_count; @@ -38,7 +38,7 @@ typedef struct GPU_Renderpass { typedef struct GPU_CmdEncoder { GPU_Pipeline *pipeline; -} GPU_CmdEncoder; // Recording +} GPU_CmdEncoder; // Recording typedef struct GPU_CmdBuffer { void *pad; @@ -53,14 +53,14 @@ typedef struct GPU_Buffer { union { u32 vao; u32 ubo_binding_point - }; // Optional - char* name; + }; // Optional + char *name; u64 size; } GPU_Buffer; typedef struct GPU_Texture { u32 id; - void* pad; + void *pad; } GPU_Texture; typedef struct opengl_support { diff --git a/src/ral/backends/opengl/opengl_helpers.h b/src/ral/backends/opengl/opengl_helpers.h index f40bbca..f3059ac 100644 --- a/src/ral/backends/opengl/opengl_helpers.h +++ b/src/ral/backends/opengl/opengl_helpers.h @@ -4,8 +4,8 @@ #include "ral_impl.h" #if defined(CEL_REND_BACKEND_OPENGL) #include "backend_opengl.h" -#include "log.h" #include "file.h" +#include "log.h" #include "ral_types.h" #include <glad/glad.h> diff --git a/src/ral/backends/vulkan/backend_vulkan.h b/src/ral/backends/vulkan/backend_vulkan.h index 790344b..f31bed2 100644 --- a/src/ral/backends/vulkan/backend_vulkan.h +++ b/src/ral/backends/vulkan/backend_vulkan.h @@ -1,10 +1,10 @@ #pragma once #ifdef CEL_REND_BACKEND_VULKAN -#include "ral_impl.h" #include "defines.h" #include "maths_types.h" #include "ral.h" +#include "ral_impl.h" #include "ral_types.h" #include <vulkan/vk_platform.h> @@ -14,31 +14,31 @@ // Provide definitions for RAL structs struct GPU_Swapchain { - VkSwapchainKHR handle; + VkSwapchainKHR handle; }; struct GPU_Device { - VkPhysicalDevice physical_device; - VkDevice logical_device; + VkPhysicalDevice physical_device; + VkDevice logical_device; }; struct GPU_PipelineLayout {}; - struct GPU_Pipeline {}; - struct GPU_Renderpass {}; - struct GPU_CmdEncoder {}; - struct GPU_CmdBuffer {}; - struct GPU_Buffer { - VkBuffer handle; - VkDeviceMemory memory; - u64 size; - }; - struct GPU_Texture { - VkImage handle; - VkDeviceMemory memory; - u64 size; - VkImageView view; - VkSampler sampler; - char* debug_label; - }; +struct GPU_Pipeline {}; +struct GPU_Renderpass {}; +struct GPU_CmdEncoder {}; +struct GPU_CmdBuffer {}; +struct GPU_Buffer { + VkBuffer handle; + VkDeviceMemory memory; + u64 size; +}; +struct GPU_Texture { + VkImage handle; + VkDeviceMemory memory; + u64 size; + VkImageView view; + VkSampler sampler; + char* debug_label; +}; #endif diff --git a/src/ral/ral.h b/src/ral/ral.h index ce3b27d..fdbadd3 100644 --- a/src/ral/ral.h +++ b/src/ral/ral.h @@ -1,5 +1,5 @@ #pragma once -#include "ral_types.h" #include "ral_common.h" -#include "ral_impl.h"
\ No newline at end of file +#include "ral_impl.h" +#include "ral_types.h"
\ No newline at end of file diff --git a/src/ral/ral_common.h b/src/ral/ral_common.h index 98f54ed..63816b1 100644 --- a/src/ral/ral_common.h +++ b/src/ral/ral_common.h @@ -1,9 +1,9 @@ /** * @brief Common functions that don't actually depend on the specific backend -*/ + */ #pragma once -#include "defines.h" #include "buf.h" +#include "defines.h" #include "mem.h" #include "ral_types.h" // #include "ral_impl.h" @@ -13,7 +13,6 @@ #include "backend_opengl.h" #endif - TYPED_POOL(GPU_Buffer, Buffer); TYPED_POOL(GPU_Texture, Texture); TYPED_POOL(GPU_PipelineLayout, PipelineLayout); @@ -39,7 +38,8 @@ struct ResourcePools { typedef struct ResourcePools ResourcePools; void ResourcePools_Init(arena* a, struct ResourcePools* res_pools); -PUB GPU_Renderpass* GPU_GetDefaultRenderpass(); // returns a renderpass that draws directly to default framebuffer with default depth +PUB GPU_Renderpass* GPU_GetDefaultRenderpass(); // returns a renderpass that draws directly to + // default framebuffer with default depth // --- Vertex formats VertexDescription static_3d_vertex_description(); diff --git a/src/ral/ral_impl.h b/src/ral/ral_impl.h index 7b40f28..6676b6c 100644 --- a/src/ral/ral_impl.h +++ b/src/ral/ral_impl.h @@ -1,6 +1,6 @@ /** * @brief -*/ + */ #pragma once #include "buf.h" #include "defines.h" @@ -20,7 +20,8 @@ typedef struct GPU_CmdBuffer GPU_CmdBuffer; // Ready for submission typedef struct GPU_Buffer GPU_Buffer; typedef struct GPU_Texture GPU_Texture; -bool GPU_Backend_Init(const char* window_name, struct GLFWwindow* window, struct ResourcePools* res_pools); +bool GPU_Backend_Init(const char* window_name, struct GLFWwindow* window, + struct ResourcePools* res_pools); void GPU_Backend_Shutdown(); bool GPU_Device_Create(GPU_Device* out_device); @@ -32,7 +33,8 @@ void GPU_Swapchain_Destroy(GPU_Swapchain* swapchain); PUB GPU_Renderpass* GPU_Renderpass_Create(GPU_RenderpassDesc description); PUB void GPU_Renderpass_Destroy(GPU_Renderpass* pass); -PUB GPU_Pipeline* GPU_GraphicsPipeline_Create(GraphicsPipelineDesc description, GPU_Renderpass* renderpass); +PUB GPU_Pipeline* GPU_GraphicsPipeline_Create(GraphicsPipelineDesc description, + GPU_Renderpass* renderpass); PUB void GraphicsPipeline_Destroy(GPU_Pipeline* pipeline); // --- Command buffer @@ -46,7 +48,8 @@ PUB GPU_CmdEncoder* GPU_GetDefaultEncoder(); PUB void GPU_QueueSubmit(GPU_CmdBuffer* cmd_buffer); // --- Buffers -PUB BufferHandle GPU_BufferCreate(u64 size, GPU_BufferType buf_type, GPU_BufferFlags flags, const void* data); +PUB BufferHandle GPU_BufferCreate(u64 size, GPU_BufferType buf_type, GPU_BufferFlags flags, + const void* data); PUB void GPU_BufferDestroy(BufferHandle handle); PUB void GPU_BufferUpload(BufferHandle buffer, size_t n_bytes, const void* data); @@ -58,8 +61,8 @@ PUB void GPU_TextureUpload(TextureHandle handle, size_t n_bytes, const void* dat // --- Data copy commands // TODO: Rename these to reflect current coding style -void encode_buffer_copy(GPU_CmdEncoder* encoder, BufferHandle src, u64 src_offset, - BufferHandle dst, u64 dst_offset, u64 copy_size); +void encode_buffer_copy(GPU_CmdEncoder* encoder, BufferHandle src, u64 src_offset, BufferHandle dst, + u64 dst_offset, u64 copy_size); void buffer_upload_bytes(BufferHandle gpu_buf, bytebuffer cpu_buf, u64 offset, u64 size); void copy_buffer_to_buffer_oneshot(BufferHandle src, u64 src_offset, BufferHandle dst, diff --git a/src/ral/ral_types.h b/src/ral/ral_types.h index bb15d2a..a41cf28 100644 --- a/src/ral/ral_types.h +++ b/src/ral/ral_types.h @@ -1,6 +1,6 @@ #pragma once -#include "defines.h" #include "darray.h" +#include "defines.h" #include "maths_types.h" #include "str.h" @@ -21,10 +21,10 @@ CORE_DEFINE_HANDLE(ShaderHandle); CORE_DEFINE_HANDLE(PipelineLayoutHandle); CORE_DEFINE_HANDLE(PipelineHandle); CORE_DEFINE_HANDLE(RenderpassHandle); -#define INVALID_TEX_HANDLE ((TextureHandle){.raw = 9999999 }) +#define INVALID_TEX_HANDLE ((TextureHandle){ .raw = 9999999 }) // --- Buffers -typedef enum GPU_BufferType{ +typedef enum GPU_BufferType { BUFFER_DEFAULT, // on Vulkan this would be a storage buffer? BUFFER_VERTEX, BUFFER_INDEX, @@ -142,12 +142,12 @@ typedef enum VertexAttribType { } VertexAttribType; typedef struct VertexDescription { - char* debug_label; - const char* attr_names[MAX_VERTEX_ATTRIBUTES]; - VertexAttribType attributes[MAX_VERTEX_ATTRIBUTES]; - u32 attributes_count; - size_t stride; - bool use_full_vertex_size; + char* debug_label; + const char* attr_names[MAX_VERTEX_ATTRIBUTES]; + VertexAttribType attributes[MAX_VERTEX_ATTRIBUTES]; + u32 attributes_count; + size_t stride; + bool use_full_vertex_size; } VertexDescription; // --- Shaders @@ -157,10 +157,10 @@ typedef enum PipelineKind { } PipelineKind; typedef enum ShaderVisibility { - VISIBILITY_VERTEX = 1 << 0, - VISIBILITY_FRAGMENT = 1 << 1, - VISIBILITY_COMPUTE = 1 << 2, -} ShaderVisibility ; + VISIBILITY_VERTEX = 1 << 0, + VISIBILITY_FRAGMENT = 1 << 1, + VISIBILITY_COMPUTE = 1 << 2, +} ShaderVisibility; typedef struct ShaderDesc { const char* debug_name; @@ -171,36 +171,43 @@ typedef struct ShaderDesc { } ShaderDesc; typedef enum ShaderBindingKind { - BINDING_BYTES, - BINDING_BUFFER, - BINDING_BUFFER_ARRAY, - BINDING_TEXTURE, - BINDING_TEXTURE_ARRAY, - BINDING_SAMPLER, - BINDING_COUNT + BINDING_BYTES, + BINDING_BUFFER, + BINDING_BUFFER_ARRAY, + BINDING_TEXTURE, + BINDING_TEXTURE_ARRAY, + BINDING_SAMPLER, + BINDING_COUNT } ShaderBindingKind; typedef struct ShaderBinding { - const char* label; - ShaderBindingKind kind; - ShaderVisibility vis; - union { - struct { u32 size; void* data; } bytes; - struct { BufferHandle handle; } buffer; - struct { TextureHandle handle; } texture; - } data; + const char* label; + ShaderBindingKind kind; + ShaderVisibility vis; + union { + struct { + u32 size; + void* data; + } bytes; + struct { + BufferHandle handle; + } buffer; + struct { + TextureHandle handle; + } texture; + } data; } ShaderBinding; typedef struct ShaderDataLayout { - ShaderBinding bindings[MAX_SHADER_BINDINGS]; - size_t binding_count; + ShaderBinding bindings[MAX_SHADER_BINDINGS]; + size_t binding_count; } ShaderDataLayout; typedef ShaderDataLayout (*FN_GetBindingLayout)(void* data); typedef struct ShaderData { - FN_GetBindingLayout get_layout; - void* data; + FN_GetBindingLayout get_layout; + void* data; } ShaderData; // --- Miscellaneous @@ -236,7 +243,7 @@ typedef struct GraphicsPipelineDesc { typedef struct GPU_RenderpassDesc { bool default_framebuffer; bool has_color_target; - TextureHandle color_target; // for now only support one + TextureHandle color_target; // for now only support one bool has_depth_stencil; - TextureHandle depth_stencil; + TextureHandle depth_stencil; } GPU_RenderpassDesc; diff --git a/src/render/backends/opengl/backend_opengl.h b/src/render/backends/opengl/backend_opengl.h index 8b88cf8..73a19ed 100644 --- a/src/render/backends/opengl/backend_opengl.h +++ b/src/render/backends/opengl/backend_opengl.h @@ -21,7 +21,7 @@ typedef struct gpu_pipeline_layout { } gpu_pipeline_layout; typedef struct gpu_pipeline { u32 shader_id; - gpu_renderpass* renderpass; + gpu_renderpass *renderpass; vertex_description vertex_desc; buffer_handle uniform_bindings[MAX_PIPELINE_UNIFORM_BUFFERS]; u32 uniform_count; @@ -47,13 +47,13 @@ typedef struct gpu_buffer { union { u32 vao; u32 ubo_binding_point - }; // Optional - char* name; + }; // Optional + char *name; u64 size; } gpu_buffer; typedef struct gpu_texture { u32 id; - void* pad; + void *pad; } gpu_texture; typedef struct opengl_support { diff --git a/src/render/builtin_materials.h b/src/render/builtin_materials.h index f2db5f4..b15e62e 100644 --- a/src/render/builtin_materials.h +++ b/src/render/builtin_materials.h @@ -82,7 +82,7 @@ static shader_data_layout pbr_params_shader_layout(void* data) { .data = { .bytes = { .size = sizeof(pbr_params_light_uniforms) } } }; if (has_data) { - // printf("Size %d \n", b3.data.bytes.size); + // printf("Size %d \n", b3.data.bytes.size); b1.data.bytes.data = &d->mvp_matrices; b2.data.bytes.data = &d->material; /* d->lights.viewPos = vec3(0, 1, 0); */ @@ -127,16 +127,14 @@ static shader_data_layout pbr_textured_shader_layout(void* data) { .stores_data = has_data, .data = { .bytes = { .size = sizeof(pbr_params_light_uniforms) } } }; - shader_binding b3 = {.label = "albedoMap", + shader_binding b3 = { .label = "albedoMap", .type = SHADER_BINDING_TEXTURE, .stores_data = has_data }; - shader_binding b4 = {.label = "metallicRoughnessMap", + shader_binding b4 = { .label = "metallicRoughnessMap", .type = SHADER_BINDING_TEXTURE, .stores_data = has_data }; - shader_binding b5 = {.label = "aoMap", - .type = SHADER_BINDING_TEXTURE, - .stores_data = has_data }; - shader_binding b6 = {.label = "normalMap", + shader_binding b5 = { .label = "aoMap", .type = SHADER_BINDING_TEXTURE, .stores_data = has_data }; + shader_binding b6 = { .label = "normalMap", .type = SHADER_BINDING_TEXTURE, .stores_data = has_data }; @@ -149,6 +147,7 @@ static shader_data_layout pbr_textured_shader_layout(void* data) { b6.data.texture.handle = d->textures.normal_tex; } - return (shader_data_layout){ .name = "pbr_params", .bindings = { b1, b2, b3, b4, b5, b6 }, .bindings_count = 6 - }; + return (shader_data_layout){ .name = "pbr_params", + .bindings = { b1, b2, b3, b4, b5, b6 }, + .bindings_count = 6 }; } diff --git a/src/render/ral_types.h b/src/render/ral_types.h index be95902..19f6ea3 100644 --- a/src/render/ral_types.h +++ b/src/render/ral_types.h @@ -26,7 +26,6 @@ CORE_DEFINE_HANDLE(pipeline_handle); CORE_DEFINE_HANDLE(renderpass_handle); #define ABSENT_MODEL_HANDLE 999999999 - // --- Shaders & Bindings typedef enum shader_visibility { @@ -85,7 +84,6 @@ typedef struct shader_binding { } data; /** @brief can store any kind of data that we can bind to a shader / descriptor set */ } shader_binding; - void print_shader_binding(shader_binding b); /** @brief A list of bindings that describe what data a shader / pipeline expects diff --git a/src/render/render.h b/src/render/render.h index f0e9a64..313b14c 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -69,7 +69,6 @@ texture_handle texture_data_upload(texture_data data, bool free_on_upload); material pbr_material_load(char* albedo_path, char* normal_path, bool metal_roughness_combined, char* metallic_path, char* roughness_map, char* ao_map); - /** * @brief Creates buffers and returns a struct that holds handles to our resources * @@ -79,7 +78,7 @@ material pbr_material_load(char* albedo_path, char* normal_path, bool metal_roug * @return mesh */ mesh mesh_create(geometry_data* geometry, bool free_on_upload); -void mesh_delete(mesh* mesh); // TODO +void mesh_delete(mesh* mesh); // TODO void draw_mesh(mesh* mesh, mat4* model, camera* cam); diff --git a/src/render/renderpasses.h b/src/render/renderpasses.h index 5a5ffee..1ceea6c 100644 --- a/src/render/renderpasses.h +++ b/src/render/renderpasses.h @@ -23,7 +23,6 @@ gpu_renderpass* renderpass_blinn_phong_create(); void renderpass_blinn_phong_execute(gpu_renderpass* pass, render_entity* entities, size_t entity_count); - typedef struct ren_shadowmaps { u32 width; u32 height; @@ -41,11 +40,11 @@ typedef struct lightspace_tf_uniform { } lightspace_tf_uniform; typedef struct debug_quad_uniform { - texture_handle depthMap; + texture_handle depthMap; } debug_quad_uniform; shader_data_layout model_uniform_layout(void* data); -shader_data_layout lightspace_uniform_layout(void* data); +shader_data_layout lightspace_uniform_layout(void* data); shader_data_layout debug_quad_layout(void* data); void ren_shadowmaps_init(ren_shadowmaps* storage); @@ -53,4 +52,5 @@ void ren_shadowmaps_init(ren_shadowmaps* storage); gpu_renderpass* shadowmaps_renderpass_create(); gpu_pipeline* shadowmaps_pipeline_create(gpu_renderpass* rpass); -void renderpass_shadowmap_execute(gpu_renderpass* pass, render_entity* entities, size_t entity_count); +void renderpass_shadowmap_execute(gpu_renderpass* pass, render_entity* entities, + size_t entity_count); diff --git a/src/std/containers/container_utils.h b/src/std/containers/container_utils.h index 39906c3..e1d164c 100644 --- a/src/std/containers/container_utils.h +++ b/src/std/containers/container_utils.h @@ -1,18 +1,17 @@ /** * @file container_utils.h * @author your name (you@domain.com) - * @brief + * @brief * @version 0.1 * @date 2024-06-19 - * + * * @copyright Copyright (c) 2024 - * + * */ #pragma once typedef struct generic_iterator { - } generic_iterator; typedef void* (*iterator_next_item)(void* iterator);
\ No newline at end of file diff --git a/src/std/containers/darray.h b/src/std/containers/darray.h index b3dbd06..ebb5795 100644 --- a/src/std/containers/darray.h +++ b/src/std/containers/darray.h @@ -86,7 +86,7 @@ size_t new_capacity = \ d->capacity > 0 ? d->capacity * DARRAY_RESIZE_FACTOR : DARRAY_DEFAULT_CAPACITY; \ T *resized = Type##_darray_resize(d, new_capacity); \ - (void)resized; \ + (void)resized; \ } \ \ d->data[d->len] = value; \ @@ -98,7 +98,7 @@ size_t new_capacity = \ d->capacity > 0 ? d->capacity * DARRAY_RESIZE_FACTOR : DARRAY_DEFAULT_CAPACITY; \ T *resized = Type##_darray_resize(d, new_capacity); \ - (void)resized; \ + (void)resized; \ } \ \ T *place = d->data + d->len; \ @@ -118,7 +118,7 @@ size_t new_capacity = \ d->capacity > 0 ? d->capacity * DARRAY_RESIZE_FACTOR : DARRAY_DEFAULT_CAPACITY; \ T *resized = Type##_darray_resize(d, new_capacity); \ - (void)resized; \ + (void)resized; \ } \ \ /* shift existing data after index */ \ diff --git a/src/std/containers/hashmap.h b/src/std/containers/hashmap.h index 64a5bf7..95c1c6b 100644 --- a/src/std/containers/hashmap.h +++ b/src/std/containers/hashmap.h @@ -9,7 +9,6 @@ * */ - typedef struct hashmap hashmap; /* @@ -18,7 +17,7 @@ Example usage init hashmap insert (string, material) get (string) -> material_opt or material* ? - + */ void hashmap_init(hashmap* map); diff --git a/src/std/containers/hashset.h b/src/std/containers/hashset.h index 978ec00..7f87213 100644 --- a/src/std/containers/hashset.h +++ b/src/std/containers/hashset.h @@ -13,7 +13,7 @@ typedef struct hashset hashset; -/** @brief Describes a function that will take a pointer to a datatype (e.g. a u64 or a struct) +/** @brief Describes a function that will take a pointer to a datatype (e.g. a u64 or a struct) and return a hashed key. */ typedef uint64_t (*hash_item)(void* item); diff --git a/src/std/mem.h b/src/std/mem.h index 789cba3..c9346cc 100644 --- a/src/std/mem.h +++ b/src/std/mem.h @@ -71,21 +71,21 @@ void void_pool_dealloc(void_pool* pool, u32 raw_handle); // TODO: macro that lets us specialise /* typedef struct Name##_handle Name##_handle; \ */ -#define TYPED_POOL(T, Name) \ - typedef struct Name##_pool { \ - void_pool inner; \ - } Name##_pool; \ - \ - static Name##_pool Name##_pool_create(arena* a, u64 cap, u64 entry_size) { \ - void_pool p = void_pool_create(a, "\"" #Name "\"", cap, entry_size); \ - return (Name##_pool){ .inner = p }; \ - } \ +#define TYPED_POOL(T, Name) \ + typedef struct Name##_pool { \ + void_pool inner; \ + } Name##_pool; \ + \ + static Name##_pool Name##_pool_create(arena* a, u64 cap, u64 entry_size) { \ + void_pool p = void_pool_create(a, "\"" #Name "\"", cap, entry_size); \ + return (Name##_pool){ .inner = p }; \ + } \ static inline T* Name##_pool_get(Name##_pool* pool, Name##Handle handle) { \ - return (T*)void_pool_get(&pool->inner, handle.raw); \ - } \ + return (T*)void_pool_get(&pool->inner, handle.raw); \ + } \ static inline T* Name##_pool_alloc(Name##_pool* pool, Name##Handle* out_handle) { \ - return (T*)void_pool_alloc(&pool->inner, &out_handle->raw); \ - } \ + return (T*)void_pool_alloc(&pool->inner, &out_handle->raw); \ + } \ static inline void Name##_pool_dealloc(Name##_pool* pool, Name##Handle handle) { \ - void_pool_dealloc(&pool->inner, handle.raw); \ + void_pool_dealloc(&pool->inner, handle.raw); \ }\ diff --git a/src/systems/input.h b/src/systems/input.h index 11c40ea..f928ed1 100644 --- a/src/systems/input.h +++ b/src/systems/input.h @@ -39,4 +39,4 @@ bool key_just_released(keycode key); bool Input_Init(Input_State *input, struct GLFWwindow *window); void Input_Shutdown(Input_State *input); -void Input_Update(Input_State *state); // must be run once per main loop +void Input_Update(Input_State *state); // must be run once per main loop diff --git a/src/systems/terrain.h b/src/systems/terrain.h index 4e709ed..2d6ff4a 100644 --- a/src/systems/terrain.h +++ b/src/systems/terrain.h @@ -30,14 +30,15 @@ typedef struct Terrain_Storage Terrain_Storage; // --- Public API PUB bool Terrain_Init(Terrain_Storage* storage); PUB void Terrain_Shutdown(Terrain_Storage* storage); -PUB void Terrain_Draw(Terrain_Storage* storage); // NOTE: For now it renders directly to main framebuffer +PUB void Terrain_Draw( + Terrain_Storage* storage); // NOTE: For now it renders directly to main framebuffer /** @brief Sets the active heightmap to be rendered and collided against. */ PUB void Terrain_LoadHeightmap(Heightmap hmap, bool free_on_upload); PUB Heightmap Heightmap_FromImage(Str8 filepath); PUB Heightmap Heightmap_FromPerlin(/* TODO: perlin noise generation parameters */); -PUB bool Terrain_IsActive(); // checks whether we have a loaded heightmap and it's being rendered +PUB bool Terrain_IsActive(); // checks whether we have a loaded heightmap and it's being rendered // --- Internal diff --git a/src/transform_hierarchy.h b/src/transform_hierarchy.h index 808baab..142ea99 100644 --- a/src/transform_hierarchy.h +++ b/src/transform_hierarchy.h @@ -39,7 +39,8 @@ TransformHierarchy* TransformHierarchy_Create(); // // --- Main usecase -// /** @brief Updates matrices of any invalidated nodes based on the `is_dirty` flag inside `transform` +// /** @brief Updates matrices of any invalidated nodes based on the `is_dirty` flag inside +// `transform` // */ // void transform_hierarchy_propagate_transforms(transform_hierarchy* tfh); @@ -58,15 +59,16 @@ TransformHierarchy* TransformHierarchy_Create(); // /** // * @brief Perform a depth-first search traversal starting from `start_node`. // * @param start_node The starting node of the traversal. -// * @param visit_node The function to call for each node visited. The callback should return false to -// stop the traversal early. -// * @param is_pre_order Indicates whether to do pre-order or post-order traversal i.e. when to call -// the `visit_node` function. -// * @param ctx_data An optional pointer to data that is be passed on each call to `visit_node`. Can -// be used to carry additional information or context. +// * @param visit_node The function to call for each node visited. The callback should return false +// to stop the traversal early. +// * @param is_pre_order Indicates whether to do pre-order or post-order traversal i.e. when to +// call the `visit_node` function. +// * @param ctx_data An optional pointer to data that is be passed on each call to `visit_node`. +// Can be used to carry additional information or context. // * // * @note The main use-cases are: -// 1. traversing the whole tree to update cached 4x4 affine transform matrices (post-order) +// 1. traversing the whole tree to update cached 4x4 affine transform matrices +// (post-order) // 2. freeing child nodes after deleting a node in the tree (post-order) // 3. debug pretty printing the whole tree (post-order) // */ |