Struct tetra::graphics::mesh::IndexBuffer [−][src]
pub struct IndexBuffer { /* fields omitted */ }
Expand description
Index data, stored in GPU memory.
An index buffer can be used as part of a Mesh
, in order to describe which vertex data should be drawn,
and what order it should be drawn in.
For example, to draw a square with raw vertex data, you need to use six vertices (two triangles, with three vertices each). This is inefficient, as two of those vertices are shared by the two triangles! Using an index buffer, you can instruct the graphics card to use vertices multiple times while constructing your square.
Index data is made up of u32
values, each of which correspond to the zero-based index of a vertex.
For example, to get the mesh to draw the third vertex, then the first, then the second, you would
create an index buffer containing [2, 0, 1]
.
Performance
When you create or modify an index 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
Creates a new index 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.
pub fn with_usage(
ctx: &mut Context,
indices: &[u32],
usage: BufferUsage
) -> Result<IndexBuffer>
pub fn with_usage(
ctx: &mut Context,
indices: &[u32],
usage: BufferUsage
) -> Result<IndexBuffer>
Creates a new index 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
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl !RefUnwindSafe for IndexBuffer
impl !Send for IndexBuffer
impl !Sync for IndexBuffer
impl Unpin for IndexBuffer
impl !UnwindSafe for IndexBuffer
Blanket Implementations
Mutably borrows from an owned value. Read more