From dacc9d03a70b5b3519923519ccb63dae7195163e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Kry=C5=84ski?= Date: Thu, 28 Oct 2021 22:53:22 +0000 Subject: [PATCH] Add support for IndexFormat::Uint16 (#2990) # Objective while testing wgpu/WebGL on mobile GPU I've noticed bevy always forces vertex index format to 32bit (and ignores mesh settings). ## Solution the solution is to pass proper vertex index format in GpuIndexInfo to render_pass --- pipelined/bevy_pbr2/src/render/light.rs | 2 +- pipelined/bevy_pbr2/src/render/mod.rs | 2 +- pipelined/bevy_render2/src/mesh/mesh/mod.rs | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pipelined/bevy_pbr2/src/render/light.rs b/pipelined/bevy_pbr2/src/render/light.rs index 98b714ff58060..bd1a91c453bde 100644 --- a/pipelined/bevy_pbr2/src/render/light.rs +++ b/pipelined/bevy_pbr2/src/render/light.rs @@ -797,7 +797,7 @@ impl Draw for DrawShadowMesh { let gpu_mesh = meshes.into_inner().get(mesh_handle).unwrap(); pass.set_vertex_buffer(0, gpu_mesh.vertex_buffer.slice(..)); if let Some(index_info) = &gpu_mesh.index_info { - pass.set_index_buffer(index_info.buffer.slice(..), 0, IndexFormat::Uint32); + pass.set_index_buffer(index_info.buffer.slice(..), 0, index_info.index_format); pass.draw_indexed(0..index_info.count, 0, 0..1); } else { panic!("non-indexed drawing not supported yet") diff --git a/pipelined/bevy_pbr2/src/render/mod.rs b/pipelined/bevy_pbr2/src/render/mod.rs index 3125ca2a28fb8..183351cb970f9 100644 --- a/pipelined/bevy_pbr2/src/render/mod.rs +++ b/pipelined/bevy_pbr2/src/render/mod.rs @@ -685,7 +685,7 @@ impl RenderCommand for DrawMesh { let gpu_mesh = meshes.into_inner().get(mesh_handle).unwrap(); pass.set_vertex_buffer(0, gpu_mesh.vertex_buffer.slice(..)); if let Some(index_info) = &gpu_mesh.index_info { - pass.set_index_buffer(index_info.buffer.slice(..), 0, IndexFormat::Uint32); + pass.set_index_buffer(index_info.buffer.slice(..), 0, index_info.index_format); pass.draw_indexed(0..index_info.count, 0, 0..1); } else { panic!("non-indexed drawing not supported yet") diff --git a/pipelined/bevy_render2/src/mesh/mesh/mod.rs b/pipelined/bevy_render2/src/mesh/mesh/mod.rs index ae2da3f66c3b7..72f1e29a92c17 100644 --- a/pipelined/bevy_render2/src/mesh/mesh/mod.rs +++ b/pipelined/bevy_render2/src/mesh/mesh/mod.rs @@ -538,6 +538,7 @@ pub struct GpuMesh { pub struct GpuIndexInfo { pub buffer: Buffer, pub count: u32, + pub index_format: IndexFormat, } impl RenderAsset for Mesh { @@ -567,6 +568,7 @@ impl RenderAsset for Mesh { label: None, }), count: mesh.indices().unwrap().len() as u32, + index_format: mesh.indices().unwrap().into(), }); Ok(GpuMesh {