Struct vulkano::buffer::BufferSlice
source · [−]pub struct BufferSlice<T: ?Sized, B> { /* private fields */ }
Expand description
A subpart of a buffer.
This object doesn’t correspond to any Vulkan object. It exists for API convenience.
Example
Creating a slice:
use vulkano::buffer::BufferSlice;
let _slice = BufferSlice::from(&buffer);
Selecting a slice of a buffer that contains [T]
:
use vulkano::buffer::BufferSlice;
let _slice = BufferSlice::from(&buffer).slice(12 .. 14).unwrap();
Implementations
sourceimpl<T: ?Sized, B> BufferSlice<T, B>
impl<T: ?Sized, B> BufferSlice<T, B>
pub fn from_typed_buffer_access(r: Arc<B>) -> Arc<BufferSlice<T, B>>where
B: TypedBufferAccess<Content = T>,
sourcepub fn offset(&self) -> DeviceSize
pub fn offset(&self) -> DeviceSize
Returns the offset of that slice within the buffer.
sourcepub fn size(&self) -> DeviceSize
pub fn size(&self) -> DeviceSize
Returns the size of that slice in bytes.
sourcepub unsafe fn slice_custom<F, R: ?Sized>(&self, f: F) -> Arc<BufferSlice<R, B>>where
F: for<'r> FnOnce(&'r T) -> &'r R,
pub unsafe fn slice_custom<F, R: ?Sized>(&self, f: F) -> Arc<BufferSlice<R, B>>where
F: for<'r> FnOnce(&'r T) -> &'r R,
Builds a slice that contains an element from inside the buffer.
This method builds an object that represents a slice of the buffer. No actual operation is performed.
Example
TODO
Safety
The object whose reference is passed to the closure is uninitialized. Therefore you must not access the content of the object.
You must return a reference to an element from the parameter. The closure must not panic.
sourcepub unsafe fn reinterpret<R: ?Sized>(&self) -> Arc<BufferSlice<R, B>>
pub unsafe fn reinterpret<R: ?Sized>(&self) -> Arc<BufferSlice<R, B>>
Changes the T
generic parameter of the BufferSlice
to the desired type. This can be
useful when you have a buffer with various types of data and want to create a typed slice
of a region that contains a single type of data.
Example
let blob_slice: Arc<BufferSlice<[u8], Arc<DeviceLocalBuffer<[u8]>>>> = return;
let vertex_slice: Arc<BufferSlice<[VertexImpl], Arc<DeviceLocalBuffer<[u8]>>>> = unsafe {
blob_slice.reinterpret::<[VertexImpl]>()
};
Safety
Correct offset
and size
must be ensured before using this BufferSlice
on the device.
See BufferSlice::slice
for adjusting these properties.
sourceimpl<T, B> BufferSlice<[T], B>
impl<T, B> BufferSlice<[T], B>
sourcepub fn len(&self) -> DeviceSize
pub fn len(&self) -> DeviceSize
Returns the number of elements in this slice.
sourcepub fn index(&self, index: DeviceSize) -> Option<Arc<BufferSlice<T, B>>>
pub fn index(&self, index: DeviceSize) -> Option<Arc<BufferSlice<T, B>>>
Reduces the slice to just one element of the array.
Returns None
if out of range.
sourcepub fn slice(&self, range: Range<DeviceSize>) -> Option<Arc<BufferSlice<[T], B>>>
pub fn slice(&self, range: Range<DeviceSize>) -> Option<Arc<BufferSlice<[T], B>>>
Reduces the slice to just a range of the array.
Returns None
if out of range.