Skip to main content

render_scene_composed

Function render_scene_composed 

Source
pub fn render_scene_composed(
    fb: &mut [u32],
    zb: &mut [f32],
    pitch_pixels: usize,
    width: u32,
    height: u32,
    pool: &mut ScratchPool,
    scene: &mut Scene,
    camera: &Camera,
    settings: &OpticastSettings,
    sky_color: u32,
    sky: Option<&Sky>,
) -> RenderOutcome
Expand description

Render every grid in scene with per-grid temporary buffers + z-buffer composition. The canonical multi-grid scene render path.

Algorithm:

  1. Caller pre-fills fb with the desired sky colour and zb with f32::INFINITY (so any rendered pixel wins the initial composition).
  2. For each grid, allocate a temporary (temp_fb, temp_zb) of the same size, pre-fill them with sky / INFINITY, and run opticast into them via a ScalarRasterizer over the temporary buffers AND the grid’s combined-world view (S4.0).
  3. Merge the temporary buffers into the shared (fb, zb) via compose_into — closer pixels (smaller z) win.

Pixel correctness across overlapping grids: sky pixels emerge with z = gxmax / i32::MAX (a very large value), so they always lose to any hit. Hits compete on actual perpendicular distance — the closer grid’s surface is what gets composited.

pitch_pixels is the framebuffer’s row stride in pixels (×4 for bytes). width × height must equal fb.len() / zb.len(). sky is the optional textured sky resource the rasterizer threads through to phase_startsky; None ⇒ solid pool.skycast fill.

Heap allocation per call: two Vec allocations per grid (a temp framebuffer and zbuffer). For repeated frame rendering an owned scratch struct that pre-allocates these is the obvious optimisation; deferred until profiling shows it matters.