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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use crate::error::SarektResult;
use ultraviolet as uv;
pub unsafe trait VertexBindings {
type BVA;
type BVB;
fn get_binding_description() -> Self::BVB;
fn get_attribute_descriptions() -> Vec<Self::BVA>;
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct DefaultForwardShaderVertex {
pub position: uv::Vec3,
pub color: uv::Vec3,
pub texture_coordinates: uv::Vec2,
}
impl DefaultForwardShaderVertex {
pub fn without_uv(pos: &[f32; 3], color: &[f32; 3]) -> Self {
Self::new(pos, color, &[0.0f32, 0.0f32])
}
pub fn new_with_texture(pos: &[f32; 3], texture_coordinates: &[f32; 2]) -> Self {
Self {
position: uv::Vec3::from(pos),
color: uv::Vec3::new(1f32, 1f32, 1f32),
texture_coordinates: uv::Vec2::from(texture_coordinates),
}
}
pub fn new(pos: &[f32; 3], color: &[f32; 3], texture_coordinates: &[f32; 2]) -> Self {
Self {
position: uv::Vec3::from(pos),
color: uv::Vec3::from(color),
texture_coordinates: uv::Vec2::from(texture_coordinates),
}
}
}
pub unsafe trait DescriptorLayoutInfo {
type BackendDescriptorSetLayoutBindings;
fn get_descriptor_set_layout_bindings() -> Self::BackendDescriptorSetLayoutBindings;
fn get_bind_uniform_info() -> SarektResult<BindUniformInfo>;
fn get_bind_texture_info() -> SarektResult<BindTextureInfo>;
}
#[derive(Clone, Debug)]
pub struct BindUniformInfo {
pub offset: u64,
pub range: u64,
pub bindings: Vec<u32>,
}
pub struct BindTextureInfo {
pub bindings: Vec<u32>,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct DefaultForwardShaderLayout {
pub mvp: uv::Mat4,
pub enable_color_mixing: u32,
pub enable_texture_mixing: u32,
}
impl DefaultForwardShaderLayout {
pub fn new(mvp: uv::Mat4, enable_color_mixing: bool, enable_texture_mixing: bool) -> Self {
Self {
mvp,
enable_color_mixing: u32::from(enable_color_mixing),
enable_texture_mixing: u32::from(enable_texture_mixing),
}
}
}
impl Default for DefaultForwardShaderLayout {
fn default() -> Self {
DefaultForwardShaderLayout {
mvp: uv::Mat4::identity(),
enable_color_mixing: 0u32,
enable_texture_mixing: 1u32,
}
}
}