#ifndef BVH_H #define BVH_H #include "Geometry/AABB.h" #include "Geometry/Triangle.h" #define SAH_BIN_COUNT 8 // Number of bins for SAH #define SAH_TRAVERSAL_COST 1.0f // Cost of traversing a node #define SAH_INTERSECTION_COST 10.0f // Cost of intersecting a triangle typedef struct { aabb_t bounds; uint64_t start_index; uint64_t primitive_count; uint64_t left_child_offset; uint64_t right_child_offset; } bvh_node_t; typedef struct { uint64_t node_count; // Current number of nodes used uint64_t node_capacity; // Allocated capacity for nodes uint64_t primitive_count; // Total number of primitives (should match triangles->count) bvh_node_t* nodes; uint64_t* primitive_indices; // Buffer of indices mapping to the original triangle_collection_t buffer const triangle_collection_t* triangles; // Pointer to the original triangle data (read-only access) } bvh_tree_t; bool bvh_tree_init(bvh_tree_t* bvh_tree, const triangle_collection_t* triangles); bool bvh_tree_build(bvh_tree_t* bvh_tree); void bvh_tree_free(bvh_tree_t* bvh_tree); #endif // BVH_H