[][src]Struct luminance::tess::TessBuilder

pub struct TessBuilder<'a, C> { /* fields omitted */ }

Build tessellations the easy way.

This type allows you to create Tess by specifying piece-by-piece what the tessellation is made of. Several situations and configurations are supported.

Specifying vertices

If you want to create a Tess holding vertices without anything else, you want to use the TessBuilder::add_vertices. Every time that function is called, a vertex buffer is virtually allocated for your tessellation, which gives you three possibilities:

1. Attributeless Tess

If you don’t call that function, you end up with an attributeless tessellation. Such a tessellation has zero memory allocated to vertices. Instead, when invoking a vertex shader, the vertices must be created on the fly inside the vertex shader directly.

2. Interleaved Tess

If you call that function once, you have a single vertex buffer allocated, which either gives you a 1-attribute tessellation, or an interleaved tessellation. Interleaved tessellation allows you to use a Rust struct (if it implements the Vertex trait) as vertex type and easily fetch them from a vertex shader.

3. Deinterleaved Tess

If you call that function several times, the TessBuilder assumes you want deinterleaved memory, which means that each patch of vertices you add is supposed to contain one type of deinterleaved vertex attributes. A coherency check is done by the TessBuilder to ensure the vertex data is correct.

Specifying indices

By default, vertices are picked in the order you specify them in the vertex buffer(s). If you want more control on the order, you can add indices.

As soon as you provide indices, the TessBuilder will change the way Tess will fetch vertices. Instead of fetching the first vertex, then second, then third, etc., it will first fetch the first index, then the second, then third, and respectively use the value of those indices to fetch the actual vertices.

For instance, if instead of fetching vertices [1, 2, 3] (which is the default) you want to fetch [12, 35, 2], you can add the [12, 35, 2] indices in the TessBuilder. When rendering, the Tess will fetch the first index and get 12; it will then make the first vertex to be fetched the 12th; then fetch the second index; get 35 and fetch the 35th vertex. Finally, as you might have guessed, it will fetch the third index, get 2 and then the third vertex to be fetched will be the second one.

That feature is really important as it allows you to factorize vertices: instead of duplicating them, you can just reuse their indices.

You can have only one set of indices. See the TessBuilder::set_indices function.

Specifying vertex instancing

It’s also possible to provide instancing information. Those are special vertex attributes that are picked on an instance-based information instead of vertex number one. It works very similarly to how vertices data work, but on a per-instance bases.

See the TessBuilder::add_instances function for further details.


impl<'a, C> TessBuilder<'a, C>[src]

pub fn new(ctx: &'a mut C) -> Self[src]

Create a new, default TessBuilder.

By default, the primitive mode of the building Tess is Mode::Point.

impl<'a, C> TessBuilder<'a, C> where
    C: GraphicsContext

pub fn add_vertices<V, W>(self, vertices: W) -> Self where
    W: AsRef<[V]>,
    V: Vertex

Add vertices to be part of the tessellation.

This method can be used in several ways. First, you can decide to use interleaved memory, in which case you will call this method only once by providing an interleaved slice / borrowed buffer. Second, you can opt-in to use deinterleaved memory, in which case you will have several, smaller buffers of borrowed data and you will issue a call to this method for all of them.

pub fn add_instances<V, W>(self, instances: W) -> Self where
    W: AsRef<[V]>,
    V: Vertex

Add instances to be part of the tessellation.

pub fn set_indices<T, I>(self, indices: T) -> Self where
    T: AsRef<[I]>,
    I: TessIndex

Set vertex indices in order to specify how vertices should be picked by the GPU pipeline.

pub fn set_mode(self, mode: Mode) -> Self[src]

Set the primitive mode for the building Tess.

pub fn set_vertex_nb(self, nb: usize) -> Self[src]

Set the default number of vertices to be rendered.

That function is not mandatory if you are not building an attributeless tessellation but is if you are.

When called while building a Tess owning at least one vertex buffer, it acts as a default number of vertices to render and is useful when you will slice the tessellation with open ranges.

pub fn set_instance_nb(self, nb: usize) -> Self[src]

Set the default number of instances to render.

0 disables geometry instancing.

pub fn set_primitive_restart_index(self, index: Option<u32>) -> Self[src]

Set the primitive restart index. The initial value is None, implying no primitive restart.

pub fn build(self) -> Result<Tess, TessError>[src]

Build the Tess.

Auto Trait Implementations

impl<'a, C> !RefUnwindSafe for TessBuilder<'a, C>

impl<'a, C> !Send for TessBuilder<'a, C>

impl<'a, C> !Sync for TessBuilder<'a, C>

impl<'a, C> Unpin for TessBuilder<'a, C>

impl<'a, C> !UnwindSafe for TessBuilder<'a, C>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.