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 Vecs. 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

source

pub fn new() -> GeometryBuilder

Creates a new empty geometry builder.

source

pub fn rectangle( &mut self, style: ShapeStyle, rectangle: Rectangle ) -> Result<&mut GeometryBuilder>

Adds a rectangle.

Errors
source

pub fn rounded_rectangle( &mut self, style: ShapeStyle, rectangle: Rectangle, radii: BorderRadii ) -> Result<&mut GeometryBuilder>

Adds a rounded rectangle.

Errors
source

pub fn circle( &mut self, style: ShapeStyle, center: Vec2<f32>, radius: f32 ) -> Result<&mut GeometryBuilder>

Adds a circle.

Errors
source

pub fn ellipse( &mut self, style: ShapeStyle, center: Vec2<f32>, radii: Vec2<f32> ) -> Result<&mut GeometryBuilder>

Adds an ellipse.

Errors
source

pub fn polygon( &mut self, style: ShapeStyle, points: &[Vec2<f32>] ) -> Result<&mut GeometryBuilder>

Adds a polygon.

Errors
source

pub fn polyline( &mut self, stroke_width: f32, points: &[Vec2<f32>] ) -> Result<&mut GeometryBuilder>

Adds a polyline.

Errors
source

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.

source

pub fn clear(&mut self) -> &mut GeometryBuilder

Clears the geometry builder’s data.

source

pub fn vertices(&self) -> &[Vertex]

Returns a view of the generated vertex data.

source

pub fn indices(&self) -> &[u32]

Returns a view of the generated index data.

source

pub fn into_data(self) -> (Vec<Vertex>, Vec<u32>)

Consumes the builder, returning the generated geometry.

source

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
source

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

Trait Implementations§

source§

impl Clone for GeometryBuilder

source§

fn clone(&self) -> GeometryBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for GeometryBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for GeometryBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

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

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,