Struct VisibilityQuery

Source
pub struct VisibilityQuery<'a, T>
where T: Copy,
{ /* private fields */ }
Expand description

Reusable, allocation-free visible-ID storage and per-frame workload counts.

IDs are caller-defined Copy values, retained in submission order without deduplication. The borrowed slice bounds storage, not classification work: every Self::test is counted even when storage is full or empty. Always inspect VisibilityQueryStats::is_truncated before treating IDs as complete. No scene data is owned or changed. There is no implicit clock or frame reset.

use ferravex_graphics::Bounds;
use ferravex_render::{Mat4, Vec3};
use ferravex_render::visibility::{Visibility, VisibilityQuery};
let bounds = Bounds { min: -Vec3::ONE, max: Vec3::ONE };
let mut storage = [0_u64; 1];
let mut query = VisibilityQuery::new(&mut storage, None, None, Default::default())?;
assert_eq!(query.capacity(), 1);
assert_eq!(query.test(7, bounds, Mat4::IDENTITY), Visibility::Visible);
assert!(!query.stats().is_truncated());
// Full storage does not change the object's classification.
assert_eq!(query.test(8, bounds, Mat4::IDENTITY), Visibility::Visible);
assert_eq!(query.visible_ids(), &[7]);
assert_eq!(query.stats().visibility.visible, 2);
assert_eq!(query.stats().overflow, 1);
query.begin_frame(None, None, Default::default())?;
assert!(query.visible_ids().is_empty());
assert_eq!(query.stats().visibility.tested, 0);

Implementations§

Source§

impl<'a, T> VisibilityQuery<'a, T>
where T: Copy,

Source

pub fn new( storage: &'a mut [T], frustum: Option<Frustum>, eye: Option<Vec3>, settings: VisibilitySettings, ) -> Result<VisibilityQuery<'a, T>, VisibilityQueryError>

Start an empty frame in initialized caller storage, including zero capacity. Invalid settings/eye return an error without writing to the slice.

Source

pub fn begin_frame( &mut self, frustum: Option<Frustum>, eye: Option<Vec3>, settings: VisibilitySettings, ) -> Result<(), VisibilityQueryError>

Replace the camera/settings and reset IDs and counters, reusing storage. On error all previous configuration, IDs and counters remain unchanged. Reset hides stale IDs; it does not overwrite unused storage or allocate.

Source

pub fn test(&mut self, id: T, bounds: Bounds, model: Mat4) -> Visibility

Classify and count an object, retaining its ID when visible and space exists. Overflow increments stats().overflow but still returns Visible, so a caller can process the object immediately instead of dropping visible work.

Source

pub fn visible_ids(&self) -> &[T]

Only this frame’s stored visible IDs, in submission order.

Source

pub fn capacity(&self) -> usize

Maximum stored IDs per frame; equal to the original slice length.

Source

pub fn stats(&self) -> VisibilityQueryStats

Copy of this frame’s counters, including classifications after storage fills.

Trait Implementations§

Source§

impl<'a, T> Debug for VisibilityQuery<'a, T>
where T: Debug + Copy,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for VisibilityQuery<'a, T>

§

impl<'a, T> RefUnwindSafe for VisibilityQuery<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for VisibilityQuery<'a, T>
where T: Send,

§

impl<'a, T> Sync for VisibilityQuery<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for VisibilityQuery<'a, T>

§

impl<'a, T> !UnwindSafe for VisibilityQuery<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.