pub struct VertexBuffer { /* private fields */ }Expand description
An in-memory buffer of interleaved vertex data with an associated layout.
§Example
use oximedia_gpu::vertex_buffer::{VertexAttribute, VertexLayout, VertexBuffer};
let mut layout = VertexLayout::new();
layout.add("POSITION", VertexAttribute::Float32x3);
layout.add("TEXCOORD", VertexAttribute::Float32x2);
// 1 vertex = 20 bytes
let data = vec![0u8; 20];
let vb = VertexBuffer::new(layout, data).expect("valid vertex buffer");
assert_eq!(vb.vertex_count(), 1);
assert_eq!(vb.stride(), 20);Implementations§
Source§impl VertexBuffer
impl VertexBuffer
Sourcepub fn new(
layout: VertexLayout,
data: Vec<u8>,
) -> Result<Self, VertexBufferError>
pub fn new( layout: VertexLayout, data: Vec<u8>, ) -> Result<Self, VertexBufferError>
Create a new vertex buffer, validating that data.len() is a multiple
of the layout stride.
§Errors
Returns VertexBufferError::StrideMismatch if the data is not aligned
to the layout stride, or VertexBufferError::Empty if the stride is
zero.
Sourcepub fn vertex_count(&self) -> usize
pub fn vertex_count(&self) -> usize
Number of complete vertex records stored in the buffer.
Sourcepub fn layout(&self) -> &VertexLayout
pub fn layout(&self) -> &VertexLayout
Return the layout describing this buffer’s format.
Sourcepub fn vertex_bytes(&self, index: usize) -> Option<&[u8]>
pub fn vertex_bytes(&self, index: usize) -> Option<&[u8]>
Return the raw bytes for vertex at index, or None if out of range.
Trait Implementations§
Source§impl Clone for VertexBuffer
impl Clone for VertexBuffer
Source§fn clone(&self) -> VertexBuffer
fn clone(&self) -> VertexBuffer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for VertexBuffer
impl RefUnwindSafe for VertexBuffer
impl Send for VertexBuffer
impl Sync for VertexBuffer
impl Unpin for VertexBuffer
impl UnsafeUnpin for VertexBuffer
impl UnwindSafe for VertexBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more