Struct solstice::mesh::VertexMesh [−][src]
pub struct VertexMesh<V> { /* fields omitted */ }
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
impl<V> VertexMesh<V> where
V: Vertex,
[src]
impl<V> VertexMesh<V> where
V: Vertex,
[src]pub fn new(ctx: &mut Context, size: usize) -> Result<Self, GraphicsError>
[src]
pub fn new(ctx: &mut Context, size: usize) -> Result<Self, GraphicsError>
[src]Construct a Mesh with a given number of vertices.
pub fn with_data(
ctx: &mut Context,
vertices: &[V]
) -> Result<Self, GraphicsError>
[src]
ctx: &mut Context,
vertices: &[V]
) -> Result<Self, GraphicsError>
pub fn with_buffer(buffer: Buffer) -> Self
[src]
pub fn set_vertices(&self, ctx: &mut Context, vertices: &[V], offset: usize)
[src]
pub fn set_vertices(&self, ctx: &mut Context, vertices: &[V], offset: usize)
[src]Write new data into a range of the Mesh’s vertex data.
pub fn set_draw_range(&mut self, draw_range: Option<Range<usize>>)
[src]
pub fn set_draw_range(&mut self, draw_range: Option<Range<usize>>)
[src]Sets the range of vertices to be drawn. Passing None
will draw the entire mesh.
pub fn set_draw_mode(&mut self, draw_mode: DrawMode)
[src]
pub fn set_draw_mode(&mut self, draw_mode: DrawMode)
[src]Sets how the vertex data should be tesselated.
pub fn draw_range(&self) -> Range<usize>
[src]
pub fn draw_mode(&self) -> DrawMode
[src]
pub fn len(&self) -> usize
[src]
Trait Implementations
impl<V: Clone> Clone for VertexMesh<V>
[src]
impl<V: Clone> Clone for VertexMesh<V>
[src]fn clone(&self) -> VertexMesh<V>
[src]
fn clone(&self) -> VertexMesh<V>
[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]Performs copy-assignment from source
. Read more
impl<V: Debug> Debug for VertexMesh<V>
[src]
impl<V: Debug> Debug for VertexMesh<V>
[src]impl<V: Vertex> Mesh for VertexMesh<V>
[src]
impl<V: Vertex> Mesh for VertexMesh<V>
[src]impl<V: Vertex> Mesh for &VertexMesh<V>
[src]
impl<V: Vertex> Mesh for &VertexMesh<V>
[src]impl<V: Vertex> MeshAttacher for VertexMesh<V>
[src]
impl<V: Vertex> MeshAttacher for VertexMesh<V>
[src]impl<V: PartialEq> PartialEq<VertexMesh<V>> for VertexMesh<V>
[src]
impl<V: PartialEq> PartialEq<VertexMesh<V>> for VertexMesh<V>
[src]fn eq(&self, other: &VertexMesh<V>) -> bool
[src]
fn eq(&self, other: &VertexMesh<V>) -> bool
[src]This method tests for self
and other
values to be equal, and is used
by ==
. Read more
fn ne(&self, other: &VertexMesh<V>) -> bool
[src]
fn ne(&self, other: &VertexMesh<V>) -> bool
[src]This method tests for !=
.
impl<V> StructuralPartialEq for VertexMesh<V>
[src]
Auto Trait Implementations
impl<V> RefUnwindSafe for VertexMesh<V> where
V: RefUnwindSafe,
V: RefUnwindSafe,
impl<V> Send for VertexMesh<V> where
V: Send,
V: Send,
impl<V> Sync for VertexMesh<V> where
V: Sync,
V: Sync,
impl<V> Unpin for VertexMesh<V> where
V: Unpin,
V: Unpin,
impl<V> UnwindSafe for VertexMesh<V> where
V: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more