diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-03-31 02:34:19 +1100 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-03-31 02:34:19 +1100 |
commit | 6463c6c1090644438d8449f7ae1a152a4a196123 (patch) | |
tree | a312ff598c85af1a2e9dd65c0fadc08a2891b6ad /src | |
parent | c4bf1916fe219324e14384fc938e767daeab26c9 (diff) |
more api design
Diffstat (limited to 'src')
-rw-r--r-- | src/maths/maths.h | 23 | ||||
-rw-r--r-- | src/maths/maths_types.h | 6 | ||||
-rw-r--r-- | src/maths/primitives.h | 2 | ||||
-rw-r--r-- | src/renderer/backends/backend_vulkan.c | 1 | ||||
-rw-r--r-- | src/renderer/cleanroom/types.h | 88 |
5 files changed, 91 insertions, 29 deletions
diff --git a/src/maths/maths.h b/src/maths/maths.h index 9206c5c..6fa2f9b 100644 --- a/src/maths/maths.h +++ b/src/maths/maths.h @@ -134,20 +134,21 @@ static inline mat4 mat4_mult(mat4 lhs, mat4 rhs) { #if defined(CEL_REND_BACKEND_VULKAN) /** @brief Creates a perspective projection matrix compatible with Vulkan */ -static inline mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_clip, f32 far_clip) { - // near_clip *= -1.0; - // far_clip *= -1.0; - - f32 half_tan_fov = tanf(fov_radians * 0.5f); - mat4 out_matrix = { .data = { 0 } }; - - out_matrix.data[0] = 1.0f / (aspect_ratio * half_tan_fov); - out_matrix.data[5] = -1.0f / half_tan_fov; // Flip Y-axis for Vulkan - out_matrix.data[10] = -((far_clip + near_clip) / (far_clip - near_clip)); +static inline mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_clip, + f32 far_clip) { + // near_clip *= -1.0; + // far_clip *= -1.0; + + f32 half_tan_fov = tanf(fov_radians * 0.5f); + mat4 out_matrix = { .data = { 0 } }; + + out_matrix.data[0] = 1.0f / (aspect_ratio * half_tan_fov); + out_matrix.data[5] = -1.0f / half_tan_fov; // Flip Y-axis for Vulkan + out_matrix.data[10] = -((far_clip + near_clip) / (far_clip - near_clip)); out_matrix.data[11] = -1.0f; out_matrix.data[14] = -((2.0f * far_clip * near_clip) / (far_clip - near_clip)); - return out_matrix; + return out_matrix; } #else /** @brief Creates a perspective projection matrix */ diff --git a/src/maths/maths_types.h b/src/maths/maths_types.h index ba741b9..6d38fc7 100644 --- a/src/maths/maths_types.h +++ b/src/maths/maths_types.h @@ -60,4 +60,8 @@ typedef struct transform { quat rotation; f32 scale; bool is_dirty; -} transform;
\ No newline at end of file +} transform; + +typedef struct vec4i { + i32 x, y, z, w; +} vec4i;
\ No newline at end of file diff --git a/src/maths/primitives.h b/src/maths/primitives.h index 60d36da..fd798c1 100644 --- a/src/maths/primitives.h +++ b/src/maths/primitives.h @@ -55,7 +55,7 @@ static mesh prim_cube_mesh_create() { /** @brief create a new model with the shape of a cube */ static model_handle prim_cube_new(core* core) { - model model = { 0 }; + model model = { 0 }; mesh cube = prim_cube_mesh_create(); mesh_darray_push(model.meshes, cube); diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c index f83b271..1657594 100644 --- a/src/renderer/backends/backend_vulkan.c +++ b/src/renderer/backends/backend_vulkan.c @@ -103,6 +103,7 @@ typedef struct vulkan_swapchain { vulkan_framebuffer_darray* framebuffers; } vulkan_swapchain; +// overengineered typedef enum vulkan_command_buffer_state { COMMAND_BUFFER_STATE_READY, COMMAND_BUFFER_STATE_IN_RENDER_PASS, diff --git a/src/renderer/cleanroom/types.h b/src/renderer/cleanroom/types.h index 0a26120..3f62cab 100644 --- a/src/renderer/cleanroom/types.h +++ b/src/renderer/cleanroom/types.h @@ -1,6 +1,7 @@ #pragma once #include "darray.h" #include "defines.h" +#include "maths_types.h" #include "str.h" typedef int texture_handle; @@ -14,9 +15,9 @@ typedef struct texture_desc { // u32x2 extents; } texture_desc; -/* +/* - render_types.h - - ral_types.h + - ral_types.h - ral.h - render.h ? */ @@ -49,15 +50,11 @@ typedef enum gpu_texture_format { typedef struct mesh mesh; typedef struct model model; typedef struct model pbr_material; -typedef struct model bp_material; // blinn-phong +typedef struct model bp_material; // blinn-phong #include "maths_types.h" -typedef enum vertex_format { - VERTEX_STATIC_3D, - VERTEX_SPRITE, - VERTEX_COUNT -} vertex_format; +typedef enum vertex_format { VERTEX_STATIC_3D, VERTEX_SPRITE, VERTEX_COUNT } vertex_format; typedef union vertex { struct { @@ -73,7 +70,14 @@ typedef union vertex { vec2 tex_coords; } sprite; - // TODO: animated 3d + struct { + vec3 position; + vec4 colour; + vec2 tex_coords; + vec3 normal; + vec4i bone_ids; // Integer vector for bone IDs + vec4 bone_weights; // Weight of each bone's influence + } animated_3d; /** @brief vertex format for skeletal (animated) geometry in 3D */ } vertex; KITC_DECL_TYPED_ARRAY(vertex) @@ -90,42 +94,93 @@ typedef struct mesh { buffer_handle index_buffer; u32 index_count; bool has_indices; - geometry_data* vertices; // NULL means it has been freed + geometry_data* vertices; // NULL means it has been freed } mesh; +/* Hot reloading: +C side - reload_model(): + - load model from disk using existing loader + - remove from transform graph so it isnt tried to be drawn + - + +*/ + typedef struct model { str8 debug_name; mesh* meshes; u32 mesh_count; } model; +// ? How to tie together materials and shaders + // Three registers // 1. low level graphics api calls "ral" // 2. higher level render calls // 3. simplified immediate mode API +// 3 - you don't need to know how the renderer works at all +// 2 - you need to know how the overall renderer is designed +// 1 - you need to understand graphics API specifics + /* render.h */ // frontend -- these can be called from say a loop in an example, or via FFI texture_handle texture_create(const char* debug_name, texture_desc description, const u8* data); void texture_data_upload(texture_handle texture); buffer_handle buffer_create(const char* debug_name, u64 size); +bool buffer_destroy(buffer_handle buffer); // models and meshes are implemented **in terms of the above** mesh mesh_create(geometry_data* geometry); -model_handle model_load(const char* filepath); +model_handle model_load(const char* debug_name, const char* filepath); /* ral.h */ + +enum pipeline_type { + GRAPHICS, + COMPUTE, +} pipeline_type; + // backend -- these are not seen by the higher-level code typedef struct gpu_swapchain gpu_swapchain; typedef struct gpu_device gpu_device; typedef struct gpu_pipeline gpu_pipeline; +typedef struct gpu_cmd_encoder gpu_cmd_encoder; +typedef struct gpu_cmd_buffer gpu_cmd_buffer; // Ready for submission -void gpu_texture_init(); -void gpu_texture_upload(); -void gpu_buffer_init(); +void gpu_cmd_encoder_begin(); +void gpu_cmd_encoder_begin_render(); +void gpu_cmd_encoder_begin_compute(); + +/* Actual commands that we can encode */ +void encode_buffer_copy(gpu_cmd_encoder* encoder, buffer_handle src, u64 src_offset, + buffer_handle dst, u64 dst_offset, u64 copy_size); +void encode_clear_buffer(gpu_cmd_encoder* encoder, buffer_handle buf); +// render pass +void encode_set_vertex_buffer(gpu_cmd_encoder* encoder, buffer_handle buf); +void encode_set_index_buffer(gpu_cmd_encoder* encoder, buffer_handle buf); +void encode_draw_indexed(gpu_cmd_encoder* encoder, u64 index_count, u64* indices); + +// FUTURE: compute passes + +/** @brief Finish recording and return a command buffer that can be submitted to a queue */ +gpu_cmd_buffer gpu_cmd_encoder_finish(gpu_cmd_encoder* encoder); + +void gpu_queue_submit(gpu_cmd_buffer* buffer); + +// Buffers +void gpu_buffer_create(u64 size); +void gpu_buffer_destroy(buffer_handle buffer); void gpu_buffer_upload(); -void gpu_buffer_bind(); +void gpu_buffer_bind(buffer_handle buffer); + +// Textures +void gpu_texture_create(); +void gpu_texture_destroy(); +void gpu_texture_upload(); + +// Samplers +void gpu_sampler_create(); // command buffer gubbins @@ -135,7 +190,8 @@ void gpu_buffer_bind(); void imm_draw_cuboid(); void imm_draw_sphere(vec3 pos, f32 radius, vec4 colour); void imm_draw_camera_frustum(); -static void imm_draw_model(const char* model_filepath); // tracks internally whether the model is loaded +static void imm_draw_model( + const char* model_filepath); // tracks internally whether the model is loaded static void imm_draw_model(const char* model_filepath) { // check that model is loaded |