Add len method to IndexBuffer (#2342)

* ### Additions
- `IndexBuffer::len` method.

* Fixed formatting
This commit is contained in:
Trevor 2023-09-28 11:12:27 -07:00 committed by GitHub
parent 56b051c954
commit c24c7ad155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -672,7 +672,7 @@ impl BufferState {
gpu_reads: 0, gpu_reads: 0,
} => (), } => (),
CurrentAccess::Shared { cpu_reads, .. } if *cpu_reads > 0 => { CurrentAccess::Shared { cpu_reads, .. } if *cpu_reads > 0 => {
return Err(AccessConflict::HostRead) return Err(AccessConflict::HostRead);
} }
CurrentAccess::Shared { .. } => return Err(AccessConflict::DeviceRead), CurrentAccess::Shared { .. } => return Err(AccessConflict::DeviceRead),
} }
@ -1014,6 +1014,16 @@ impl IndexBuffer {
IndexBuffer::U32(buffer) => buffer.as_bytes(), IndexBuffer::U32(buffer) => buffer.as_bytes(),
} }
} }
/// Returns the number of elements in the buffer.
#[inline]
pub fn len(&self) -> DeviceSize {
match self {
IndexBuffer::U8(buffer) => buffer.len(),
IndexBuffer::U16(buffer) => buffer.len(),
IndexBuffer::U32(buffer) => buffer.len(),
}
}
} }
impl From<Subbuffer<[u8]>> for IndexBuffer { impl From<Subbuffer<[u8]>> for IndexBuffer {