Function draw_residents_checked

Source
pub fn draw_residents_checked(
    instances: &[(&ResidentMesh, Mat4)],
) -> InstanceGroupReport
Expand description

Atomically submit a caller slice of resident mesh/model pairs using the current camera, material, lighting, visibility and shadow settings.

All entries are validated before recording, including invisible entries. The first validation error in input order wins over aggregate capacity. Otherwise capacity counts only instances that would actually be recorded (visible or shadow-only); its error index is the first entry that would exceed the remaining frame budget. Empty input succeeds without validation. Skinned residents require palettes and are rejected, as by draw_resident_checked. Borrowed ResidentMesh handles guarantee live, already-validated geometry; cloned/duplicate handles are valid and each pair is a separate instance. No raw identity lookup or new geometry is needed.

Failure leaves every frame buffer’s contents, length, capacity, mesh/material lifetimes and visibility counters unchanged. It increments exactly one saturating RetainedRejections activity counter; report.rejected is the entire slice length. Success records in caller order through the existing single-instance path, with its adjacent batching and later opaque regrouping. Valid complete culls are reported separately and are not rejections.

Preflight uses O(n) work and O(1) stack storage, with no scratch allocation. Commit repeats preparation/classification; the caller bounds work by slice length. Buffers grow normally on success and retain warmed capacity across frames. Atomicity covers reported validation/capacity errors, not allocation failures or unwinding/destructor panics; no panic rollback is promised.

§Runnable composition recipe

Retain authored geometry once, then submit each frame’s caller-owned model array as a group. This headless recipe uses the same recorder as game hosts; it does not require a window or replace their rendering implementation.

use ferravex_math::affine::PreparedAffine3D;
use ferravex_render::{Mat4, Vec3, WHITE, BLACK, clear_background,
    set_default_camera, mesh::Mesh3d,
    retained::{ResidentMesh, draw_residents_checked, telemetry_snapshot}};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let resident = ResidentMesh::try_new(&Mesh3d::cuboid(Vec3::ONE, WHITE).mesh)?;
    let clone = resident.clone(); // shares the validated geometry
    let authored = PreparedAffine3D::try_new(Mat4::from_scale(
        Vec3::new(-2.0, 3.0, 1.0)))?;
    clear_background(BLACK);
    set_default_camera();
    let instances = [(&resident, authored.model()), (&clone, Mat4::IDENTITY)];
    let report = draw_residents_checked(&instances);
    assert_eq!((report.accepted, report.rejected, report.visible), (2, 0, 2));
    assert_eq!(report.culled, 0);
    assert!(report.error.is_none());
    let before = telemetry_snapshot();
    let failed = draw_residents_checked(&[
        (&resident, Mat4::IDENTITY), (&resident, Mat4::ZERO)]);
    assert_eq!((failed.accepted, failed.rejected), (0, 2));
    assert_eq!(failed.error.unwrap().index, 1);
    assert_eq!(telemetry_snapshot().instances, before.instances);
    clear_background(BLACK); // frame reset reuses recording storage
    let next = draw_residents_checked(&instances);
    if let Some(error) = next.error { return Err(error.into()); }
    assert_eq!(next.accepted, 2);
    Ok(())
}