summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/defines.h7
-rw-r--r--src/logos/threadpool.h4
-rw-r--r--src/new_render/render.c22
-rw-r--r--src/new_render/render.h3
-rw-r--r--src/new_render/render_frame.c20
-rw-r--r--src/new_render/render_frame.h27
-rw-r--r--src/platform/path.c2
-rw-r--r--src/ral/backends/opengl/backend_opengl.h2
8 files changed, 80 insertions, 7 deletions
diff --git a/src/defines.h b/src/defines.h
index 2edba8a..7275a4d 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -53,6 +53,9 @@ CORE_DEFINE_HANDLE(Handle); // Untyped handle that can be casted to a strongly t
#define PUB // For collecting public APIs to expose in an amalgamation header file
+#define MB(x) ((size_t) x * 1000 * 1000)
+#define KB(x) ((size_t) x * 1000)
+
// NOTE: The below is now handled in xmake.lua
// Platform will inform renderer backend (unless user overrides)
#if defined(CEL_PLATFORM_LINUX)
@@ -68,6 +71,6 @@ CORE_DEFINE_HANDLE(Handle); // Untyped handle that can be casted to a strongly t
#if defined(CEL_PLATFORM_MAC)
// #define CEL_REND_BACKEND_METAL 1
-// #define CEL_REND_BACKEND_OPENGL 1
-#define CEL_REND_BACKEND_VULKAN 1
+#define CEL_REND_BACKEND_OPENGL 1
+// #define CEL_REND_BACKEND_VULKAN 1
#endif
diff --git a/src/logos/threadpool.h b/src/logos/threadpool.h
index d5df2cd..fbe43d6 100644
--- a/src/logos/threadpool.h
+++ b/src/logos/threadpool.h
@@ -91,4 +91,6 @@ bool threadpool_add_task(threadpool *pool, tpool_task_start do_task,
bool buffer_result_for_main_thread, void *param_data, u32 param_data_size,
u32 result_data_size);
-void threadpool_process_results(threadpool *pool, int num_to_process); \ No newline at end of file
+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
diff --git a/src/new_render/render.c b/src/new_render/render.c
index 58041dd..bcdeb75 100644
--- a/src/new_render/render.c
+++ b/src/new_render/render.c
@@ -10,6 +10,7 @@
#include "log.h"
#include "maths.h"
#include "maths_types.h"
+#include "mem.h"
#include "pbr.h"
#include "ral_common.h"
#include "ral_impl.h"
@@ -21,6 +22,8 @@
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
+#define FRAME_ARENA_SIZE MB(1)
+
extern Core g_core;
struct Renderer {
@@ -36,6 +39,7 @@ struct Renderer {
// Terrain_Storage terrain;
// Text_Storage text;
ResourcePools* resource_pools;
+ arena frame_arena;
};
Renderer* get_renderer() { return g_core.renderer; }
@@ -43,6 +47,8 @@ Renderer* get_renderer() { return g_core.renderer; }
bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window) {
INFO("Renderer init");
+ ren->frame_arena = arena_create(malloc(FRAME_ARENA_SIZE), FRAME_ARENA_SIZE);
+
// init resource pools
DEBUG("Initialise GPU resource pools");
arena pool_arena = arena_create(malloc(1024 * 1024), 1024 * 1024);
@@ -100,10 +106,18 @@ bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window
return true;
}
-void Renderer_Shutdown(Renderer* ren) { free(ren->shadows); }
+void Renderer_Shutdown(Renderer* ren) {
+ free(ren->shadows);
+ DEBUG("Freed Shadows storage");
+ free(ren->pbr);
+ DEBUG("Freed PBR storage");
+ arena_free_storage(&ren->frame_arena);
+ DEBUG("Freed frame allocator buffer");
+}
size_t Renderer_GetMemReqs() { return sizeof(Renderer); }
void Render_FrameBegin(Renderer* ren) {
+ arena_free_all(&ren->frame_arena);
ren->frame_aborted = false;
if (!GPU_Backend_BeginFrame()) {
ren->frame_aborted = true;
@@ -207,4 +221,8 @@ 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; } \ No newline at end of file
+void SetMainLight(DirectionalLight light) { g_core.renderer->scene.sun = light; }
+
+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 718ac3e..0043c6c 100644
--- a/src/new_render/render.h
+++ b/src/new_render/render.h
@@ -64,3 +64,6 @@ PUB void DrawMesh(Mesh* mesh, Material* material, Mat4 model);
/** @brief the renderer does some internal bookkeeping for terrain so we use the terrain
stored on the Renderer rather than accept it as a parameter */
PUB void Render_DrawTerrain();
+
+// --- Getters (not in love with this but I'm finding keeping Renderer internals private to be okay)
+arena* GetRenderFrameArena(Renderer* r); \ No newline at end of file
diff --git a/src/new_render/render_frame.c b/src/new_render/render_frame.c
new file mode 100644
index 0000000..2dc98b0
--- /dev/null
+++ b/src/new_render/render_frame.c
@@ -0,0 +1,20 @@
+
+
+#include "render_frame.h"
+#include <assert.h>
+#include "logos/threadpool.h"
+#include "mem.h"
+#include "render.h"
+
+
+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
+
+ assert((result.n_visible_objects + result.n_culled_objects == entity_count));
+ return result;
+} \ No newline at end of file
diff --git a/src/new_render/render_frame.h b/src/new_render/render_frame.h
new file mode 100644
index 0000000..11b24f2
--- /dev/null
+++ b/src/new_render/render_frame.h
@@ -0,0 +1,27 @@
+#pragma once
+#include "camera.h"
+#include "defines.h"
+#include "ral_types.h"
+#include "render_types.h"
+
+// Frame lifecycle on CPU
+
+// 1. extract
+// 2. culling
+// 3. render
+// 4. dispatch (combined with render for now)
+
+typedef struct Cull_Result {
+ u64 n_visible_objects;
+ u64 n_culled_objects;
+ u32* visible_ent_indices; // allocated on frame arena
+ size_t index_count;
+} Cull_Result;
+
+// everything that can be in the world, knows how to extract rendering data
+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
diff --git a/src/platform/path.c b/src/platform/path.c
index e49aa3a..31fa59c 100644
--- a/src/platform/path.c
+++ b/src/platform/path.c
@@ -12,7 +12,7 @@ path_opt path_parent(arena* a, const char* path) {
char* path_copy = arena_alloc(a, strlen(path) + 1);
strcpy(path_copy, path);
char* path_dirname = dirname(path_copy);
- return (path_opt){ .path = str8_cstr_view(path_dirname), .has_value = true };
+ return (path_opt){ .path = Str8_cstr_view(path_dirname), .has_value = true };
}
#endif
#ifdef CEL_PLATFORM_WINDOWS
diff --git a/src/ral/backends/opengl/backend_opengl.h b/src/ral/backends/opengl/backend_opengl.h
index f8e76b8..f5ab9c8 100644
--- a/src/ral/backends/opengl/backend_opengl.h
+++ b/src/ral/backends/opengl/backend_opengl.h
@@ -66,7 +66,7 @@ typedef struct GPU_Texture {
typedef struct opengl_support {
} opengl_support;
-u32 shader_create_separate(const char *vert_shader, const char *frag_shader);
+// u32 shader_create_separate(const char *vert_shader, const char *frag_shader);
void uniform_vec3f(u32 program_id, const char *uniform_name, Vec3 *value);
void uniform_f32(u32 program_id, const char *uniform_name, f32 value);