1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::sync::Arc;

use bytemuck::{Pod, Zeroable};
use easygpu::{
    buffers::{IndexBuffer, VertexBuffer},
    color::Rgba8,
};

#[repr(C)]
#[derive(Copy, Clone, Debug, Pod, Zeroable)]
pub(crate) struct Vertex {
    pub position: [f32; 3],
    pub color: Rgba8,
}

/// Shape is a loaded, prepared ShapeBuilder that is ready to be drawn
pub struct Shape {
    /// Number of indices contained in `indices`
    pub index_count: u32,
    /// The vertices stored in a vertex buffer
    pub vertices: Arc<VertexBuffer>,
    /// An index buffer representing a TriangleList of indices within `vertices`
    pub indices: Arc<IndexBuffer>,
}

impl Shape {
    /// Draws the shape to the Pass.
    ///
    /// You should use `Pass::set_pipeline` before calling this method.
    ///
    /// # Arguments
    ///
    /// * `pass`- The render pass to draw to.
    pub fn draw<'a, 'b>(&'a self, pass: &'b mut easygpu::wgpu::RenderPass<'a>) {
        pass.set_vertex_buffer(0, self.vertices.slice());
        pass.set_index_buffer(self.indices.slice(), easygpu::wgpu::IndexFormat::Uint16);
        pass.draw_indexed(0..self.index_count, 0, 0..1)
    }
}