Skip to content

Commit

Permalink
[GLES] Always use instanced methods to workaround for instance attrib…
Browse files Browse the repository at this point in the history
…utes when rendering a single instance
  • Loading branch information
Wumpf authored and grovesNL committed Mar 20, 2023
1 parent f99b37e commit ca9341b
Showing 1 changed file with 37 additions and 50 deletions.
87 changes: 37 additions & 50 deletions wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit ca9341b

Please sign in to comment.