Skip to content

Commit

Permalink
Fix draw indexed
Browse files Browse the repository at this point in the history
  • Loading branch information
valaphee committed Apr 12, 2024
1 parent 813cf03 commit a0124af
Showing 1 changed file with 27 additions and 51 deletions.
78 changes: 27 additions & 51 deletions wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,60 +209,36 @@ impl super::Queue {
instance_count,
ref first_instance_location,
} => {
match base_vertex {
0 => {
unsafe {
gl.uniform_1_u32(first_instance_location.as_ref(), first_instance)
};
let supports_full_instancing = self
.shared
.private_caps
.contains(PrivateCapabilities::FULLY_FEATURED_INSTANCING);

unsafe {
// 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
gl.draw_elements_instanced(
topology,
index_count as i32,
index_type,
index_offset as i32,
instance_count as i32,
)
}
if supports_full_instancing {
unsafe {
gl.draw_elements_instanced_base_vertex_base_instance(
topology,
index_count as i32,
index_type,
index_offset as i32,
instance_count as i32,
base_vertex,
first_instance,
)
}
_ => {
let supports_full_instancing = self
.shared
.private_caps
.contains(PrivateCapabilities::FULLY_FEATURED_INSTANCING);

if supports_full_instancing {
unsafe {
gl.draw_elements_instanced_base_vertex_base_instance(
topology,
index_count as i32,
index_type,
index_offset as i32,
instance_count as i32,
base_vertex,
first_instance,
)
}
} else {
unsafe {
gl.uniform_1_u32(first_instance_location.as_ref(), first_instance)
};
} else {
unsafe { gl.uniform_1_u32(first_instance_location.as_ref(), first_instance) };

// If we've gotten here, wgpu-core has already validated that this function exists via the DownlevelFlags::BASE_VERTEX feature.
unsafe {
gl.draw_elements_instanced_base_vertex(
topology,
index_count as _,
index_type,
index_offset as i32,
instance_count as i32,
base_vertex,
)
}
}
// If we've gotten here, wgpu-core has already validated that this function exists via the DownlevelFlags::BASE_VERTEX feature.
unsafe {
gl.draw_elements_instanced_base_vertex(
topology,
index_count as _,
index_type,
index_offset as i32,
instance_count as i32,
base_vertex,
)
}
}
}
Expand Down

0 comments on commit a0124af

Please sign in to comment.