diff options
Diffstat (limited to 'src/new_render')
-rw-r--r-- | src/new_render/render.c | 22 | ||||
-rw-r--r-- | src/new_render/render.h | 3 | ||||
-rw-r--r-- | src/new_render/render_frame.c | 20 | ||||
-rw-r--r-- | src/new_render/render_frame.h | 27 |
4 files changed, 70 insertions, 2 deletions
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 |