Struct tetra::graphics::mesh::GeometryBuilder
source · pub struct GeometryBuilder { /* private fields */ }
Expand description
A builder for creating primitive shape geometry, and associated buffers/meshes.
Performance
GeometryBuilder
stores the generated vertex and index data in a pair of Vec
s. This means that creating
a new builder (as well as cloning an existing one) will allocate memory. Consider reusing a GeometryBuilder
if you need to reuse the generated data, or if you need to create new data every frame.
Creating buffers/meshes from the generated geometry is a fairly expensive operation. Try to avoid creating lots of seperate buffers/meshes, and pack multiple shapes into the same buffers/mesh if they don’t move relative to each other.
Examples
The shapes
example demonstrates
how to draw primitive shapes, both through the simplified API on Mesh
, and the more powerful
GeometryBuilder
API.
Implementations§
source§impl GeometryBuilder
impl GeometryBuilder
sourcepub fn new() -> GeometryBuilder
pub fn new() -> GeometryBuilder
Creates a new empty geometry builder.
sourcepub fn rectangle(
&mut self,
style: ShapeStyle,
rectangle: Rectangle
) -> Result<&mut GeometryBuilder>
pub fn rectangle( &mut self, style: ShapeStyle, rectangle: Rectangle ) -> Result<&mut GeometryBuilder>
Adds a rectangle.
Errors
TetraError::TessellationError
will be returned if the shape could not be turned into vertex data.
sourcepub fn rounded_rectangle(
&mut self,
style: ShapeStyle,
rectangle: Rectangle,
radii: BorderRadii
) -> Result<&mut GeometryBuilder>
pub fn rounded_rectangle( &mut self, style: ShapeStyle, rectangle: Rectangle, radii: BorderRadii ) -> Result<&mut GeometryBuilder>
Adds a rounded rectangle.
Errors
TetraError::TessellationError
will be returned if the shape could not be turned into vertex data.
sourcepub fn circle(
&mut self,
style: ShapeStyle,
center: Vec2<f32>,
radius: f32
) -> Result<&mut GeometryBuilder>
pub fn circle( &mut self, style: ShapeStyle, center: Vec2<f32>, radius: f32 ) -> Result<&mut GeometryBuilder>
Adds a circle.
Errors
TetraError::TessellationError
will be returned if the shape could not be turned into vertex data.
sourcepub fn ellipse(
&mut self,
style: ShapeStyle,
center: Vec2<f32>,
radii: Vec2<f32>
) -> Result<&mut GeometryBuilder>
pub fn ellipse( &mut self, style: ShapeStyle, center: Vec2<f32>, radii: Vec2<f32> ) -> Result<&mut GeometryBuilder>
Adds an ellipse.
Errors
TetraError::TessellationError
will be returned if the shape could not be turned into vertex data.
sourcepub fn polygon(
&mut self,
style: ShapeStyle,
points: &[Vec2<f32>]
) -> Result<&mut GeometryBuilder>
pub fn polygon( &mut self, style: ShapeStyle, points: &[Vec2<f32>] ) -> Result<&mut GeometryBuilder>
Adds a polygon.
Errors
TetraError::TessellationError
will be returned if the shape could not be turned into vertex data.
sourcepub fn polyline(
&mut self,
stroke_width: f32,
points: &[Vec2<f32>]
) -> Result<&mut GeometryBuilder>
pub fn polyline( &mut self, stroke_width: f32, points: &[Vec2<f32>] ) -> Result<&mut GeometryBuilder>
Adds a polyline.
Errors
TetraError::TessellationError
will be returned if the shape could not be turned into vertex data.
sourcepub fn set_color(&mut self, color: Color) -> &mut GeometryBuilder
pub fn set_color(&mut self, color: Color) -> &mut GeometryBuilder
Sets the color that will be used for subsequent shapes.
You can also use DrawParams::color
to tint an entire mesh -
this method only needs to be used if you want to display multiple colors in a
single piece of geometry.
sourcepub fn clear(&mut self) -> &mut GeometryBuilder
pub fn clear(&mut self) -> &mut GeometryBuilder
Clears the geometry builder’s data.
sourcepub fn into_data(self) -> (Vec<Vertex>, Vec<u32>)
pub fn into_data(self) -> (Vec<Vertex>, Vec<u32>)
Consumes the builder, returning the generated geometry.
sourcepub fn build_buffers(
&self,
ctx: &mut Context
) -> Result<(VertexBuffer, IndexBuffer)>
pub fn build_buffers( &self, ctx: &mut Context ) -> Result<(VertexBuffer, IndexBuffer)>
Builds a vertex and index buffer from the generated geometry.
This involves uploading the geometry to the GPU, and is a fairly expensive operation.
Errors
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.
sourcepub fn build_mesh(&self, ctx: &mut Context) -> Result<Mesh>
pub fn build_mesh(&self, ctx: &mut Context) -> Result<Mesh>
Builds a mesh from the generated geometry.
This involves uploading the geometry to the GPU, and is a fairly expensive operation.
Errors
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.
Trait Implementations§
source§impl Clone for GeometryBuilder
impl Clone for GeometryBuilder
source§fn clone(&self) -> GeometryBuilder
fn clone(&self) -> GeometryBuilder
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more