diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-08-10 14:06:15 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-08-10 14:06:15 +1000 |
commit | 9cb4bfacc69b2a95ce8e9250afc33fb04d1ba548 (patch) | |
tree | fbe75da188ac83b34153ac79c367b9d57e0d5ff9 /src | |
parent | 071a635e63536e50abfad7d5aeca1208dba58025 (diff) |
remove old code
Diffstat (limited to 'src')
-rw-r--r-- | src/new_render/draw.h | 13 | ||||
-rw-r--r-- | src/new_render/render_frame.c | 20 | ||||
-rw-r--r-- | src/new_render/render_frame.h | 27 | ||||
-rw-r--r-- | src/new_render/render_scene.h | 20 | ||||
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.c | 3 | ||||
-rw-r--r-- | src/render/archive/backends/backend_test.c (renamed from src/render/backends/backend_test.c) | 0 | ||||
-rw-r--r-- | src/render/archive/backends/metal/README.md (renamed from src/render/backends/metal/README.md) | 0 | ||||
-rw-r--r-- | src/render/archive/backends/metal/backend_metal.h (renamed from src/render/backends/metal/backend_metal.h) | 0 | ||||
-rw-r--r-- | src/render/archive/backends/metal/backend_metal.m (renamed from src/render/backends/metal/backend_metal.m) | 0 | ||||
-rw-r--r-- | src/render/archive/backends/opengl/backend_opengl.c (renamed from src/render/backends/opengl/backend_opengl.c) | 0 | ||||
-rw-r--r-- | src/render/archive/backends/opengl/backend_opengl.h (renamed from src/render/backends/opengl/backend_opengl.h) | 0 | ||||
-rw-r--r-- | src/render/archive/backends/vulkan/README.md (renamed from src/render/backends/vulkan/README.md) | 0 | ||||
-rw-r--r-- | src/render/archive/backends/vulkan/backend_vulkan.c (renamed from src/render/backends/vulkan/backend_vulkan.c) | 0 | ||||
-rw-r--r-- | src/render/archive/backends/vulkan/backend_vulkan.h (renamed from src/render/backends/vulkan/backend_vulkan.h) | 0 | ||||
-rw-r--r-- | src/render/builtin_materials.h | 153 | ||||
-rw-r--r-- | src/render/immdraw.c (renamed from src/new_render/immdraw.c) | 0 | ||||
-rw-r--r-- | src/render/immdraw.h (renamed from src/new_render/immdraw.h) | 0 | ||||
-rw-r--r-- | src/render/immediate.c | 46 | ||||
-rw-r--r-- | src/render/pbr.c (renamed from src/new_render/pbr.c) | 3 | ||||
-rw-r--r-- | src/render/pbr.h (renamed from src/new_render/pbr.h) | 0 | ||||
-rw-r--r-- | src/render/ral.c | 97 | ||||
-rw-r--r-- | src/render/ral_types.h | 102 | ||||
-rw-r--r-- | src/render/render.c (renamed from src/new_render/render.c) | 10 | ||||
-rw-r--r-- | src/render/render.h (renamed from src/new_render/render.h) | 49 | ||||
-rw-r--r-- | src/render/render_types.h (renamed from src/new_render/render_types.h) | 0 | ||||
-rw-r--r-- | src/render/renderpasses.c | 140 | ||||
-rw-r--r-- | src/render/renderpasses.h | 56 | ||||
-rw-r--r-- | src/render/shader_layouts.h (renamed from src/new_render/shader_layouts.h) | 0 | ||||
-rw-r--r-- | src/render/shadows.c (renamed from src/new_render/shadows.c) | 1 | ||||
-rw-r--r-- | src/render/shadows.h (renamed from src/new_render/shadows.h) | 0 | ||||
-rw-r--r-- | src/render/skybox.c (renamed from src/new_render/skybox.c) | 0 | ||||
-rw-r--r-- | src/render/skybox.h (renamed from src/new_render/skybox.h) | 0 | ||||
-rw-r--r-- | src/resources/gltf.c | 3 | ||||
-rw-r--r-- | src/std/mem.c | 4 | ||||
-rw-r--r-- | src/systems/grid.c | 3 | ||||
-rw-r--r-- | src/systems/terrain.c | 3 |
36 files changed, 62 insertions, 691 deletions
diff --git a/src/new_render/draw.h b/src/new_render/draw.h deleted file mode 100644 index 58e104e..0000000 --- a/src/new_render/draw.h +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @file draw.h - * @brief - */ -#pragma once -#include "defines.h" -#include "maths_types.h" -#include "render_types.h" - -// --- Public APIs - -PUB void EncodeDrawModel(Handle model, Mat4 transform); -PUB void EncodeDrawMesh(Mesh* mesh, Material* material, Mat4 affine); diff --git a/src/new_render/render_frame.c b/src/new_render/render_frame.c deleted file mode 100644 index 87c99e5..0000000 --- a/src/new_render/render_frame.c +++ /dev/null @@ -1,20 +0,0 @@ - - -#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 deleted file mode 100644 index 02f7f22..0000000 --- a/src/new_render/render_frame.h +++ /dev/null @@ -1,27 +0,0 @@ -#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/new_render/render_scene.h b/src/new_render/render_scene.h deleted file mode 100644 index 31dc1c9..0000000 --- a/src/new_render/render_scene.h +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @file render_scene.h - * @brief - */ -#pragma once -#include "camera.h" -#include "defines.h" -#include "render_types.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; -} RenderScene; - -// --- Public APIs - -PUB void SetCamera(Camera camera); -PUB void SetMainLight(DirectionalLight light); diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c index 5e08cf3..f971568 100644 --- a/src/ral/backends/opengl/backend_opengl.c +++ b/src/ral/backends/opengl/backend_opengl.c @@ -57,8 +57,7 @@ bool GPU_Backend_Init(const char* window_name, struct GLFWwindow* window, } // All of these are no-ops in OpenGL -void GPU_Backend_Shutdown() { /* TODO */ -} +void GPU_Backend_Shutdown() { /* TODO */ } bool GPU_Device_Create(GPU_Device* out_device) { return true; } void GPU_Device_Destroy(GPU_Device* device) {} bool GPU_Swapchain_Create(GPU_Swapchain* out_swapchain) { return true; } diff --git a/src/render/backends/backend_test.c b/src/render/archive/backends/backend_test.c index 6347e27..6347e27 100644 --- a/src/render/backends/backend_test.c +++ b/src/render/archive/backends/backend_test.c diff --git a/src/render/backends/metal/README.md b/src/render/archive/backends/metal/README.md index f87f5c1..f87f5c1 100644 --- a/src/render/backends/metal/README.md +++ b/src/render/archive/backends/metal/README.md diff --git a/src/render/backends/metal/backend_metal.h b/src/render/archive/backends/metal/backend_metal.h index 9561bb6..9561bb6 100644 --- a/src/render/backends/metal/backend_metal.h +++ b/src/render/archive/backends/metal/backend_metal.h diff --git a/src/render/backends/metal/backend_metal.m b/src/render/archive/backends/metal/backend_metal.m index 4787755..4787755 100644 --- a/src/render/backends/metal/backend_metal.m +++ b/src/render/archive/backends/metal/backend_metal.m diff --git a/src/render/backends/opengl/backend_opengl.c b/src/render/archive/backends/opengl/backend_opengl.c index 43105e2..43105e2 100644 --- a/src/render/backends/opengl/backend_opengl.c +++ b/src/render/archive/backends/opengl/backend_opengl.c diff --git a/src/render/backends/opengl/backend_opengl.h b/src/render/archive/backends/opengl/backend_opengl.h index 73a19ed..73a19ed 100644 --- a/src/render/backends/opengl/backend_opengl.h +++ b/src/render/archive/backends/opengl/backend_opengl.h diff --git a/src/render/backends/vulkan/README.md b/src/render/archive/backends/vulkan/README.md index 220ed64..220ed64 100644 --- a/src/render/backends/vulkan/README.md +++ b/src/render/archive/backends/vulkan/README.md diff --git a/src/render/backends/vulkan/backend_vulkan.c b/src/render/archive/backends/vulkan/backend_vulkan.c index 8801230..8801230 100644 --- a/src/render/backends/vulkan/backend_vulkan.c +++ b/src/render/archive/backends/vulkan/backend_vulkan.c diff --git a/src/render/backends/vulkan/backend_vulkan.h b/src/render/archive/backends/vulkan/backend_vulkan.h index 6ca0bb5..6ca0bb5 100644 --- a/src/render/backends/vulkan/backend_vulkan.h +++ b/src/render/archive/backends/vulkan/backend_vulkan.h diff --git a/src/render/builtin_materials.h b/src/render/builtin_materials.h deleted file mode 100644 index b15e62e..0000000 --- a/src/render/builtin_materials.h +++ /dev/null @@ -1,153 +0,0 @@ -/** - * @file builtin_materials.h - * @author your name (you@domain.com) - * @brief - * @version 0.1 - * @date 2024-06-15 - * - * @copyright Copyright (c) 2024 - * - */ -#pragma once - -#include <assert.h> -#include "defines.h" -#include "ral_types.h" - -// Currently supported materials -// - Blinn Phong (textured) -// - PBR (params) -// - PBR (textured) - -// Thoughts -// -------- -// -// A material and a shader are inextricably linked. The input data for a shader needs the material. -// However, a shader may require more than just a material? - -// --- Common uniform blocks - -/* In glsl code we call it 'MVP_Matrices' */ -typedef struct mvp_matrix_uniforms { - mat4 model; - mat4 view; - mat4 projection; -} mvp_matrix_uniforms; - -// --- PBR (params) - -typedef struct pbr_params_material_uniforms { - vec3 albedo; - f32 metallic; - f32 roughness; - f32 ao; - f32 pad[2]; -} pbr_params_material_uniforms; - -typedef struct pbr_point_light { - vec3 pos; - f32 pad; - vec3 color; - f32 pad2; -} pbr_point_light; - -typedef struct pbr_params_light_uniforms { - pbr_point_light pointLights[4]; - vec4 viewPos; -} pbr_params_light_uniforms; - -typedef struct pbr_params_bindgroup { - mvp_matrix_uniforms mvp_matrices; - pbr_params_material_uniforms material; - pbr_params_light_uniforms lights; -} pbr_params_bindgroup; - -static shader_data_layout pbr_params_shader_layout(void* data) { - pbr_params_bindgroup* d = (pbr_params_bindgroup*)data; - bool has_data = data != NULL; - - shader_binding b1 = { .label = "MVP_Matrices", - .type = SHADER_BINDING_BYTES, - .stores_data = has_data, - .data = { .bytes = { .size = sizeof(mvp_matrix_uniforms) } } }; - - shader_binding b2 = { .label = "PBR_Params", - .type = SHADER_BINDING_BYTES, - .stores_data = has_data, - .data = { .bytes = { .size = sizeof(pbr_params_material_uniforms) } } }; - - shader_binding b3 = { .label = "Scene_Lights", - .type = SHADER_BINDING_BYTES, - .stores_data = has_data, - .data = { .bytes = { .size = sizeof(pbr_params_light_uniforms) } } }; - - if (has_data) { - // printf("Size %d \n", b3.data.bytes.size); - b1.data.bytes.data = &d->mvp_matrices; - b2.data.bytes.data = &d->material; - /* d->lights.viewPos = vec3(0, 1, 0); */ - b3.data.bytes.data = &d->lights; - // print_vec3(d->lights.viewPos); - } - - return (shader_data_layout){ .name = "pbr_params", .bindings = { b1, b2, b3 }, .bindings_count = 3 - - }; -} - -static void* shader_layout_get_binding(shader_data_layout* layout, u32 nth_binding) { - assert(nth_binding < layout->bindings_count); - return &layout->bindings[nth_binding].data; -} - -typedef struct pbr_textures { - texture_handle albedo_tex; - texture_handle metal_roughness_tex; - texture_handle ao_tex; - texture_handle normal_tex; -} pbr_textures; - -typedef struct pbr_textured_bindgroup { - mvp_matrix_uniforms mvp_matrices; - pbr_params_light_uniforms lights; - pbr_textures textures; -} pbr_textured_bindgroup; - -static shader_data_layout pbr_textured_shader_layout(void* data) { - pbr_textured_bindgroup* d = (pbr_textured_bindgroup*)data; - bool has_data = data != NULL; - - shader_binding b1 = { .label = "MVP_Matrices", - .type = SHADER_BINDING_BYTES, - .stores_data = has_data, - .data = { .bytes = { .size = sizeof(mvp_matrix_uniforms) } } }; - - shader_binding b2 = { .label = "Scene_Lights", - .type = SHADER_BINDING_BYTES, - .stores_data = has_data, - .data = { .bytes = { .size = sizeof(pbr_params_light_uniforms) } } }; - - shader_binding b3 = { .label = "albedoMap", - .type = SHADER_BINDING_TEXTURE, - .stores_data = has_data }; - shader_binding b4 = { .label = "metallicRoughnessMap", - .type = SHADER_BINDING_TEXTURE, - .stores_data = has_data }; - shader_binding b5 = { .label = "aoMap", .type = SHADER_BINDING_TEXTURE, .stores_data = has_data }; - shader_binding b6 = { .label = "normalMap", - .type = SHADER_BINDING_TEXTURE, - .stores_data = has_data }; - - if (has_data) { - b1.data.bytes.data = &d->mvp_matrices; - b2.data.bytes.data = &d->lights; - b3.data.texture.handle = d->textures.albedo_tex; - b4.data.texture.handle = d->textures.metal_roughness_tex; - b5.data.texture.handle = d->textures.ao_tex; - b6.data.texture.handle = d->textures.normal_tex; - } - - return (shader_data_layout){ .name = "pbr_params", - .bindings = { b1, b2, b3, b4, b5, b6 }, - .bindings_count = 6 }; -} diff --git a/src/new_render/immdraw.c b/src/render/immdraw.c index c711b0c..c711b0c 100644 --- a/src/new_render/immdraw.c +++ b/src/render/immdraw.c diff --git a/src/new_render/immdraw.h b/src/render/immdraw.h index 0d58375..0d58375 100644 --- a/src/new_render/immdraw.h +++ b/src/render/immdraw.h diff --git a/src/render/immediate.c b/src/render/immediate.c deleted file mode 100644 index 63a62b8..0000000 --- a/src/render/immediate.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "immediate.h" -#include "glad/glad.h" -#include "maths.h" -#include "primitives.h" -#include "ral_types.h" -#include "render.h" -#include "render_types.h" - -typedef struct immdraw_system { - // primitive meshes (get reused for each draw call) - mesh plane; - mesh cube; - mesh sphere; - // command lists - -} immdraw_system; - -bool immdraw_system_init(immdraw_system* state) { - geometry_data plane_geometry = geo_create_plane(f32x2(1, 1)); - state->plane = mesh_create(&plane_geometry, true); - - geometry_data cube_geometry = geo_create_cuboid(f32x3(1, 1, 1)); - state->cube = mesh_create(&cube_geometry, true); - - geometry_data sphere_geometry = geo_create_uvsphere(1.0, 48, 48); - state->sphere = mesh_create(&sphere_geometry, true); - - return true; -} - -void immdraw_plane(vec3 pos, quat rotation, f32 u_scale, f32 v_scale, vec4 colour) {} - -void immdraw_system_render(immdraw_system* state) {} - -// void imm_draw_sphere(vec3 pos, f32 radius, vec4 colour) { -// // Create the vertices -// geometry_data geometry = geo_create_uvsphere(radius, 16, 16); -// geo_set_vertex_colours(&geometry, colour); - -// // Upload to GPU -// mat4 model = mat4_translation(pos); - -// // Set pipeline - -// // Draw -// }
\ No newline at end of file diff --git a/src/new_render/pbr.c b/src/render/pbr.c index 1e94e81..1a7b4de 100644 --- a/src/new_render/pbr.c +++ b/src/render/pbr.c @@ -9,7 +9,6 @@ #include "ral_impl.h" #include "ral_types.h" #include "render.h" -#include "render_scene.h" #include "render_types.h" #include "shader_layouts.h" @@ -214,4 +213,4 @@ Material PBRMaterialDefault() { .metallic_roughness_map = INVALID_TEX_HANDLE, .normal_map = INVALID_TEX_HANDLE, .ambient_occlusion_map = INVALID_TEX_HANDLE }; -}
\ No newline at end of file +} diff --git a/src/new_render/pbr.h b/src/render/pbr.h index cbdc577..cbdc577 100644 --- a/src/new_render/pbr.h +++ b/src/render/pbr.h diff --git a/src/render/ral.c b/src/render/ral.c deleted file mode 100644 index 9ca99ce..0000000 --- a/src/render/ral.c +++ /dev/null @@ -1,97 +0,0 @@ -#include "ral.h" -#include "file.h" -#include "log.h" -#include "mem.h" -#include "str.h" - -#if defined(CEL_REND_BACKEND_VULKAN) -#include "backend_vulkan.h" -#elif defined(CEL_REND_BACKEND_METAL) -#include "backend_metal.h" -#elif defined(CEL_REND_BACKEND_OPENGL) -#include "backend_opengl.h" -#endif - -size_t vertex_attrib_size(vertex_attrib_type attr) { - switch (attr) { - case ATTR_F32: - case ATTR_U32: - case ATTR_I32: - return 4; - case ATTR_F32x2: - case ATTR_U32x2: - case ATTR_I32x2: - return 8; - case ATTR_F32x3: - case ATTR_U32x3: - case ATTR_I32x3: - return 12; - case ATTR_F32x4: - case ATTR_U32x4: - case ATTR_I32x4: - return 16; - break; - } -} - -void vertex_desc_add(vertex_description* builder, const char* name, vertex_attrib_type type) { - u32 i = builder->attributes_count; - - size_t size = vertex_attrib_size(type); - builder->attributes[i] = type; - builder->stride += size; - builder->attr_names[i] = name; - - builder->attributes_count++; -} - -vertex_description static_3d_vertex_description() { - vertex_description builder = { .debug_label = "Standard static 3d vertex format" }; - vertex_desc_add(&builder, "inPosition", ATTR_F32x3); - vertex_desc_add(&builder, "inNormal", ATTR_F32x3); - vertex_desc_add(&builder, "inTexCoords", ATTR_F32x2); - builder.use_full_vertex_size = true; - return builder; -} - -void backend_pools_init(arena* a, gpu_backend_pools* backend_pools) { - pipeline_layout_pool pipeline_layout_pool = - pipeline_layout_pool_create(a, MAX_PIPELINES, sizeof(gpu_pipeline_layout)); - backend_pools->pipeline_layouts = pipeline_layout_pool; - pipeline_pool pipeline_pool = pipeline_pool_create(a, MAX_PIPELINES, sizeof(gpu_pipeline)); - backend_pools->pipelines = pipeline_pool; - renderpass_pool rpass_pool = renderpass_pool_create(a, MAX_RENDERPASSES, sizeof(gpu_renderpass)); - backend_pools->renderpasses = rpass_pool; - - // context.gpu_pools; -} - -void resource_pools_init(arena* a, struct resource_pools* res_pools) { - buffer_pool buf_pool = buffer_pool_create(a, MAX_BUFFERS, sizeof(gpu_buffer)); - res_pools->buffers = buf_pool; - texture_pool tex_pool = texture_pool_create(a, MAX_TEXTURES, sizeof(gpu_texture)); - res_pools->textures = tex_pool; - - // context.resource_pools = res_pools; -} - -void print_shader_binding(shader_binding b) { - printf("Binding name: %s type %s vis %d stores data %d\n", b.label, - shader_binding_type_name[b.type], b.vis, b.stores_data); -} - -shader_desc shader_quick_load(const char* filepath) { - arena a = arena_create(malloc(1024 * 1024), 1024 * 1024); - str8 path = str8_cstr_view(filepath); - str8_opt shader = str8_from_file(&a, path); - if (!shader.has_value) { - ERROR_EXIT("Failed to load shaders from disk"); - } - - return (shader_desc){ - .debug_name = filepath, - .code = shader.contents, - .filepath = path, - .is_spirv = true, - }; -} diff --git a/src/render/ral_types.h b/src/render/ral_types.h deleted file mode 100644 index 19f6ea3..0000000 --- a/src/render/ral_types.h +++ /dev/null @@ -1,102 +0,0 @@ -/** - * @file ral_types.h - * @author your name (you@domain.com) - * @brief Struct and enum definitions for RAL - * @version 0.1 - * @date 2024-04-27 - * - * @copyright Copyright (c) 2024 - * - */ -#pragma once - -#include "darray.h" -#include "defines.h" -#include "maths_types.h" - -#define MAX_VERTEX_ATTRIBUTES 16 - -/* #ifndef RENDERER_TYPED_HANDLES */ -CORE_DEFINE_HANDLE(buffer_handle); -CORE_DEFINE_HANDLE(texture_handle); -CORE_DEFINE_HANDLE(sampler_handle); -CORE_DEFINE_HANDLE(shader_handle); -CORE_DEFINE_HANDLE(pipeline_layout_handle); -CORE_DEFINE_HANDLE(pipeline_handle); -CORE_DEFINE_HANDLE(renderpass_handle); -#define ABSENT_MODEL_HANDLE 999999999 - -// --- Shaders & Bindings - -typedef enum shader_visibility { - VISIBILITY_VERTEX = 1 << 0, - VISIBILITY_FRAGMENT = 1 << 1, - VISIBILITY_COMPUTE = 1 << 2, -} shader_visibility; - -/** @brief Describes the kind of binding a `shader_binding` is for. This changes how we create - * backing data for it. */ -typedef enum shader_binding_type { - /** - * @brief Binds a buffer to a shader - * @note Vulkan: Becomes a Storage Buffer - */ - SHADER_BINDING_BUFFER, - SHADER_BINDING_BUFFER_ARRAY, - SHADER_BINDING_TEXTURE, - SHADER_BINDING_TEXTURE_ARRAY, - SHADER_BINDING_SAMPLER, - /** - * @brief Binds raw data to a shader - * @note Vulkan: Becomes a Uniform Buffer - */ - SHADER_BINDING_BYTES, - // TODO: Acceleration Structure - SHADER_BINDING_COUNT -} shader_binding_type; - -static const char* shader_binding_type_name[] = { "BUFFER", "BUFFER ARRAY", "TEXTURE", - "TEXTURE ARRAY", "SAMPLER", "BYTES", - "COUNT" }; - -// pub trait ShaderBindable: Clone + Copy { -// fn bind_to(&self, context: &mut PipelineContext, index: u32); -// } - -typedef struct shader_binding { - const char* label; - shader_binding_type type; - shader_visibility vis; - bool stores_data; /** @brief if this is true then the shader binding has references to live data, - if false then its just being used to describe a layout and .data - should be zeroed */ - union { - struct { - buffer_handle handle; - } buffer; - struct { - void* data; - size_t size; - } bytes; - struct { - texture_handle handle; - } texture; - } data; /** @brief can store any kind of data that we can bind to a shader / descriptor set */ -} shader_binding; - -void print_shader_binding(shader_binding b); - -/** @brief A list of bindings that describe what data a shader / pipeline expects - @note This roughly correlates to a descriptor set layout in Vulkan -*/ - -// ? How to tie together materials and shaders - -// Three registers -// 1. low level graphics api calls "ral" -// 2. higher level render calls -// 3. simplified immediate mode API - -// 3 - you don't need to know how the renderer works at all -// 2 - you need to know how the overall renderer is designed -// 1 - you need to understand graphics API specifics diff --git a/src/new_render/render.c b/src/render/render.c index c180597..697a79e 100644 --- a/src/new_render/render.c +++ b/src/render/render.c @@ -18,7 +18,6 @@ #include "ral_common.h" #include "ral_impl.h" #include "ral_types.h" -#include "render_scene.h" #include "render_types.h" #include "shadows.h" #include "terrain.h" @@ -284,11 +283,12 @@ void Geometry_Destroy(Geometry* geometry) { Vertex_darray_free(geometry->vertices); } } -PUB MeshHandle Mesh_Insert(Mesh* mesh) { - return Mesh_pool_insert(Render_GetMeshPool(), mesh); -} +PUB MeshHandle Mesh_Insert(Mesh* mesh) { return Mesh_pool_insert(Render_GetMeshPool(), mesh); } PUB MaterialHandle Material_Insert(Material* material) { - return Material_pool_insert(Render_GetMaterialPool(), material); + return Material_pool_insert(Render_GetMaterialPool(), material); +} +Mesh* Mesh_Get(MeshHandle handle) { + return Mesh_pool_get(Render_GetMeshPool(), handle); } size_t ModelExtractRenderEnts(RenderEnt_darray* entities, ModelHandle model_handle, Mat4 affine, diff --git a/src/new_render/render.h b/src/render/render.h index 7fbc0a7..0aee51c 100644 --- a/src/new_render/render.h +++ b/src/render/render.h @@ -9,6 +9,7 @@ #include "ral_types.h" #include "render_types.h" #include "shadows.h" +#include "camera.h" typedef struct Renderer Renderer; typedef struct GLFWwindow GLFWwindow; @@ -27,6 +28,16 @@ typedef struct RenderCtx { Mat4 projection; } RenderCtx; +/** @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; +} RenderScene; + +PUB void SetCamera(Camera camera); +PUB void SetMainLight(DirectionalLight light); + // #define MESH_GET(h) (Mesh_pool_get(g_core.renderer->meshes, h)) // #define MATERIAL_GET(h) (Material_pool_get(g_core.renderer->material, h)) @@ -61,6 +72,7 @@ PUB ModelHandle ModelLoad(const char* debug_name, const char* filepath); PUB Mesh Mesh_Create(Geometry* geometry, bool free_on_upload); PUB void Mesh_Delete(Mesh* mesh); +Mesh* Mesh_Get(MeshHandle handle); void Geometry_Destroy(Geometry* geometry); MeshHandle Mesh_Insert(Mesh* mesh); MaterialHandle Material_Insert(Material* material); @@ -95,3 +107,40 @@ Material_pool* Render_GetMaterialPool(); // --- Setters void Render_SetRenderMode(RenderMode mode); + +// ------------------------------------------------- + +// 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); + +// 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; +// } diff --git a/src/new_render/render_types.h b/src/render/render_types.h index 5fdca8a..5fdca8a 100644 --- a/src/new_render/render_types.h +++ b/src/render/render_types.h diff --git a/src/render/renderpasses.c b/src/render/renderpasses.c deleted file mode 100644 index b93d487..0000000 --- a/src/render/renderpasses.c +++ /dev/null @@ -1,140 +0,0 @@ -/** - * @file renderpasses.c - * @author your name (you@domain.com) - * @brief - * @version 0.1 - * @date 2024-06-22 - * - * @copyright Copyright (c) 2024 - * - */ - -#include "renderpasses.h" -#include "file.h" -#include "log.h" -#include "maths_types.h" -#include "ral.h" -#include "ral_types.h" - -#define SHADOW_WIDTH 1000 -#define SHADOW_HEIGHT 1000 - -shader_data_layout debug_quad_layout(void* data) { - debug_quad_uniform* d = data; - bool has_data = data != NULL; - - shader_binding b1 = { .label = "depthMap", - .type = SHADER_BINDING_TEXTURE, - .stores_data = has_data }; - if (has_data) { - b1.data.texture.handle = d->depthMap; - } - return ( - shader_data_layout){ .name = "debug quad uniforms", .bindings = { b1 }, .bindings_count = 1 }; -} - -gpu_pipeline* debug_quad_pipeline_create() { - gpu_renderpass_desc rpass_desc = { .default_framebuffer = true }; - gpu_renderpass* rpass = gpu_renderpass_create(&rpass_desc); - shader_data shader_layout = { .data = NULL, .shader_data_get_layout = debug_quad_layout }; - struct graphics_pipeline_desc desc = { .debug_name = "Shadow maps debug quad", - .vertex_desc = static_3d_vertex_description(), - .data_layouts = { shader_layout }, - .data_layouts_count = 1, - .vs = shader_quick_load("assets/shaders/debug_quad.vert"), - .fs = shader_quick_load("assets/shaders/debug_quad.frag"), - .renderpass = rpass, - .wireframe = false }; - - return gpu_graphics_pipeline_create(desc); -} - -void ren_shadowmaps_init(ren_shadowmaps* storage) { - storage->rpass = shadowmaps_renderpass_create(); - storage->static_pipeline = shadowmaps_pipeline_create(storage->rpass); - storage->debug_quad = debug_quad_pipeline_create(); - storage->depth_tex = storage->rpass->description.depth_stencil; -} - -gpu_renderpass* shadowmaps_renderpass_create() { - // Create depthmap texture - u32x2 extents = u32x2(SHADOW_WIDTH, SHADOW_HEIGHT); - texture_desc depthmap_desc = { .extents = extents, - .format = CEL_TEXTURE_FORMAT_DEPTH_DEFAULT, - .tex_type = CEL_TEXTURE_TYPE_2D }; - texture_handle depthmap = gpu_texture_create(depthmap_desc, false, NULL); - - gpu_renderpass_desc shadows_desc = { .default_framebuffer = false, - .has_color_target = false, - .has_depth_stencil = true, - .depth_stencil = depthmap }; - return gpu_renderpass_create(&shadows_desc); -} - -// == shader bindings - -shader_data_layout model_uniform_layout(void* data) { - bool has_data = data != NULL; - - shader_binding b1 = { .label = "Model", - .type = SHADER_BINDING_BYTES, - .stores_data = has_data, - .data = { .bytes.size = sizeof(model_uniform) } }; - if (has_data) { - b1.data.bytes.data = data; - } - return (shader_data_layout){ .name = "model_uniform", .bindings = { b1 }, .bindings_count = 1 }; -} -shader_data_layout lightspace_uniform_layout(void* data) { - bool has_data = data != NULL; - - shader_binding b1 = { .label = "LightSpace", - .type = SHADER_BINDING_BYTES, - .stores_data = has_data, - .data = { .bytes.size = sizeof(lightspace_tf_uniform) } }; - if (has_data) { - b1.data.bytes.data = data; - } - return (shader_data_layout){ .name = "lightspace_tf_uniform", - .bindings = { b1 }, - .bindings_count = 1 }; -} - -// ================== - -gpu_pipeline* shadowmaps_pipeline_create(gpu_renderpass* rpass) { - arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024); - - str8 vert_path = str8lit("assets/shaders/shadows.vert"); - str8 frag_path = str8lit("assets/shaders/shadows.frag"); - str8_opt vertex_shader = str8_from_file(&scratch, vert_path); - str8_opt fragment_shader = str8_from_file(&scratch, frag_path); - if (!vertex_shader.has_value || !fragment_shader.has_value) { - ERROR_EXIT("Failed to load shaders from disk"); - } - - // We'll have two data layouts. 1. for the light-space transform, and 2. for the model matrix - shader_data model_uniform = { .data = NULL, .shader_data_get_layout = &model_uniform_layout }; - shader_data lightspace_uniform = { .data = NULL, - .shader_data_get_layout = &lightspace_uniform_layout }; - - struct graphics_pipeline_desc desc = { .debug_name = "Shadowmap drawing pipeline", - .vertex_desc = static_3d_vertex_description(), - .data_layouts = { model_uniform, lightspace_uniform }, - .data_layouts_count = 2, - .vs = { .debug_name = "Shadows Vert shader", - .filepath = vert_path, - .code = vertex_shader.contents, - .is_spirv = true }, - .fs = { .debug_name = "Shadows Frag shader", - .filepath = frag_path, - .code = fragment_shader.contents, - .is_spirv = true }, - .renderpass = rpass }; - - arena_free_storage(&scratch); - return gpu_graphics_pipeline_create(desc); -} - -void renderpass_shadowmap_execute(gpu_renderpass* pass, render_entity* entities, - size_t entity_count) {} diff --git a/src/render/renderpasses.h b/src/render/renderpasses.h deleted file mode 100644 index 1ceea6c..0000000 --- a/src/render/renderpasses.h +++ /dev/null @@ -1,56 +0,0 @@ -/** - * @file renderpasses.h - * @author your name (you@domain.com) - * @brief Built-in renderpasses to the engine - * @version 0.1 - * @date 2024-04-28 - * - * @copyright Copyright (c) 2024 - * - */ -#pragma once -#include "ral.h" -#include "ral_types.h" -#include "render_types.h" - -// Shadowmap pass -// Blinn-phong pass -// Unlit pass -// Debug visualisations pass - -// Don't need to pass in *anything*. -gpu_renderpass* renderpass_blinn_phong_create(); -void renderpass_blinn_phong_execute(gpu_renderpass* pass, render_entity* entities, - size_t entity_count); - -typedef struct ren_shadowmaps { - u32 width; - u32 height; - gpu_renderpass* rpass; - gpu_pipeline* static_pipeline; - gpu_pipeline* debug_quad; - texture_handle depth_tex; -} ren_shadowmaps; - -typedef struct model_uniform { - mat4 model; -} model_uniform; -typedef struct lightspace_tf_uniform { - mat4 lightSpaceMatrix; -} lightspace_tf_uniform; - -typedef struct debug_quad_uniform { - texture_handle depthMap; -} debug_quad_uniform; - -shader_data_layout model_uniform_layout(void* data); -shader_data_layout lightspace_uniform_layout(void* data); -shader_data_layout debug_quad_layout(void* data); - -void ren_shadowmaps_init(ren_shadowmaps* storage); - -gpu_renderpass* shadowmaps_renderpass_create(); -gpu_pipeline* shadowmaps_pipeline_create(gpu_renderpass* rpass); - -void renderpass_shadowmap_execute(gpu_renderpass* pass, render_entity* entities, - size_t entity_count); diff --git a/src/new_render/shader_layouts.h b/src/render/shader_layouts.h index 09cf129..09cf129 100644 --- a/src/new_render/shader_layouts.h +++ b/src/render/shader_layouts.h diff --git a/src/new_render/shadows.c b/src/render/shadows.c index 1ca9119..18a5f7a 100644 --- a/src/new_render/shadows.c +++ b/src/render/shadows.c @@ -10,7 +10,6 @@ #include "ral_impl.h" #include "ral_types.h" #include "render.h" -#include "render_scene.h" #include "render_types.h" #include "str.h" diff --git a/src/new_render/shadows.h b/src/render/shadows.h index 0482d10..0482d10 100644 --- a/src/new_render/shadows.h +++ b/src/render/shadows.h diff --git a/src/new_render/skybox.c b/src/render/skybox.c index cc5797f..cc5797f 100644 --- a/src/new_render/skybox.c +++ b/src/render/skybox.c diff --git a/src/new_render/skybox.h b/src/render/skybox.h index c2ef3a2..c2ef3a2 100644 --- a/src/new_render/skybox.h +++ b/src/render/skybox.h diff --git a/src/resources/gltf.c b/src/resources/gltf.c index ce6a83b..01291ea 100644 --- a/src/resources/gltf.c +++ b/src/resources/gltf.c @@ -554,7 +554,8 @@ size_t GLTF_LoadMaterials(cgltf_data *data, Str8 relative_path, Material_darray } else { our_material.albedo_map = Render_GetWhiteTexture(); WARN("GLTF model has no albedo map"); - our_material.base_colour = vec3_create(pbr.base_color_factor[0],pbr.base_color_factor[1], pbr.base_color_factor[2]); + our_material.base_colour = + vec3_create(pbr.base_color_factor[0], pbr.base_color_factor[1], pbr.base_color_factor[2]); } // -- metallic diff --git a/src/std/mem.c b/src/std/mem.c index a537330..1f9078b 100644 --- a/src/std/mem.c +++ b/src/std/mem.c @@ -101,7 +101,7 @@ void* void_pool_alloc(void_pool* pool, u32* out_raw_handle) { // What index does this become? uintptr_t start = (uintptr_t)pool->backing_buffer; uintptr_t cur = (uintptr_t)free_node; - TRACE("%ld %ld ", start, cur); + // TRACE("%ld %ld ", start, cur); assert(cur > start); u32 index = (u32)((cur - start) / pool->entry_size); /* printf("Index %d\n", index); */ @@ -132,4 +132,4 @@ u32 void_pool_insert(void_pool* pool, void* item) { void* item_dest = void_pool_alloc(pool, &raw_handle); memcpy(item_dest, item, pool->entry_size); return raw_handle; -}
\ No newline at end of file +} diff --git a/src/systems/grid.c b/src/systems/grid.c index 14722e3..8a6f4f6 100644 --- a/src/systems/grid.c +++ b/src/systems/grid.c @@ -8,7 +8,6 @@ #include "ral_impl.h" #include "ral_types.h" #include "render.h" -#include "render_scene.h" #include "render_types.h" #include "shader_layouts.h" @@ -82,4 +81,4 @@ void Grid_Execute(Grid_Storage* storage) { GPU_EncodeSetIndexBuffer(enc, storage->plane_indices); GPU_EncodeDrawIndexed(enc, 6); GPU_CmdEncoder_EndRender(enc); -}
\ No newline at end of file +} diff --git a/src/systems/terrain.c b/src/systems/terrain.c index bde4b4d..ead7700 100644 --- a/src/systems/terrain.c +++ b/src/systems/terrain.c @@ -12,7 +12,6 @@ #include "ral_impl.h" #include "ral_types.h" #include "render.h" -#include "render_scene.h" #include "shader_layouts.h" #include "str.h" @@ -202,4 +201,4 @@ ShaderDataLayout TerrainUniforms_GetLayout(void* data) { b1.data.texture.handle = d->tex_slot_1; } return (ShaderDataLayout){ .bindings = { b1 }, .binding_count = 1 }; -}
\ No newline at end of file +} |