Struct tetra::graphics::mesh::VertexBuffer
source · pub struct VertexBuffer { /* private fields */ }
Expand description
Vertex data, stored in GPU memory.
This data can be drawn to the screen via a Mesh
.
Performance
When you create or modify a vertex buffer, you are effectively ‘uploading’ data to the GPU, which can be relatively slow. You should try to minimize how often you do this - for example, if a piece of geometry does not change from frame to frame, reuse the buffer instead of recreating it.
You can clone a vertex buffer cheaply, as it is a reference-counted
handle to a GPU resource. However, this does mean that modifying a buffer (e.g.
calling set_data
) will also affect any clones that exist of it.
Implementations§
source§impl VertexBuffer
impl VertexBuffer
sourcepub fn new(ctx: &mut Context, vertices: &[Vertex]) -> Result<VertexBuffer>
pub fn new(ctx: &mut Context, vertices: &[Vertex]) -> Result<VertexBuffer>
Creates a new vertex buffer.
The buffer will be created with the BufferUsage::Dynamic
usage hint - this can
be overridden via the with_usage
constructor.
Errors
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.
sourcepub fn with_usage(
ctx: &mut Context,
vertices: &[Vertex],
usage: BufferUsage
) -> Result<VertexBuffer>
pub fn with_usage( ctx: &mut Context, vertices: &[Vertex], usage: BufferUsage ) -> Result<VertexBuffer>
Creates a new vertex buffer, with the specified usage hint.
The GPU may optionally use the usage hint to optimize data storage and access.
Errors
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.
Trait Implementations§
source§impl Clone for VertexBuffer
impl Clone for VertexBuffer
source§fn clone(&self) -> VertexBuffer
fn clone(&self) -> VertexBuffer
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for VertexBuffer
impl Debug for VertexBuffer
source§impl From<VertexBuffer> for Mesh
impl From<VertexBuffer> for Mesh
source§fn from(buffer: VertexBuffer) -> Self
fn from(buffer: VertexBuffer) -> Self
source§impl PartialEq<VertexBuffer> for VertexBuffer
impl PartialEq<VertexBuffer> for VertexBuffer
source§fn eq(&self, other: &VertexBuffer) -> bool
fn eq(&self, other: &VertexBuffer) -> bool
self
and other
values to be equal, and is used
by ==
.