gles: allow clearing index buffers on WebGL (#2740)

This commit is contained in:
Josh Groves 2022-06-07 03:38:51 -02:30 committed by GitHub
parent 31c6b39c20
commit be625f9a01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -213,19 +213,39 @@ impl super::Queue {
ref range,
} => match dst.raw {
Some(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;
while dst_offset < range.end {
let size = (range.end - dst_offset).min(super::ZERO_BUFFER_SIZE as u64);
gl.copy_buffer_sub_data(
glow::COPY_READ_BUFFER,
dst_target,
0,
dst_offset as i32,
size as i32,
);
dst_offset += size;
// 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;
while dst_offset < range.end {
let size = (range.end - dst_offset).min(super::ZERO_BUFFER_SIZE as u64);
gl.copy_buffer_sub_data(
glow::COPY_READ_BUFFER,
dst_target,
0,
dst_offset as i32,
size as i32,
);
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 => {