Added: - Updated `.gitignore` to ignore the `[Bb]uild/` directory. - Additional tasks added to the roadmap in `README.md` for light unit standardization and GPU backend support. Changed: - Removed line in `settings.json` that disabled error squiggles for C/C++ code. - Modified `Triangle.h` to include `material_id` in `triangle_t` and reorganized properties. - Reordered parameters in `triangle_collection_init` for clarity. - Updated `shading_context_t` in `Material.h` and added size parameter to `material_create`. - Streamlined initialization in `scene_init` and updated `scene_free` for proper resource management. - Updated `window_create` in `Window.h` to accept a `render_job_t` parameter. - Introduced `renderer_start` in `Renderer.c` to handle rendering jobs and optimized pixel rendering logic.
66 lines
1.4 KiB
C
66 lines
1.4 KiB
C
#include "Rendering/Scene.h"
|
|
|
|
bool scene_init(scene_t* scene, uint64_t triangle_count, uint8_t material_count, uint32_t punctual_light_count)
|
|
{
|
|
scene_t temp = {0};
|
|
|
|
if (!triangle_collection_init(&temp.triangles, triangle_count))
|
|
{
|
|
goto triangle_failed;
|
|
}
|
|
|
|
if (!material_collection_init(material_count, &temp.materials))
|
|
{
|
|
goto material_failed;
|
|
}
|
|
|
|
if (!light_collection_create(punctual_light_count, 16, &temp.lights)) // NOTE: We just fixed the max directional light count to 16.
|
|
{
|
|
goto light_failed;
|
|
}
|
|
|
|
temp.camera = camera_create(
|
|
(vec3s){0.0f, 0.0f, 5.0f},
|
|
glms_quat_identity(),
|
|
0.025f,
|
|
0.036f,
|
|
16.0f / 9.0f
|
|
);
|
|
|
|
*scene = temp;
|
|
return true;
|
|
|
|
light_failed:
|
|
material_collection_free(&temp.materials);
|
|
material_failed:
|
|
triangle_collection_free(&temp.triangles);
|
|
triangle_failed:
|
|
return false;
|
|
}
|
|
|
|
bool scene_build_bvh(scene_t* scene)
|
|
{
|
|
if (scene == NULL || scene->triangles.count == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bvh_tree_t bvh_tree = {0};
|
|
if (!bvh_tree_init(&bvh_tree, &scene->triangles))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bvh_tree_build(&bvh_tree);
|
|
scene->bvh_tree = bvh_tree;
|
|
return true;
|
|
}
|
|
|
|
void scene_free(scene_t* scene)
|
|
{
|
|
bvh_tree_free(&scene->bvh_tree);
|
|
triangle_collection_free(&scene->triangles);
|
|
material_collection_free(&scene->materials);
|
|
light_collection_free(&scene->lights);
|
|
}
|