summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-07-11 21:43:06 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-07-11 21:43:06 +1000
commitfedba7ff68924ff50022405fc9103a5acf7013fe (patch)
treecd4e8ebd21736d460ac0434ce08cc2012bf613e0
parent9f23f65ec631bcd08f200b3ef517da8acf8d6b17 (diff)
wip
-rw-r--r--src/core/core.c36
-rw-r--r--src/core/core.h20
-rw-r--r--src/new_render/immdraw.h14
-rw-r--r--src/new_render/render.c37
-rw-r--r--src/new_render/render.h12
-rw-r--r--src/new_render/render_types.h4
-rw-r--r--src/new_render/shadows.h1
-rw-r--r--src/new_render/skybox.h6
-rw-r--r--src/ral/ral_types.h3
-rw-r--r--src/systems/input.h13
-rw-r--r--src/ui/ui.h13
-rw-r--r--xmake.lua151
12 files changed, 191 insertions, 119 deletions
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
diff --git a/xmake.lua b/xmake.lua
index f794221..8cbb910 100644
--- a/xmake.lua
+++ b/xmake.lua
@@ -61,10 +61,11 @@ local core_sources = {
"src/platform/*.c",
"src/physics/*.c",
"src/ral/*.c",
- "src/ral/backends/opengl/*.c",
- "src/renderer/*.c",
- "src/renderer/backends/*.c",
- "src/renderer/backends/opengl/*.c",
+ -- "src/ral/backends/opengl/*.c",
+ "src/new_render/*.c",
+ -- "src/renderer/*.c",
+ -- "src/renderer/backends/*.c",
+ -- "src/renderer/backends/opengl/*.c",
"src/resources/*.c",
"src/std/*.c",
"src/std/containers/*.c",
@@ -115,6 +116,8 @@ target("core_config")
add_includedirs("src/platform/", {public = true})
add_includedirs("src/physics/", {public = true})
add_includedirs("src/ral", {public = true})
+ add_includedirs("src/ral/backends/opengl", {public = true})
+ add_includedirs("src/new_render", {public = true})
-- add_includedirs("src/renderer/", {public = true})
-- add_includedirs("src/renderer/backends/", {public = true})
-- add_includedirs("src/renderer/backends/opengl", {public = true})
@@ -169,84 +172,84 @@ target("core_shared")
-- 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("cube")
- set_kind("binary")
- set_group("examples")
- -- add_defines("CEL_REND_BACKEND_OPENGL")
- add_deps("core_static")
- add_files("examples/cube/ex_cube.c")
- set_rundir("$(projectdir)")
-
-target("primitives")
- set_kind("binary")
- set_group("examples")
- add_deps("core_static")
- add_files("examples/primitives/ex_primitives.c")
- set_rundir("$(projectdir)")
-
--- target("std")
+-- target("tri")
-- set_kind("binary")
-- set_group("examples")
-- add_deps("core_static")
--- add_files("examples/standard_lib/ex_std.c")
+-- 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("obj")
+-- target("cube")
-- set_kind("binary")
-- set_group("examples")
+-- -- add_defines("CEL_REND_BACKEND_OPENGL")
-- add_deps("core_static")
--- add_files("examples/obj_loading/ex_obj_loading.c")
+-- add_files("examples/cube/ex_cube.c")
-- set_rundir("$(projectdir)")
--- target("input")
+-- target("primitives")
-- set_kind("binary")
-- set_group("examples")
-- add_deps("core_static")
--- add_files("examples/input/ex_input.c")
+-- add_files("examples/primitives/ex_primitives.c")
-- set_rundir("$(projectdir)")
-target("gltf")
- set_kind("binary")
- set_group("examples")
- add_deps("core_static")
- add_files("examples/gltf_loading/ex_gltf_loading.c")
- set_rundir("$(projectdir)")
+-- -- target("std")
+-- -- set_kind("binary")
+-- -- set_group("examples")
+-- -- add_deps("core_static")
+-- -- add_files("examples/standard_lib/ex_std.c")
+-- -- set_rundir("$(projectdir)")
-target("pbr_params")
- set_kind("binary")
- set_group("examples")
- add_deps("core_static")
- add_files("examples/pbr_params/ex_pbr_params.c")
- set_rundir("$(projectdir)")
+-- -- target("obj")
+-- -- set_kind("binary")
+-- -- set_group("examples")
+-- -- add_deps("core_static")
+-- -- add_files("examples/obj_loading/ex_obj_loading.c")
+-- -- set_rundir("$(projectdir)")
-target("pbr_textured")
- set_kind("binary")
- set_group("examples")
- add_deps("core_static")
- add_files("examples/pbr_textured/ex_pbr_textured.c")
- set_rundir("$(projectdir)")
+-- -- target("input")
+-- -- set_kind("binary")
+-- -- set_group("examples")
+-- -- add_deps("core_static")
+-- -- add_files("examples/input/ex_input.c")
+-- -- set_rundir("$(projectdir)")
-target("shadows")
- set_kind("binary")
- set_group("examples")
- add_deps("core_static")
- add_files("examples/shadow_maps/ex_shadow_maps.c")
- set_rundir("$(projectdir)")
+-- target("gltf")
+-- set_kind("binary")
+-- set_group("examples")
+-- add_deps("core_static")
+-- add_files("examples/gltf_loading/ex_gltf_loading.c")
+-- set_rundir("$(projectdir)")
+
+-- target("pbr_params")
+-- set_kind("binary")
+-- set_group("examples")
+-- add_deps("core_static")
+-- add_files("examples/pbr_params/ex_pbr_params.c")
+-- set_rundir("$(projectdir)")
+
+-- target("pbr_textured")
+-- set_kind("binary")
+-- set_group("examples")
+-- add_deps("core_static")
+-- add_files("examples/pbr_textured/ex_pbr_textured.c")
+-- set_rundir("$(projectdir)")
+
+-- target("shadows")
+-- set_kind("binary")
+-- set_group("examples")
+-- add_deps("core_static")
+-- add_files("examples/shadow_maps/ex_shadow_maps.c")
+-- set_rundir("$(projectdir)")
-- target("transforms")
-- set_kind("binary")
@@ -283,13 +286,13 @@ target("shadows")
-- add_files("examples/demo/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")
+-- 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")