mod common;
use std::sync::{Arc, Mutex};
#[test]
fn capturing_intersect_filter_is_invoked_with_live_state() {
let deviec = common::device();
let mut scene = deviec.create_scene().unwrap();
let probe: Arc<Mutex<Vec<u32>>> = Arc::new(Mutex::new(vec![]));
let probe_in_cb = probe.clone();
let mut tri = common::unit_triangle(&deviec);
tri.set_intersect_filter_function::<_, ()>(
move |_ray, _hit, valid, _ctx, _user: Option<&()>| {
probe_in_cb
.lock()
.unwrap()
.push(0xF11A_u32 ^ valid.len() as u32);
},
);
let tri = tri.commit();
scene.attach_geometry(&tri);
scene.commit();
common::clobber_stack();
let hit = common::cast_center_ray(&scene);
assert!(hit.hit.is_valid(), "ray should hit the triangle");
assert_eq!(
*probe.lock().unwrap(),
vec![0xF11A_u32 ^ 1],
"filter closure must run exactly once with N=1 and live captured state"
);
}