From 438aaebcbc5c963d378d297bfb13e2af24b12084 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 18 Jul 2026 15:19:07 +0400 Subject: feat(render): support full-scene 32-bit indices --- apps/fparkan-game/src/main.rs | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'apps/fparkan-game') diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index af5d7ed..850b509 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -465,28 +465,24 @@ fn append_static_preview_component( component: VulkanStaticMesh, selector_remap: &[(u16, u16)], ) -> Result<(), String> { - let vertex_base = u16::try_from(target.vertices.len()).map_err(|_| { - "static preview exceeds the available 16-bit vertex index space".to_string() - })?; + let vertex_base = u32::try_from(target.vertices.len()) + .map_err(|_| "static preview vertex count exceeds u32".to_string())?; let first_index_base = u32::try_from(target.indices.len()) .map_err(|_| "static preview index count exceeds u32".to_string())?; target .vertices .len() .checked_add(component.vertices.len()) - .filter(|count| *count <= usize::from(u16::MAX) + 1) - .ok_or_else(|| { - "static preview exceeds the available 16-bit vertex index space".to_string() - })?; + .ok_or_else(|| "static preview vertex count exceeds addressable memory".to_string())?; target.vertices.extend(component.vertices); target.indices.extend( component .indices .into_iter() .map(|index| { - index.checked_add(vertex_base).ok_or_else(|| { - "static preview exceeds the available 16-bit vertex index space".to_string() - }) + index + .checked_add(vertex_base) + .ok_or_else(|| "static preview vertex index exceeds u32".to_string()) }) .collect::, _>>()?, ); @@ -1292,6 +1288,29 @@ mod tests { Ok(()) } + #[test] + fn static_preview_component_merge_keeps_indices_above_u16() -> Result<(), String> { + let vertex = fparkan_render_vulkan::VulkanStaticVertex { + position: [0.0, 0.0, 0.0], + color: [1.0, 1.0, 1.0], + uv: [0.0, 0.0], + }; + let mut merged = VulkanStaticMesh { + vertices: vec![vertex; usize::from(u16::MAX) + 1], + indices: Vec::new(), + draw_ranges: Vec::new(), + }; + + append_static_preview_component( + &mut merged, + VulkanStaticMesh::smoke_triangle(), + &[(0, 0)], + )?; + + assert_eq!(merged.indices, vec![65_536, 65_537, 65_538]); + Ok(()) + } + #[test] fn render_commands_follow_snapshot_order() -> Result<(), String> { let snapshot = WorldSnapshot { -- cgit v1.2.3