X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=bvh.h;fp=bvh.h;h=9e4528604d59c8cf205f20d3d172b671102085e1;hb=a3c10b9dec1ed7136721695033ebeef30717f249;hp=84f4c6b7d675c7b1cfdf9f914722b572424aa347;hpb=859f92700a49095740474842730af9ede3430c3b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/bvh.h b/bvh.h index 84f4c6b..9e45286 100644 --- a/bvh.h +++ b/bvh.h @@ -32,6 +32,7 @@ struct bh_tree bh_system *system; void *user; + u32 max_per_leaf; struct bh_node { @@ -77,6 +78,9 @@ VG_STATIC void bh_subdivide( bh_tree *bh, u32 inode ) { bh_node *node = &bh->nodes[ inode ]; + if( node->count <= bh->max_per_leaf ) + return; + v3f extent; v3_sub( node->bbx[1], node->bbx[0], extent ); @@ -135,8 +139,10 @@ VG_STATIC void bh_subdivide( bh_tree *bh, u32 inode ) } VG_STATIC bh_tree *bh_create( void *lin_alloc, bh_system *system, - void *user, u32 item_count ) + void *user, u32 item_count, u32 max_per_leaf ) { + assert( max_per_leaf > 0 ); + if( item_count == 0 ) { bh_tree *bh = vg_linear_alloc( lin_alloc, sizeof(bh_tree) ); @@ -150,6 +156,7 @@ VG_STATIC bh_tree *bh_create( void *lin_alloc, bh_system *system, bh_tree *bh = vg_linear_alloc( lin_alloc, totsize ); bh->system = system; bh->user = user; + bh->max_per_leaf = max_per_leaf; bh_node *root = &bh->nodes[0]; bh->node_count = 1;