1use std::{fmt, slice};
2
3define_handle!(VertexBuffer);
4define_handle!(IndexBuffer);
5
6#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
8pub enum IndexType { U8, U16, U32 }
9
10impl IndexType {
11 #[inline]
12 pub const fn size(self) -> usize {
13 match self {
14 IndexType::U8 => 1,
15 IndexType::U16 => 2,
16 IndexType::U32 => 4,
17 }
18 }
19}
20
21pub trait TIndex: Copy + Ord + Default + dataview::Pod + fmt::Debug {
23 const TYPE: IndexType;
24}
25
26impl TIndex for u8 {
27 const TYPE: IndexType = IndexType::U8;
28}
29impl TIndex for u16 {
30 const TYPE: IndexType = IndexType::U16;
31}
32impl TIndex for u32 {
33 const TYPE: IndexType = IndexType::U32;
34}
35
36pub trait TIndices {
38 type Index: TIndex;
39
40 fn as_indices(&self) -> &[Self::Index];
41}
42impl<T: TIndex> TIndices for [T] {
43 type Index = T;
44
45 #[inline]
46 fn as_indices(&self) -> &[Self::Index] {
47 self
48 }
49}
50impl<T: TIndex, const N: usize> TIndices for [T; N] {
51 type Index = T;
52
53 #[inline]
54 fn as_indices(&self) -> &[Self::Index] {
55 self.as_slice()
56 }
57}
58impl<T: TIndex> TIndices for Vec<T> {
59 type Index = T;
60
61 #[inline]
62 fn as_indices(&self) -> &[Self::Index] {
63 self.as_slice()
64 }
65}
66
67#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
69#[repr(C)]
70pub struct Index3 {
71 pub p1: u32,
72 pub p2: u32,
73 pub p3: u32,
74}
75unsafe impl dataview::Pod for Index3 {}
76impl TIndices for Vec<Index3> {
77 type Index = u32;
78
79 #[inline]
80 fn as_indices(&self) -> &[Self::Index] {
81 unsafe { slice::from_raw_parts(self.as_ptr() as *const u32, self.len() * 3) }
82 }
83}
84
85#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
87pub enum PrimType {
88 Triangles,
90 Lines,
92}
93
94#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash)]
96#[non_exhaustive]
97pub enum BlendMode {
98 #[default]
105 Solid,
106
107 Alpha,
114
115 PremultipliedAlpha,
122
123 Additive,
129
130 Lighten,
136
137 Screen,
143
144 Darken,
150
151 Multiply,
157}
158
159#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
161pub enum Compare {
162 Never,
164 Less,
166 Equal,
168 NotEqual,
170 LessEqual,
172 Greater,
174 GreaterEqual,
176 Always,
178}
179
180#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
182pub enum CullMode {
183 CCW,
185 CW,
187}
188
189#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
191pub enum BufferUsage {
192 Static,
194 Dynamic,
196 Stream,
198}