diff options
Diffstat (limited to 'src/new_render')
-rw-r--r-- | src/new_render/immdraw.h | 1 | ||||
-rw-r--r-- | src/new_render/pbr.h | 28 | ||||
-rw-r--r-- | src/new_render/render.c | 4 | ||||
-rw-r--r-- | src/new_render/render.h | 12 | ||||
-rw-r--r-- | src/new_render/render_frame.c | 8 | ||||
-rw-r--r-- | src/new_render/render_frame.h | 4 | ||||
-rw-r--r-- | src/new_render/render_scene.h | 6 | ||||
-rw-r--r-- | src/new_render/render_types.h | 30 | ||||
-rw-r--r-- | src/new_render/shader_layouts.h | 37 | ||||
-rw-r--r-- | src/new_render/shadows.h | 20 | ||||
-rw-r--r-- | src/new_render/skybox.h | 39 |
11 files changed, 85 insertions, 104 deletions
diff --git a/src/new_render/immdraw.h b/src/new_render/immdraw.h index 46c5add..add7b76 100644 --- a/src/new_render/immdraw.h +++ b/src/new_render/immdraw.h @@ -7,7 +7,6 @@ #include "maths_types.h" typedef struct Immdraw_Storage { - } Immdraw_Storage; // --- Public API diff --git a/src/new_render/pbr.h b/src/new_render/pbr.h index f3bad4b..914975b 100644 --- a/src/new_render/pbr.h +++ b/src/new_render/pbr.h @@ -5,18 +5,18 @@ #pragma once #include "backend_opengl.h" -#include "defines.h" #include "camera.h" +#include "defines.h" #include "maths_types.h" #include "ral_types.h" #include "render_types.h" // --- Public API typedef struct PBR_Storage { - GPU_Renderpass* pbr_pass; - GPU_Pipeline* pbr_pipeline; + GPU_Renderpass* pbr_pass; + GPU_Pipeline* pbr_pipeline; -} PBR_Storage; // Stores all necessary data and handles +} PBR_Storage; // Stores all necessary data and handles typedef struct PBRMaterialUniforms { Material mat; @@ -25,12 +25,11 @@ typedef struct PBRMaterialUniforms { PUB void PBR_Init(PBR_Storage* storage); // NOTE: For simplicity's sake we will render this pass directly to the default framebuffer -PUB void PBR_Run( - PBR_Storage* storage - // light data - // camera - // geometry - // materials +PUB void PBR_Run(PBR_Storage* storage + // light data + // camera + // geometry + // materials ); typedef struct PBR_Params { @@ -57,12 +56,7 @@ GPU_Renderpass* PBR_RPassCreate(); GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass); -void PBR_Execute( - PBR_Storage* storage, - Camera camera, - TextureHandle shadowmap_tex, - RenderEnt* entities, - size_t entity_count -); +void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_tex, + RenderEnt* entities, size_t entity_count); ShaderDataLayout PBRMaterial_GetLayout(void* data);
\ No newline at end of file diff --git a/src/new_render/render.c b/src/new_render/render.c index bcdeb75..dcaa5a5 100644 --- a/src/new_render/render.c +++ b/src/new_render/render.c @@ -223,6 +223,4 @@ 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; } -arena* GetRenderFrameArena(Renderer* r) { - return &r->frame_arena; -}
\ No newline at end of file +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 0043c6c..13c626d 100644 --- a/src/new_render/render.h +++ b/src/new_render/render.h @@ -11,18 +11,18 @@ typedef struct Renderer Renderer; typedef struct GLFWwindow GLFWwindow; typedef struct RendererConfig { - char window_name[256]; - u32 scr_width, scr_height; - Vec3 clear_colour; + char window_name[256]; + u32 scr_width, scr_height; + Vec3 clear_colour; } RendererConfig; typedef struct RenderFlags { - bool wireframe; + bool wireframe; } RenderFlags; typedef struct RenderCtx { - Mat4 view; - Mat4 projection; + Mat4 view; + Mat4 projection; } RenderCtx; // --- Lifecycle diff --git a/src/new_render/render_frame.c b/src/new_render/render_frame.c index 2dc98b0..9a95259 100644 --- a/src/new_render/render_frame.c +++ b/src/new_render/render_frame.c @@ -6,14 +6,14 @@ #include "mem.h" #include "render.h" - -Cull_Result Frame_Cull(Renderer* ren, RenderEnt *entities, size_t entity_count, Camera *camera) { +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 + 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; diff --git a/src/new_render/render_frame.h b/src/new_render/render_frame.h index 11b24f2..02f7f22 100644 --- a/src/new_render/render_frame.h +++ b/src/new_render/render_frame.h @@ -14,7 +14,7 @@ typedef struct Cull_Result { u64 n_visible_objects; u64 n_culled_objects; - u32* visible_ent_indices; // allocated on frame arena + u32* visible_ent_indices; // allocated on frame arena size_t index_count; } Cull_Result; @@ -24,4 +24,4 @@ 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 +Cull_Result Frame_Cull(Renderer* ren, RenderEnt* entities, size_t entity_count, Camera* camera);
\ No newline at end of file diff --git a/src/new_render/render_scene.h b/src/new_render/render_scene.h index 1e4660a..31dc1c9 100644 --- a/src/new_render/render_scene.h +++ b/src/new_render/render_scene.h @@ -3,15 +3,15 @@ * @brief */ #pragma once +#include "camera.h" #include "defines.h" #include "render_types.h" -#include "camera.h" /** @brief Holds globally bound data for rendering a scene. Typically held by the renderer. * Whenever you call draw functions you can think of this as an implicit parameter. */ typedef struct RenderScene { - Camera camera; - DirectionalLight sun; + Camera camera; + DirectionalLight sun; } RenderScene; // --- Public APIs diff --git a/src/new_render/render_types.h b/src/new_render/render_types.h index 4807559..e0bd76b 100644 --- a/src/new_render/render_types.h +++ b/src/new_render/render_types.h @@ -1,13 +1,13 @@ /** * @file render_types.h * @brief -*/ + */ #pragma once #include "defines.h" +#include "maths.h" #include "maths_types.h" #include "ral.h" -#include "maths.h" #include "ral_types.h" // --- Handles @@ -29,9 +29,9 @@ typedef struct u32_opt { typedef struct Mesh { BufferHandle vertex_buffer; BufferHandle index_buffer; - Geometry geometry; // NULL means it has been freed CPU-side - i32 material_index; // -1 => no material - bool is_uploaded; // has the data been uploaded to the GPU + Geometry geometry; // NULL means it has been freed CPU-side + i32 material_index; // -1 => no material + bool is_uploaded; // has the data been uploaded to the GPU } Mesh; #ifndef TYPED_MESH_ARRAY KITC_DECL_TYPED_ARRAY(Mesh) @@ -39,15 +39,15 @@ KITC_DECL_TYPED_ARRAY(Mesh) #endif typedef struct TextureData { - TextureDesc description; - void* image_data; + TextureDesc description; + void* image_data; } TextureData; // --- Supported materials typedef enum MaterialKind { - MAT_BLINN_PHONG, // NOTE: we're dropping support for this - MAT_PBR, // uses textures for PBR properties - MAT_PBR_PARAMS, // uses float values to represent a surface uniformly + MAT_BLINN_PHONG, // NOTE: we're dropping support for this + MAT_PBR, // uses textures for PBR properties + MAT_PBR_PARAMS, // uses float values to represent a surface uniformly MAT_COUNT } MaterialKind; static const char* material_kind_names[] = { "Blinn Phong", "PBR (Textures)", "PBR (Params)", @@ -107,11 +107,11 @@ typedef struct DirectionalLight { // A renderable 'thing' typedef struct RenderEnt { - Mesh* mesh; - Material* material; - Mat4 affine; // In the future this should be updated by the transform graph - // Bbox_3D bounding_box; - bool casts_shadows; + Mesh* mesh; + Material* material; + Mat4 affine; // In the future this should be updated by the transform graph + // Bbox_3D bounding_box; + bool casts_shadows; } RenderEnt; #ifndef TYPED_RENDERENT_ARRAY diff --git a/src/new_render/shader_layouts.h b/src/new_render/shader_layouts.h index c98f3c5..09cf129 100644 --- a/src/new_render/shader_layouts.h +++ b/src/new_render/shader_layouts.h @@ -15,7 +15,6 @@ typedef struct Binding_Model { /** @brief data that is handy to have in any shader */ typedef struct Binding_Globals { - } Binding_Globals; typedef struct pbr_point_light { @@ -33,45 +32,39 @@ static ShaderDataLayout Binding_Camera_GetLayout(void* data) { Binding_Camera* d = data; bool has_data = data != NULL; - ShaderBinding b1 = { - .label = "Camera", - .kind = BINDING_BYTES, - .data.bytes = { .size = sizeof(Binding_Camera) } - }; + ShaderBinding b1 = { .label = "Camera", + .kind = BINDING_BYTES, + .data.bytes = { .size = sizeof(Binding_Camera) } }; if (has_data) { b1.data.bytes.data = d; } - return (ShaderDataLayout) {.bindings = {b1 }, .binding_count = 1}; + return (ShaderDataLayout){ .bindings = { b1 }, .binding_count = 1 }; } static ShaderDataLayout Binding_Model_GetLayout(void* data) { Binding_Model* d = data; bool has_data = data != NULL; - ShaderBinding b1 = { - .label = "Model", - .kind = BINDING_BYTES, - .vis = VISIBILITY_VERTEX, - .data.bytes = { .size = sizeof(Binding_Model) } - }; + ShaderBinding b1 = { .label = "Model", + .kind = BINDING_BYTES, + .vis = VISIBILITY_VERTEX, + .data.bytes = { .size = sizeof(Binding_Model) } }; if (has_data) { b1.data.bytes.data = d; } - return (ShaderDataLayout) {.bindings = {b1 }, .binding_count = 1}; + return (ShaderDataLayout){ .bindings = { b1 }, .binding_count = 1 }; } static ShaderDataLayout Binding_Lights_GetLayout(void* data) { -Binding_Lights* d = data; + Binding_Lights* d = data; bool has_data = data != NULL; - ShaderBinding b1 = { - .label = "Lights", - .kind = BINDING_BYTES, - .vis = VISIBILITY_FRAGMENT, - .data.bytes = { .size = sizeof(Binding_Lights) } - }; + ShaderBinding b1 = { .label = "Lights", + .kind = BINDING_BYTES, + .vis = VISIBILITY_FRAGMENT, + .data.bytes = { .size = sizeof(Binding_Lights) } }; if (has_data) { b1.data.bytes.data = d; } - return (ShaderDataLayout) {.bindings = {b1 }, .binding_count = 1}; + return (ShaderDataLayout){ .bindings = { b1 }, .binding_count = 1 }; }
\ No newline at end of file diff --git a/src/new_render/shadows.h b/src/new_render/shadows.h index 9e8a6ad..11fce3b 100644 --- a/src/new_render/shadows.h +++ b/src/new_render/shadows.h @@ -1,7 +1,6 @@ /** * @brief Functions for adding shadows to scene rendering. -*/ - + */ #pragma once #include "defines.h" @@ -10,11 +9,11 @@ #include "render_types.h" typedef struct Shadow_Storage { - GPU_Renderpass* shadowmap_pass; - GPU_Pipeline* pipeline; - bool debug_quad_enabled; - TextureHandle depth_texture; - // TODO: Some statistics tracking + GPU_Renderpass* shadowmap_pass; + GPU_Pipeline* pipeline; + bool debug_quad_enabled; + TextureHandle depth_texture; + // TODO: Some statistics tracking } Shadow_Storage; typedef struct ShadowUniforms { @@ -36,7 +35,8 @@ PUB void Shadow_Run(Shadow_Storage* storage, RenderEnt* entities, size_t entity_ PUB Handle Shadow_GetShadowMapTexture(Shadow_Storage* storage); // --- Internal -GPU_Renderpass* Shadow_RPassCreate(); // Creates the render pass -GPU_Pipeline* Shadow_PipelineCreate(GPU_Renderpass* rpass); // Creates the pipeline -void Shadow_ShadowmapExecute(Shadow_Storage* storage, Mat4 light_space_transform, RenderEnt* entities, size_t entity_count); +GPU_Renderpass* Shadow_RPassCreate(); // Creates the render pass +GPU_Pipeline* Shadow_PipelineCreate(GPU_Renderpass* rpass); // Creates the pipeline +void Shadow_ShadowmapExecute(Shadow_Storage* storage, Mat4 light_space_transform, + RenderEnt* entities, size_t entity_count); void Shadow_RenderDebugQuad(); diff --git a/src/new_render/skybox.h b/src/new_render/skybox.h index 71262fd..465d603 100644 --- a/src/new_render/skybox.h +++ b/src/new_render/skybox.h @@ -9,34 +9,31 @@ #include "render_types.h" typedef struct Skybox { - Mesh cube; - TextureHandle texture; - GPU_Pipeline* pipeline; // "shader" + Mesh cube; + TextureHandle texture; + GPU_Pipeline* pipeline; // "shader" } Skybox; -PUB Skybox Skybox_Create(const char** face_paths, int n); // should always pass n = 6 for now +PUB Skybox Skybox_Create(const char** face_paths, int n); // should always pass n = 6 for now PUB void Skybox_Draw(Skybox* skybox, Camera camera); typedef struct SkyboxUniforms { - TextureHandle cubemap; + TextureHandle cubemap; } SkyboxUniforms; static ShaderDataLayout Skybox_GetLayout(void* data) { - SkyboxUniforms* d = (SkyboxUniforms*)data; // cold cast - bool has_data = data != NULL; - - ShaderBinding b1 = { - .label = "cubeMap", - .vis = VISIBILITY_FRAGMENT, - .kind = BINDING_TEXTURE, - }; - - if (has_data) { - b1.data.texture.handle = d->cubemap; - } - return (ShaderDataLayout) { - .bindings = { b1}, - .binding_count = 1 - }; + SkyboxUniforms* d = (SkyboxUniforms*)data; // cold cast + bool has_data = data != NULL; + + ShaderBinding b1 = { + .label = "cubeMap", + .vis = VISIBILITY_FRAGMENT, + .kind = BINDING_TEXTURE, + }; + + if (has_data) { + b1.data.texture.handle = d->cubemap; + } + return (ShaderDataLayout){ .bindings = { b1 }, .binding_count = 1 }; } |