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

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

Sends new index data to the GPU.

Panics

Panics if the offset is out of bounds.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.