Skip to main content

mln_engine/draw/
segment.rs

1/// A range of a mesh's vertices and indexes that one draw call draws,
2/// within the 16-bit indexes of one segment, and its instances.
3#[derive(Clone, Debug, PartialEq, mln_wire::Wire)]
4pub struct SegmentBase {
5    pub vertex_offset: usize,
6    pub index_offset: usize,
7    pub vertex_length: usize,
8    pub index_length: usize,
9    pub base_instance: usize,
10    pub instance_count: usize,
11    pub sort_key: f32,
12}
13
14impl SegmentBase {
15    /// An empty segment from the vertex at `vertex_offset` and the index at
16    /// `index_offset`.
17    #[must_use]
18    pub fn new(vertex_offset: usize, index_offset: usize) -> Self {
19        Self::with_lengths(vertex_offset, index_offset, 0, 0)
20    }
21
22    /// The segment of `vertex_length` vertices and `index_length` indexes from
23    /// those offsets.
24    #[must_use]
25    pub fn with_lengths(vertex_offset: usize, index_offset: usize, vertex_length: usize, index_length: usize) -> Self {
26        SegmentBase {
27            vertex_offset,
28            index_offset,
29            vertex_length,
30            index_length,
31            base_instance: 0,
32            instance_count: 1,
33            sort_key: 0.0,
34        }
35    }
36
37    /// The field-by-field copy the C++ code spells out (there is no copy
38    /// constructor).
39    #[must_use]
40    pub fn copy(&self) -> Self {
41        SegmentBase {
42            vertex_offset: self.vertex_offset,
43            index_offset: self.index_offset,
44            vertex_length: self.vertex_length,
45            index_length: self.index_length,
46            base_instance: self.base_instance,
47            instance_count: self.instance_count,
48            sort_key: self.sort_key,
49        }
50    }
51}
52
53/// The most vertices a segment holds, since they are addressed by 16-bit
54/// indices.
55pub const MAX_SEGMENT_VERTICES: usize = u16::MAX as usize;