gles: allow clearing index buffers on WebGL
@@ -213,6 +213,21 @@ impl super::Queue {
ref range,
} => match dst.raw {
Some(buffer) => {
+ // When `INDEX_BUFFER_ROLE_CHANGE` isn't available, we can't copy into the
+ // index buffer from the zero buffer. This would fail in Chrome with the
+ // following message:
+ //
+ // > Cannot copy into an element buffer destination from a non-element buffer
+ // > source
+ //
+ // Instead, we'll upload zeroes into the buffer.
+ let can_use_zero_buffer = self
+ .shared
+ .private_caps
+ .contains(super::PrivateCapabilities::INDEX_BUFFER_ROLE_CHANGE)
+ || dst_target != glow::ELEMENT_ARRAY_BUFFER;
+
+ if can_use_zero_buffer {
gl.bind_buffer(glow::COPY_READ_BUFFER, Some(self.zero_buffer));
gl.bind_buffer(dst_target, Some(buffer));
let mut dst_offset = range.start;
@@ -227,6 +242,11 @@ impl super::Queue {
);
dst_offset += size;
}
+ } else {
+ gl.bind_buffer(dst_target, Some(buffer));
+ let zeroes = vec![0u8; (range.end - range.start) as usize];
+ gl.buffer_sub_data_u8_slice(dst_target, range.start as i32, &zeroes);
+ }
}
None => {
dst.data.as_ref().unwrap().lock().unwrap().as_mut_slice()
