Module luminance::vertex
[−]
[src]
Vertex formats, associated types and functions.
A vertex is a type representing a point. It’s common to find vertex positions, normals, colors
or even texture coordinates. However, you’re free to use whichever type you want. Nevertheless,
you’re limited to a range of types and dimensions. See Type
and Dim
for further details.
Vertex
Rules
To be able to use a type as a vertex, you have to implement the Vertex
trait. That trait
represents a mapping between your type and VertexFormat
. A VertexFormat
gives runtime hints
about your type and restricts the supported type. If you cannot map your type to VertexFormat
,
that means you cannot use it as a Vertex
.
The rule is that your type should have a static size greater than 0 and less than or equal to 4.
It should also be either integral, unsigned, floating or boolean. If your type is a complex one
– for instance a struct
– you have to recursively apply that rule to all its fields.
For instance, the tuple (i32, bool)
implements Vertex
by providing an implementation using
the ones of i32
and bool
.
Components list
As mentionned above, you can use tuples and structs as Vertex
. If you look at the definition
of VertexFormat
, you’ll notice that it’s a Vec<VertexComponentFormat>
. That means simple
and primary types map to unit vectors – i.e. their size is 1 – but tuples and structs need
several VertexComponentFormat
s to be represented, hence vectors with sizes greater than 1. No
check is made on how many vertex components you’re using – there’s a practical limit, set by the
GPU, but it’s not checked (yet).
Generic implementation
You have Vertex
implementations for all the primary types that can be mapped to
VertexFormat
. However, as it’s not possible to automatically implement Vertex
for your
structure (yet?), a type is provided to help you design your vertex type so that you’re
automatically provided with a Vertex
implementation if you use Chain
.
Chain
is a special type used to represent static list of types. With that in hand, you can
easily create Vertex
types and start using them without even implementing Vertex
, as long as
you use Vertex
types. Feel free to dig in the Chain
documentation for further details.
If you absolutely want to use your own types – which is legit, you can to implement Vertex
by
mapping your inner fields to tuples, and call the right Vertex
method on that tuple.
Structs
VertexComponentFormat |
Vertex component format. It gives information on how vertices should be passed to the GPU and optimized in buffers. |
Enums
Dim |
Possible dimension of vertex components. |
Type |
Possible type of vertex components. |
Traits
Vertex |
A type that can be used as a |
Functions
vertex_format_size |
Retrieve the number of components in a |
Type Definitions
VertexFormat |
A |