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
This commit is contained in:
Mariusz Kryński 2021-10-28 22:53:22 +00:00
parent 015617a774
commit dacc9d03a7
3 changed files with 4 additions and 2 deletions

View file

@ -797,7 +797,7 @@ impl Draw<Shadow> for DrawShadowMesh {
let gpu_mesh = meshes.into_inner().get(mesh_handle).unwrap(); let gpu_mesh = meshes.into_inner().get(mesh_handle).unwrap();
pass.set_vertex_buffer(0, gpu_mesh.vertex_buffer.slice(..)); pass.set_vertex_buffer(0, gpu_mesh.vertex_buffer.slice(..));
if let Some(index_info) = &gpu_mesh.index_info { 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); pass.draw_indexed(0..index_info.count, 0, 0..1);
} else { } else {
panic!("non-indexed drawing not supported yet") panic!("non-indexed drawing not supported yet")

View file

@ -685,7 +685,7 @@ impl RenderCommand<Transparent3d> for DrawMesh {
let gpu_mesh = meshes.into_inner().get(mesh_handle).unwrap(); let gpu_mesh = meshes.into_inner().get(mesh_handle).unwrap();
pass.set_vertex_buffer(0, gpu_mesh.vertex_buffer.slice(..)); pass.set_vertex_buffer(0, gpu_mesh.vertex_buffer.slice(..));
if let Some(index_info) = &gpu_mesh.index_info { 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); pass.draw_indexed(0..index_info.count, 0, 0..1);
} else { } else {
panic!("non-indexed drawing not supported yet") panic!("non-indexed drawing not supported yet")

View file

@ -538,6 +538,7 @@ pub struct GpuMesh {
pub struct GpuIndexInfo { pub struct GpuIndexInfo {
pub buffer: Buffer, pub buffer: Buffer,
pub count: u32, pub count: u32,
pub index_format: IndexFormat,
} }
impl RenderAsset for Mesh { impl RenderAsset for Mesh {
@ -567,6 +568,7 @@ impl RenderAsset for Mesh {
label: None, label: None,
}), }),
count: mesh.indices().unwrap().len() as u32, count: mesh.indices().unwrap().len() as u32,
index_format: mesh.indices().unwrap().into(),
}); });
Ok(GpuMesh { Ok(GpuMesh {