From fedba7ff68924ff50022405fc9103a5acf7013fe Mon Sep 17 00:00:00 2001 From: Omniscient Date: Thu, 11 Jul 2024 21:43:06 +1000 Subject: wip --- src/core/core.c | 36 +++++++++++++++--------------------- src/core/core.h | 20 +++----------------- src/new_render/immdraw.h | 14 ++++++++++++++ src/new_render/render.c | 37 +++++++++++++++++++++++++++++++++++++ src/new_render/render.h | 12 ++++++++++++ src/new_render/render_types.h | 4 ++++ src/new_render/shadows.h | 1 - src/new_render/skybox.h | 6 ++++++ src/ral/ral_types.h | 3 +++ src/systems/input.h | 13 +++++++------ src/ui/ui.h | 13 +++++++++++++ 11 files changed, 114 insertions(+), 45 deletions(-) create mode 100644 src/new_render/immdraw.h create mode 100644 src/new_render/render.c create mode 100644 src/new_render/skybox.h create mode 100644 src/ui/ui.h (limited to 'src') diff --git a/src/core/core.c b/src/core/core.c index 1d8fe91..a022366 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -10,48 +10,42 @@ #include "render.h" #include "render_types.h" #include "scene.h" -// #include "threadpool.h" #define SCR_WIDTH 1000 #define SCR_HEIGHT 1000 -core g_core; /** @brief global `core` that other files can use */ +Core g_core; /** @brief global `Core` that other files can use */ -inline core* get_global_core() { return &g_core; } + +struct Core { + const char* app_name; + Renderer renderer; + input_state input; + model_pool models; +}; + +/** @brief Gets the global `Core` singleton */ +inline Core* GetCore() { return &g_core; } void core_bringup() { INFO("Initiate Core bringup"); - renderer_config conf = { .window_name = { "Celeritas Engine Core" }, + RendererConfig conf = { .window_name = { "Celeritas Engine Core" }, .scr_width = SCR_WIDTH, .scr_height = SCR_HEIGHT, .clear_colour = (vec3){ .08, .08, .1 } }; - g_core.renderer.config = conf; - g_core.renderer.backend_context = NULL; - // threadpool_create(&c->threadpool, 6, 256); - // threadpool_set_ctx(&c->threadpool, c); // Gives the threadpool access to the core + g_core.renderer.backend_context = NULL; // initialise all subsystems - if (!renderer_init(&g_core.renderer)) { + if (!Renderer_Init(conf, &g_core.renderer)) { // FATAL("Failed to start renderer"); ERROR_EXIT("Failed to start renderer\n"); } - if (!input_system_init(&g_core.input, g_core.renderer.window)) { + if (!Input_Init(&g_core.input, g_core.renderer.window)) { // the input system needs the glfw window which is created by the renderer // hence the order here is important - FATAL("Failed to start input system"); ERROR_EXIT("Failed to start input system\n"); } - /* - if (!text_system_init(&c->text)) { - // FATAL("Failed to start text system"); - ERROR_EXIT("Failed to start text system\n"); - } - if (!screenspace_2d_init(&c->screenspace)) { - // FATAL("Failed to start screenspace 2d plugin"); - ERROR_EXIT("Failed to start screenspace 2d plugin\n"); - } - */ size_t model_data_max = 1024 * 1024 * 1024; arena model_arena = arena_create(malloc(model_data_max), model_data_max); diff --git a/src/core/core.h b/src/core/core.h index 89702fd..469f8d1 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -6,23 +6,9 @@ #include "screenspace.h" #include "terrain.h" #include "text.h" -// #include "threadpool.h" - -typedef struct core { - const char* app_name; - // foundations - renderer renderer; - // threadpool threadpool; - // systems - input_state input; - text_system_state text; - terrain_state terrain; - screenspace_state screenspace; - // data storage - scene default_scene; - model_pool models; - // model_darray* models; -} core; + +typedef struct Core Core; + core* get_global_core(); diff --git a/src/new_render/immdraw.h b/src/new_render/immdraw.h new file mode 100644 index 0000000..c2c3a24 --- /dev/null +++ b/src/new_render/immdraw.h @@ -0,0 +1,14 @@ +/** + * @brief Immediate-mode drawing APIs + */ + +#pragma once +#include "defines.h" +#include "maths_types.h" + +// --- Public API + + +void Immdraw_Cuboid(Transform tf); +void Immdraw_Sphere(Transform tf, f32 size); +void Immdraw_TransformGizmo(Transform tf, f32 size); diff --git a/src/new_render/render.c b/src/new_render/render.c new file mode 100644 index 0000000..455b730 --- /dev/null +++ b/src/new_render/render.c @@ -0,0 +1,37 @@ +/** + * @brief + */ + +#include "render.h" +#include "maths_types.h" +#include "shadow.h" + +struct RendererConfig { + char window_name[256]; + u32 scr_width, scr_height; + Vec3 clear_colour; +}; + +struct Renderer { + struct GLFWwindow* window; + RendererConfig config; + GPU_Device device; + GPU_Swapchain swapchain; + GPU_Renderpass* default_renderpass; + bool frame_aborted; + RenderScene scene; + PBR_Storage pbr; + Shadow_Storage shadows; + Terrain_Storage terrain; + Text_Storage text; + ResourcePools* resource_pools; +}; + +bool Renderer_Init(RendererConfig config, Renderer* renderer) { + // set the RAL backend up + + // create our renderpasses + Shadow_Init(&renderer->shadows); + + return true; +} diff --git a/src/new_render/render.h b/src/new_render/render.h index e69de29..93b2366 100644 --- a/src/new_render/render.h +++ b/src/new_render/render.h @@ -0,0 +1,12 @@ +/** + * @brief + */ + +#pragma once +#include "defines.h" + +typedef struct Renderer Renderer; +typedef struct RendererConfig RendererConfig; + +PUB bool Renderer_Init(RendererConfig config, Renderer* renderer); +PUB void Renderer_Shutdown(Renderer* renderer); diff --git a/src/new_render/render_types.h b/src/new_render/render_types.h index 13a45a4..63c472e 100644 --- a/src/new_render/render_types.h +++ b/src/new_render/render_types.h @@ -37,6 +37,10 @@ typedef enum MaterialKind { static const char* material_kind_names[] = { "Blinn Phong", "PBR (Textures)", "PBR (Params)", "Count (This should be an error)" }; +typedef struct Material { + char name[64]; +} Material; + typedef struct Model { // meshes // materials diff --git a/src/new_render/shadows.h b/src/new_render/shadows.h index 4f10f35..fd1c45d 100644 --- a/src/new_render/shadows.h +++ b/src/new_render/shadows.h @@ -1,5 +1,4 @@ /** - * @file shadows.h * @brief Functions for adding shadows to scene rendering. */ diff --git a/src/new_render/skybox.h b/src/new_render/skybox.h new file mode 100644 index 0000000..10ec4f9 --- /dev/null +++ b/src/new_render/skybox.h @@ -0,0 +1,6 @@ +/** + * @brief + */ + +#pragma once +#include "defines.h" diff --git a/src/ral/ral_types.h b/src/ral/ral_types.h index a27bbd2..5987fbf 100644 --- a/src/ral/ral_types.h +++ b/src/ral/ral_types.h @@ -54,6 +54,9 @@ typedef enum vertex_attrib_type { ATTR_I32x4, } vertex_attrib_type; +typedef struct vertex_description {} vertex_description; +typedef struct shader_desc {} shader_desc; + typedef struct graphics_pipeline_desc { const char* debug_name; vertex_description vertex_desc; diff --git a/src/systems/input.h b/src/systems/input.h index c119016..1ef7940 100644 --- a/src/systems/input.h +++ b/src/systems/input.h @@ -6,7 +6,6 @@ #include "defines.h" #include "keys.h" -struct core; struct GLFWWindow; typedef struct mouse_state { @@ -18,13 +17,13 @@ typedef struct mouse_state { bool left_btn_pressed; } mouse_state; -typedef struct input_state { +typedef struct Input_State { struct GLFWwindow *window; mouse_state mouse; bool depressed_keys[KEYCODE_MAX]; bool just_pressed_keys[KEYCODE_MAX]; bool just_released_keys[KEYCODE_MAX]; -} input_state; +} Input_State; /** @brief `key` is currently being held down */ bool key_is_pressed(keycode key); @@ -36,6 +35,8 @@ bool key_just_pressed(keycode key); bool key_just_released(keycode key); // --- Lifecycle -bool input_system_init(input_state *input, struct GLFWwindow *window); -void input_system_shutdown(input_state *input); -void input_update(input_state *state); \ No newline at end of file + +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 diff --git a/src/ui/ui.h b/src/ui/ui.h new file mode 100644 index 0000000..c5ace97 --- /dev/null +++ b/src/ui/ui.h @@ -0,0 +1,13 @@ +/** + * @brief + */ + +#pragma once +#include "defines.h" + +typedef struct UI_Storage UI_Storage; + +PUB bool UI_Init(UI_Storage* storage); +PUB void UI_Shutdown(UI_Storage* storage); + +// TODO: define immui api -- cgit v1.2.3-70-g09d2