Struct solstice::mesh::VertexMesh

source ·
pub struct VertexMesh<V> { /* private fields */ }
Expand description

The Mesh represents a set of vertices to be drawn by a shader program and how to draw them. A well-formed Vertex implementation will provide information to the mesh about it’s layout in order to properly sync the data to the GPU. A derive macro exists in Vertex that will derive this implementation for you.

use solstice::vertex::{VertexFormat, AttributeType};
#[repr(C)]
#[derive(Copy, Clone, bytemuck::Zeroable, bytemuck::Pod)]
struct TestVertex {
    position: [f32; 2],
    color: [f32; 4],
}

impl solstice::vertex::Vertex for TestVertex {
    fn build_bindings() -> &'static [VertexFormat] {
        &[VertexFormat {
            name: "position",
            offset: 0,
            atype: AttributeType::F32F32,
            normalize: false,
        }, VertexFormat {
            name: "color",
            offset: std::mem::size_of::<[f32; 2]>(),
            atype: AttributeType::F32F32F32F32,
            normalize: false
        }]
    }
}

let vertex_data = vec![
    TestVertex {
        position: [0.5, 0.],
        color: [1., 0., 0., 1.]
    },
    TestVertex {
        position: [0., 1.0],
        color: [0., 1., 0., 1.]
    },
    TestVertex {
        position: [1., 0.],
        color: [0., 0., 1., 1.]
    },
];

Vertex data is then copied into the mesh.

let mut mesh = solstice::mesh::Mesh::new(&mut ctx, 3);
mesh.set_vertices(&vertex_data, 0);

Once constructed, a Mesh is of an immutable size but the draw range can be modified to effectively change it’s size without changing the underlying memory’s size.

let mut mesh = solstice::mesh::Mesh::new(&mut ctx, 3000).unwrap();
mesh.set_draw_range(Some(0..3)); // draws only the first three vertices of the 3000 allocated

Implementations§

source§

impl<V> VertexMesh<V>where V: Vertex,

source

pub fn new(ctx: &mut Context, size: usize) -> Result<Self, GraphicsError>

Construct a Mesh with a given number of vertices.

source

pub fn with_data( ctx: &mut Context, vertices: &[V] ) -> Result<Self, GraphicsError>

source

pub fn with_buffer(buffer: Buffer) -> Self

source

pub fn set_vertices(&self, ctx: &mut Context, vertices: &[V], offset: usize)

Write new data into a range of the Mesh’s vertex data.

source

pub fn set_draw_range(&mut self, draw_range: Option<Range<usize>>)

Sets the range of vertices to be drawn. Passing None will draw the entire mesh.

source

pub fn set_draw_mode(&mut self, draw_mode: DrawMode)

Sets how the vertex data should be tesselated.

source

pub fn draw_range(&self) -> Range<usize>

source

pub fn draw_mode(&self) -> DrawMode

source

pub fn len(&self) -> usize

Trait Implementations§

source§

impl<V: Clone> Clone for VertexMesh<V>

source§

fn clone(&self) -> VertexMesh<V>

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<V: Debug> Debug for VertexMesh<V>

source§

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

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

impl<V: Vertex> Mesh for &VertexMesh<V>

source§

fn attachments(&self) -> Vec<AttachedAttributes<'_>>

source§

fn draw( &self, ctx: &mut Context, draw_range: Range<usize>, draw_mode: DrawMode, instance_count: usize )

source§

impl<V: Vertex> Mesh for VertexMesh<V>

source§

fn attachments(&self) -> Vec<AttachedAttributes<'_>>

source§

fn draw( &self, ctx: &mut Context, draw_range: Range<usize>, draw_mode: DrawMode, instance_count: usize )

source§

impl<V: Vertex> MeshAttacher for VertexMesh<V>

source§

fn attach_with_step<'a, T: Mesh>( &'a self, other: &'a T, step: u32 ) -> MultiMesh<'a>

source§

fn attach<'a, T: Mesh>(&'a self, other: &'a T) -> MultiMesh<'a>

source§

impl<V: PartialEq> PartialEq<VertexMesh<V>> for VertexMesh<V>

source§

fn eq(&self, other: &VertexMesh<V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<V> StructuralPartialEq for VertexMesh<V>

Auto Trait Implementations§

§

impl<V> RefUnwindSafe for VertexMesh<V>where V: RefUnwindSafe,

§

impl<V> Send for VertexMesh<V>where V: Send,

§

impl<V> Sync for VertexMesh<V>where V: Sync,

§

impl<V> Unpin for VertexMesh<V>where V: Unpin,

§

impl<V> UnwindSafe for VertexMesh<V>where V: UnwindSafe,

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.

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.

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