shade/
common.rs

1use std::fmt;
2
3define_handle!(VertexBuffer);
4define_handle!(IndexBuffer);
5
6/// Index type for index buffers.
7#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
8pub enum IndexType { U8, U16, U32 }
9
10impl IndexType {
11	pub const fn size(self) -> usize {
12		match self {
13			IndexType::U8 => 1,
14			IndexType::U16 => 2,
15			IndexType::U32 => 4,
16		}
17	}
18}
19
20/// Trait for index types.
21pub trait TIndex: Copy + Ord + Default + dataview::Pod + fmt::Debug {
22	const TYPE: IndexType;
23}
24
25impl TIndex for u8 {
26	const TYPE: IndexType = IndexType::U8;
27}
28impl TIndex for u16 {
29	const TYPE: IndexType = IndexType::U16;
30}
31impl TIndex for u32 {
32	const TYPE: IndexType = IndexType::U32;
33}
34
35/// Primitive type.
36#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
37pub enum PrimType {
38	/// Triangles.
39	Triangles,
40	/// Lines.
41	Lines,
42}
43
44/// Blend mode.
45#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash)]
46pub enum BlendMode {
47	/// Solid color.
48	///
49	/// ```text
50	/// result[rgb] = src[rgb]
51	/// result[a] = src[a]
52	/// ```
53	#[default]
54	Solid,
55
56	/// Alpha blending.
57	///
58	/// ```text
59	/// result[rgb] = src[rgb] * src[a] + dest[rgb] * (1 - src[a])
60	/// result[a] = src[a] + dest[a] * (1 - src[a])
61	/// ```
62	Alpha,
63
64	/// Additive blending.
65	///
66	/// ```text
67	/// result[rgb] = src[rgb] + dest[rgb]
68	/// ```
69	Additive,
70
71	/// Maximum of the src and dest colors.
72	///
73	/// ```text
74	/// result[rgb] = max(src[rgb], dest[rgb])
75	/// ```
76	Lighten,
77
78	/// Screen effect.
79	///
80	/// ```text
81	/// result[rgb] = src[rgb] + (1 - dest[rgb])
82	/// ```
83	Screen,
84
85	/// Minimum of the src and dest colors.
86	///
87	/// ```text
88	/// result[rgb] = min(src[rgb], dest[rgb])
89	/// ```
90	Darken,
91
92	/// Multiply blending.
93	///
94	/// ```text
95	/// result[rgb] = src[rgb] * dest[rgb]
96	/// ```
97	Multiply,
98}
99
100/// Depth test.
101#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
102pub enum DepthTest {
103	/// Never pass.
104	Never,
105	/// Pass if the new depth is less than the old depth.
106	Less,
107	/// Pass if the new depth is equal to the old depth.
108	Equal,
109	/// Pass if the new depth is not equal to the old depth.
110	NotEqual,
111	/// Pass if the new depth is less than or equal to the old depth.
112	LessEqual,
113	/// Pass if the new depth is greater than the old depth.
114	Greater,
115	/// Pass if the new depth is greater than or equal to the old depth.
116	GreaterEqual,
117	/// Always pass.
118	Always,
119}
120
121/// Cull mode.
122#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
123pub enum CullMode {
124	/// Cull counter-clockwise faces.
125	CCW,
126	/// Cull clockwise faces.
127	CW,
128}
129
130/// Buffer usage.
131#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
132pub enum BufferUsage {
133	/// Buffer is static and used frequently.
134	Static,
135	/// Buffer is dynamic and used frequently.
136	Dynamic,
137	/// Buffer is streamed and used infrequently.
138	Stream,
139}