pub struct Bvh { /* private fields */ }Expand description
A reference-counted standalone BVH (RTCBVH). Build target for
Bvh::build_scoped.
Not Clone: the result of a build borrows the Bvh exclusively, and a
second handle could rebuild and free the arena out from under a live result.
Implementations§
Source§impl Bvh
impl Bvh
Sourcepub fn build_scoped<B, F, R>(
&mut self,
config: &BuildConfig,
primitives: &mut Vec<BuildPrimitive>,
builder: &B,
f: F,
) -> Result<R, Error>
pub fn build_scoped<B, F, R>( &mut self, config: &BuildConfig, primitives: &mut Vec<BuildPrimitive>, builder: &B, f: F, ) -> Result<R, Error>
Build a BVH over primitives inside a generative scope. The result and
any NodePtr handles cannot escape f; return owned data
(counts, a Vec, a copied-out tree) instead.
The generative brand makes escaping a handle a compile error, which is what prevents resolving a handle against a different build:
ⓘ
use embree3::{
Allocator, Bvh, BvhBuilder, BvhNode, BuildConfig, BuildPrimitive, ChildBounds,
Children, Device,
};
#[derive(Clone, Copy)]
struct Node {
n: u32,
}
unsafe impl BvhNode for Node {}
struct B;
impl BvhBuilder for B {
type Node<'id> = Node;
const MAX_CHILDREN: usize = 2;
fn create_node<'id>(&self, a: &Allocator<'id>, _n: usize) -> &'id mut Node {
a.alloc(Node { n: 0 })
}
fn set_children<'id>(&self, _n: &mut Node, _c: Children<'id, Node>) {}
fn set_bounds<'id>(&self, _n: &mut Node, _b: ChildBounds<'_>) {}
fn create_leaf<'id>(&self, a: &Allocator<'id>, _p: &[BuildPrimitive]) -> &'id mut Node {
a.alloc(Node { n: 0 })
}
}
let device = Device::new().unwrap();
let mut bvh = device.create_bvh().unwrap();
let mut prims: Vec<BuildPrimitive> = Vec::new();
// ERROR: a branded handle cannot escape the generative scope.
let _escaped = bvh.build_scoped(&BuildConfig::default(), &mut prims, &B, |r| r.root_ptr());The cross-build case directly: a handle from one build cannot be resolved by a nested, independent build (their generative brands differ):
ⓘ
use embree3::{
Allocator, Bvh, BvhBuilder, BvhNode, BuildConfig, BuildPrimitive, ChildBounds,
Children, Device,
};
#[derive(Clone, Copy)]
struct Node {
n: u32,
}
unsafe impl BvhNode for Node {}
struct B;
impl BvhBuilder for B {
type Node<'id> = Node;
const MAX_CHILDREN: usize = 2;
fn create_node<'id>(&self, a: &Allocator<'id>, _n: usize) -> &'id mut Node {
a.alloc(Node { n: 0 })
}
fn set_children<'id>(&self, _n: &mut Node, _c: Children<'id, Node>) {}
fn set_bounds<'id>(&self, _n: &mut Node, _b: ChildBounds<'_>) {}
fn create_leaf<'id>(&self, a: &Allocator<'id>, _p: &[BuildPrimitive]) -> &'id mut Node {
a.alloc(Node { n: 0 })
}
}
let device = Device::new().unwrap();
let mut outer = device.create_bvh().unwrap();
let mut inner = device.create_bvh().unwrap();
let mut po: Vec<BuildPrimitive> = Vec::new();
let mut pi: Vec<BuildPrimitive> = Vec::new();
let cfg = BuildConfig::default();
outer.build_scoped(&cfg, &mut po, &B, |ra| {
// ERROR: `ra`'s handle has a different brand than `rb`'s scope, so it cannot be
// passed to `rb.resolve`. (Returns a `Copy` field to isolate that one error.)
inner.build_scoped(&cfg, &mut pi, &B, |rb| {
rb.resolve(ra.root_ptr().unwrap()).n
})
}).unwrap().unwrap();Trait Implementations§
Auto Trait Implementations§
impl !Send for Bvh
impl !Sync for Bvh
impl Freeze for Bvh
impl RefUnwindSafe for Bvh
impl Unpin for Bvh
impl UnsafeUnpin for Bvh
impl UnwindSafe for Bvh
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more