[GLES] Always use instanced methods to workaround for instance attributes when rendering a single instance

This commit is contained in:
Andreas Reich 2023-03-18 16:50:44 +01:00 committed by Josh Groves
parent f99b37e87e
commit ca9341b988

View File

@ -164,18 +164,17 @@ impl super::Queue {
vertex_count,
instance_count,
} => {
if instance_count == 1 {
unsafe { gl.draw_arrays(topology, start_vertex as i32, vertex_count as i32) };
} else {
unsafe {
gl.draw_arrays_instanced(
topology,
start_vertex as i32,
vertex_count as i32,
instance_count as i32,
)
};
}
// Don't use `gl.draw_arrays` for `instance_count == 1`.
// Angle has a bug where it doesn't consider the instance divisor when `DYNAMIC_DRAW` is used in `draw_arrays`.
// See https://github.com/gfx-rs/wgpu/issues/3578
unsafe {
gl.draw_arrays_instanced(
topology,
start_vertex as i32,
vertex_count as i32,
instance_count as i32,
)
};
}
C::DrawIndexed {
topology,
@ -184,44 +183,32 @@ impl super::Queue {
index_offset,
base_vertex,
instance_count,
} => match (base_vertex, instance_count) {
(0, 1) => unsafe {
gl.draw_elements(
topology,
index_count as i32,
index_type,
index_offset as i32,
)
},
(0, _) => unsafe {
gl.draw_elements_instanced(
topology,
index_count as i32,
index_type,
index_offset as i32,
instance_count as i32,
)
},
(_, 1) => unsafe {
gl.draw_elements_base_vertex(
topology,
index_count as i32,
index_type,
index_offset as i32,
base_vertex,
)
},
(_, _) => unsafe {
gl.draw_elements_instanced_base_vertex(
topology,
index_count as _,
index_type,
index_offset as i32,
instance_count as i32,
base_vertex,
)
},
},
} => {
match base_vertex {
// Don't use `gl.draw_elements`/`gl.draw_elements_base_vertex` for `instance_count == 1`.
// Angle has a bug where it doesn't consider the instance divisor when `DYNAMIC_DRAW` is used in `gl.draw_elements`/`gl.draw_elements_base_vertex`.
// See https://github.com/gfx-rs/wgpu/issues/3578
0 => unsafe {
gl.draw_elements_instanced(
topology,
index_count as i32,
index_type,
index_offset as i32,
instance_count as i32,
)
},
_ => unsafe {
gl.draw_elements_instanced_base_vertex(
topology,
index_count as _,
index_type,
index_offset as i32,
instance_count as i32,
base_vertex,
)
},
}
}
C::DrawIndirect {
topology,
indirect_buf,