pub struct TessBuilder<'a, B, V, I = (), W = (), S = Interleaved>{ /* private fields */ }
Expand description
Tess
builder object.
This type allows to create Tess
via a builder pattern. You have several flavors of
possible vertex storages, as well as data encoding, described below.
§Vertex storage
§Interleaved
You can pass around interleaved vertices and indices. Those are encoded in Vec<T>
. You
typically want to use this when you already have the vertices and/or indices allocated somewhere,
as the interface will use the input vector as a source of truth for lengths.
§Deinterleaved
This is the same as interleaved data in terms of interface, but the T
type is interpreted
a bit differently. Here, the encoding is (Vec<Field0>, Vec<Field1>, …)
, where Field0
,
Field1
etc. are all the ordered fieds in T
. This logic is hidden behind Vec<DeinterleavedData>
.
That representation allows field-based operations on Tess
, while it would be impossible
with the interleaved version (you would need to get all the fields at once, since
you would work on T
directly and each of its fields).
§Data encoding
- Vectors: you can pass vectors as input data for both vertices and indices. Those will be interpreted differently based on the vertex storage you chose for vertices / instances. For indices, there is no difference.
- Disabled: disabling means that no data will be passed to the GPU. You can disable independently
vertex data and/or index data by using the unit
()
type.
§Indexed vertex sets
It is possible to index the geometry via the use of indices. Indices are stored in contiguous
regions of memory (Vec<T>
), where T
satisfies TessIndex
. When using an indexed tessellation,
the meaning of its attributes slightly changes. First, the vertices are not used as input source for
the vertex stream. In order to provide vertices that will go through the vertex stream, the indices
reference the vertex set to provide the order in which they should appear in the stream.
When rendering with a TessView
, the number of vertices to render must be provided or inferred
based on the Tess
the view was made from. That number will refer to either the vertex set or
index set, depending on the kind of tessellation. Asking to render a Tess
with 3 vertices will
pick 3 vertices from the vertex set for direct tessellations and 3 indices to index the vertex set
for indexed tessellations.
§Primitive mode
By default, a TessBuilder
will build points. Each vertex in the vertex stream will be independently rendered
from the others, resulting in a point cloud. This logic is encoded with Mode::Point
. You can change how
vertices are interpreted by changing the Mode
.
§Parametricity
B
is the backend typeV
is the vertex type.I
is the index type.W
is the vertex instance type.S
is the storage type.
Implementations§
Source§impl<'a, B, V, I, W, S> TessBuilder<'a, B, V, I, W, S>
impl<'a, B, V, I, W, S> TessBuilder<'a, B, V, I, W, S>
Sourcepub fn set_mode(self, mode: Mode) -> Self
pub fn set_mode(self, mode: Mode) -> Self
Set the Mode
to connect vertices.
Calling that function twice replaces the previously set value.
Sourcepub fn set_render_vertex_nb(self, vert_nb: usize) -> Self
pub fn set_render_vertex_nb(self, vert_nb: usize) -> Self
Set the default number of vertices to render.
Calling that function twice replaces the previously set value. This method changes the number of vertices to pick:
- From the vertex set for regular geometries.
- From the index set, using the picked indices to reference the vertex set.
Sourcepub fn set_render_instance_nb(self, inst_nb: usize) -> Self
pub fn set_render_instance_nb(self, inst_nb: usize) -> Self
Set the default number of instances to render.
Calling that function twice replaces the previously set value.
Sourcepub fn set_primitive_restart_index(self, restart_index: I) -> Self
pub fn set_primitive_restart_index(self, restart_index: I) -> Self
Set the primitive restart index.
Calling that function twice replaces the previously set value.
Source§impl<'a, B, V, I, W, S> TessBuilder<'a, B, V, I, W, S>
impl<'a, B, V, I, W, S> TessBuilder<'a, B, V, I, W, S>
Sourcepub fn new<C>(ctx: &'a mut C) -> Selfwhere
C: GraphicsContext<Backend = B>,
pub fn new<C>(ctx: &'a mut C) -> Selfwhere
C: GraphicsContext<Backend = B>,
Create a new default TessBuilder
.
§Notes
Feel free to use the GraphicsContext::new_tess
method for a simpler method.
Source§impl<'a, B, V, W, S> TessBuilder<'a, B, V, (), W, S>
impl<'a, B, V, W, S> TessBuilder<'a, B, V, (), W, S>
Sourcepub fn set_indices<I, X>(self, indices: X) -> TessBuilder<'a, B, V, I, W, S>
pub fn set_indices<I, X>(self, indices: X) -> TessBuilder<'a, B, V, I, W, S>
Add indices to be bundled in the Tess
.
Every time you call that function, the set of indices is replaced by the one you provided.
The type of expected indices is ruled by the II
type variable you chose.
Source§impl<'a, B, I, W> TessBuilder<'a, B, (), I, W, Interleaved>
impl<'a, B, I, W> TessBuilder<'a, B, (), I, W, Interleaved>
Sourcepub fn set_vertices<V, X>(
self,
vertices: X,
) -> TessBuilder<'a, B, V, I, W, Interleaved>
pub fn set_vertices<V, X>( self, vertices: X, ) -> TessBuilder<'a, B, V, I, W, Interleaved>
Add vertices to be bundled in the Tess
.
Every time you call that function, the set of vertices is replaced by the one you provided.
Source§impl<'a, B, I, V> TessBuilder<'a, B, V, I, (), Interleaved>
impl<'a, B, I, V> TessBuilder<'a, B, V, I, (), Interleaved>
Sourcepub fn set_instances<W, X>(
self,
instances: X,
) -> TessBuilder<'a, B, V, I, W, Interleaved>
pub fn set_instances<W, X>( self, instances: X, ) -> TessBuilder<'a, B, V, I, W, Interleaved>
Add instances to be bundled in the Tess
.
Every time you call that function, the set of instances is replaced by the one you provided.
Source§impl<'a, B, V, I, W> TessBuilder<'a, B, V, I, W, Deinterleaved>where
B: ?Sized,
V: TessVertexData<Deinterleaved, Data = Vec<DeinterleavedData>>,
I: TessIndex,
W: TessVertexData<Deinterleaved, Data = Vec<DeinterleavedData>>,
impl<'a, B, V, I, W> TessBuilder<'a, B, V, I, W, Deinterleaved>where
B: ?Sized,
V: TessVertexData<Deinterleaved, Data = Vec<DeinterleavedData>>,
I: TessIndex,
W: TessVertexData<Deinterleaved, Data = Vec<DeinterleavedData>>,
Sourcepub fn set_attributes<A, X>(self, attributes: X) -> Self
pub fn set_attributes<A, X>(self, attributes: X) -> Self
Add vertices to be bundled in the Tess
.
Every time you call that function, the set of vertices is replaced by the one you provided.
Sourcepub fn set_instance_attributes<A, X>(self, attributes: X) -> Self
pub fn set_instance_attributes<A, X>(self, attributes: X) -> Self
Add instances to be bundled in the Tess
.
Every time you call that function, the set of instances is replaced by the one you provided.
Source§impl<'a, B, V, I, W, S> TessBuilder<'a, B, V, I, W, S>where
B: ?Sized + TessBackend<V, I, W, S>,
V: TessVertexData<S>,
I: TessIndex,
W: TessVertexData<S>,
impl<'a, B, V, I, W, S> TessBuilder<'a, B, V, I, W, S>where
B: ?Sized + TessBackend<V, I, W, S>,
V: TessVertexData<S>,
I: TessIndex,
W: TessVertexData<S>,
Sourcepub fn build(self) -> Result<Tess<B, V, I, W, S>, TessError>
pub fn build(self) -> Result<Tess<B, V, I, W, S>, TessError>
Build a Tess
if the TessBuilder
has enough data and is in a valid state. What is
needed is backend-dependent but most of the time, you will want to:
- Set a
Mode
. - Give vertex data and optionally indices, or give none of them but only a number of vertices (attributeless objects).
- If you provide vertex data by submitting several sets with
TessBuilder::set_attributes
and/orTessBuilder::set_instances
, do not forget that you must submit sets with the same size. Otherwise, the GPU will not know what values use for missing attributes in vertices.