easygpu_lyon/
shape.rs

1use std::sync::Arc;
2
3use bytemuck::{Pod, Zeroable};
4use easygpu::buffers::{IndexBuffer, VertexBuffer};
5use easygpu::color::Rgba8;
6
7#[repr(C)]
8#[derive(Copy, Clone, Debug, Pod, Zeroable)]
9pub(crate) struct Vertex {
10    pub position: [f32; 3],
11    pub color: Rgba8,
12}
13
14/// Shape is a loaded, prepared ShapeBuilder that is ready to be drawn
15pub struct Shape {
16    /// Number of indices contained in `indices`
17    pub index_count: u32,
18    /// The vertices stored in a vertex buffer
19    pub vertices: Arc<VertexBuffer>,
20    /// An index buffer representing a TriangleList of indices within `vertices`
21    pub indices: Arc<IndexBuffer>,
22}
23
24impl Shape {
25    /// Draws the shape to the Pass.
26    ///
27    /// You should use `Pass::set_pipeline` before calling this method.
28    ///
29    /// # Arguments
30    ///
31    /// * `pass`- The render pass to draw to.
32    pub fn draw<'a>(&'a self, pass: &mut easygpu::wgpu::RenderPass<'a>) {
33        pass.set_vertex_buffer(0, self.vertices.slice());
34        pass.set_index_buffer(self.indices.slice(), easygpu::wgpu::IndexFormat::Uint16);
35        pass.draw_indexed(0..self.index_count, 0, 0..1)
36    }
37}