diff options
Diffstat (limited to 'src/renderer/cleanroom')
-rw-r--r-- | src/renderer/cleanroom/ral.h | 86 | ||||
-rw-r--r-- | src/renderer/cleanroom/types.h | 130 |
2 files changed, 3 insertions, 213 deletions
diff --git a/src/renderer/cleanroom/ral.h b/src/renderer/cleanroom/ral.h deleted file mode 100644 index 15eb027..0000000 --- a/src/renderer/cleanroom/ral.h +++ /dev/null @@ -1,86 +0,0 @@ -/** - * @file ral.h - * @author your name (you@domain.com) - * @brief Render Abstraction Layer - * @details API that a graphics backend *must* implement - * @version 0.1 - * @date 2024-03-31 - * - * @copyright Copyright (c) 2024 - * - */ -#pragma once - -#include "cleanroom/types.h" -#include "defines.h" - -// Forward declare structs -typedef struct gpu_swapchain gpu_swapchain; -typedef struct gpu_device gpu_device; -typedef struct gpu_pipeline gpu_pipeline; -typedef struct gpu_renderpass gpu_renderpass; -typedef struct gpu_cmd_encoder gpu_cmd_encoder; // Recording -typedef struct gpu_cmd_buffer gpu_cmd_buffer; // Ready for submission - -enum pipeline_kind { - GRAPHICS, - COMPUTE, -} pipeline_kind; - -typedef struct shader_desc { - const char* debug_name; - str8 filepath; // where it came from - str8 glsl; // contents -} shader_desc; - -struct pipeline_desc { - shader_desc vs; /** @brief Vertex shader stage */ - shader_desc fs; /** @brief Fragment shader stage */ -}; - -// lifecycle functions -gpu_device* gpu_device_create(); -void gpu_device_destroy(); - -gpu_renderpass* gpu_renderpass_create(); -void gpu_renderpass_destroy(gpu_renderpass* pass); - -gpu_pipeline* gpu_pipeline_create(enum pipeline_kind kind, struct pipeline_desc description); -void gpu_pipeline_destroy(gpu_pipeline* pipeline); - -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); -void encode_set_pipeline(gpu_cmd_encoder* encoder, gpu_pipeline* pipeline); -// 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_set_bind_group(); -void encode_draw(gpu_cmd_encoder* encoder); -void encode_draw_indexed(gpu_cmd_encoder* encoder, u64 index_count); - -// 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(buffer_handle buffer); - -// Textures -void gpu_texture_create(); -void gpu_texture_destroy(); -void gpu_texture_upload(); - -// Samplers -void gpu_sampler_create();
\ No newline at end of file diff --git a/src/renderer/cleanroom/types.h b/src/renderer/cleanroom/types.h index 7a6cfbd..0a28b1c 100644 --- a/src/renderer/cleanroom/types.h +++ b/src/renderer/cleanroom/types.h @@ -3,22 +3,11 @@ #include "defines.h" #include "maths_types.h" #include "str.h" +#include "render_types.h" -CORE_DEFINE_HANDLE(buffer_handle); -CORE_DEFINE_HANDLE(texture_handle); -CORE_DEFINE_HANDLE(sampler_handle); -CORE_DEFINE_HANDLE(shader_handle); -CORE_DEFINE_HANDLE(model_handle); +// typedef struct transform_hierarchy { +// } transform_hierarchy; -typedef struct transform_hierarchy { -} transform_hierarchy; - -/** @brief Texture Description - used by texture creation functions */ -typedef struct texture_desc { - // gpu_texture_type tex_type; - // gpu_texture_format format; - // u32x2 extents; -} texture_desc; /* - render_types.h @@ -27,102 +16,10 @@ typedef struct texture_desc { - render.h ? */ -// gpu types -typedef enum gpu_primitive_topology { - CEL_PRIMITIVE_TOPOLOGY_POINT, - CEL_PRIMITIVE_TOPOLOGY_LINE, - CEL_PRIMITIVE_TOPOLOGY_LINE_STRIP, - CEL_PRIMITIVE_TOPOLOGY_TRIANGLE, - CEL_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, - CEL_PRIMITIVE_TOPOLOGY_COUNT -} cel_primitive_topology; - -typedef enum gpu_texture_type { - CEL_TEXTURE_TYPE_2D, - CEL_TEXTURE_TYPE_3D, - CEL_TEXTURE_TYPE_2D_ARRAY, - CEL_TEXTURE_TYPE_CUBE_MAP, - CEL_TEXTURE_TYPE_COUNT -} gpu_texture_type; - -typedef enum gpu_texture_format { - CEL_TEXTURE_FORMAT_8_8_8_8_RGBA_UNORM, - CEL_TEXTURE_FORMAT_DEPTH_DEFAULT, - CEL_TEXTURE_FORMAT_COUNT -} gpu_texture_format; - /* render_types */ typedef struct model pbr_material; typedef struct model bp_material; // blinn-phong -#include "maths_types.h" - -typedef enum vertex_format { - VERTEX_STATIC_3D, - VERTEX_SPRITE, - VERTEX_SKINNED, - VERTEX_COUNT -} vertex_format; - -typedef union vertex { - struct { - vec3 position; - vec4 colour; - vec2 tex_coords; - vec3 normal; - } static_3d; /** @brief standard vertex format for static geometry in 3D */ - - struct { - vec2 position; - vec4 colour; - vec2 tex_coords; - } sprite; /** @brief vertex format for 2D sprites or quads */ - - 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 - } skinned_3d; /** @brief vertex format for skeletal (animated) geometry in 3D */ -} vertex; - -KITC_DECL_TYPED_ARRAY(vertex) -KITC_DECL_TYPED_ARRAY(u32) - -typedef struct geometry_data { - vertex_format format; - vertex_darray vertices; - bool has_indices; - u32_darray indices; - vec3 colour; /** Optional: set vertex colours */ -} geometry_data; - -void geo_set_vertex_colours(geometry_data* geo, vec4 colour); - -typedef struct mesh { - buffer_handle vertex_buffer; - buffer_handle index_buffer; - u32 index_count; - bool has_indices; - 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 - - - -*/ - -// TODO: move to some sort of render layer (not inside the abstraction layer) -typedef struct model { - str8 debug_name; - mesh* meshes; - u32 mesh_count; -} model; // ? How to tie together materials and shaders @@ -149,27 +46,6 @@ typedef struct model { /* --- Renderer layer */ /* render.h */ -typedef struct renderer { - void* backend_context; -} renderer; - -bool renderer_init(renderer* ren); -void renderer_shutdown(renderer* ren); - -// 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); - -// Frontend Resources -void texture_data_upload(texture_handle texture); -buffer_handle buffer_create(const char* debug_name, u64 size); -bool buffer_destroy(buffer_handle buffer); -sampler_handle sampler_create(); - -void shader_hot_reload(const char* filepath); - -// models and meshes are implemented **in terms of the above** -mesh mesh_create(geometry_data* geometry); -model_handle model_load(const char* debug_name, const char* filepath); // Drawing |