rend3_routine/common/
vertex.rs

1use rend3::managers::{
2    VERTEX_COLOR_SLOT, VERTEX_JOINT_INDEX_SLOT, VERTEX_JOINT_WEIGHT_SLOT, VERTEX_NORMAL_SLOT, VERTEX_OBJECT_INDEX_SLOT,
3    VERTEX_POSITION_SLOT, VERTEX_TANGENT_SLOT, VERTEX_UV0_SLOT, VERTEX_UV1_SLOT,
4};
5use wgpu::{VertexAttribute, VertexBufferLayout, VertexFormat, VertexStepMode};
6
7/// Vertex buffer layouts used when CpuDriven.
8pub static CPU_VERTEX_BUFFERS: [VertexBufferLayout<'static>; 8] = [
9    VertexBufferLayout {
10        array_stride: rend3::managers::VERTEX_POSITION_SIZE as u64,
11        step_mode: VertexStepMode::Vertex,
12        attributes: &[VertexAttribute {
13            format: VertexFormat::Float32x3,
14            offset: 0,
15            shader_location: VERTEX_POSITION_SLOT,
16        }],
17    },
18    VertexBufferLayout {
19        array_stride: rend3::managers::VERTEX_NORMAL_SIZE as u64,
20        step_mode: VertexStepMode::Vertex,
21        attributes: &[VertexAttribute {
22            format: VertexFormat::Float32x3,
23            offset: 0,
24            shader_location: VERTEX_NORMAL_SLOT,
25        }],
26    },
27    VertexBufferLayout {
28        array_stride: rend3::managers::VERTEX_TANGENT_SIZE as u64,
29        step_mode: VertexStepMode::Vertex,
30        attributes: &[VertexAttribute {
31            format: VertexFormat::Float32x3,
32            offset: 0,
33            shader_location: VERTEX_TANGENT_SLOT,
34        }],
35    },
36    VertexBufferLayout {
37        array_stride: rend3::managers::VERTEX_UV_SIZE as u64,
38        step_mode: VertexStepMode::Vertex,
39        attributes: &[VertexAttribute {
40            format: VertexFormat::Float32x2,
41            offset: 0,
42            shader_location: VERTEX_UV0_SLOT,
43        }],
44    },
45    VertexBufferLayout {
46        array_stride: rend3::managers::VERTEX_UV_SIZE as u64,
47        step_mode: VertexStepMode::Vertex,
48        attributes: &[VertexAttribute {
49            format: VertexFormat::Float32x2,
50            offset: 0,
51            shader_location: VERTEX_UV1_SLOT,
52        }],
53    },
54    VertexBufferLayout {
55        array_stride: rend3::managers::VERTEX_COLOR_SIZE as u64,
56        step_mode: VertexStepMode::Vertex,
57        attributes: &[VertexAttribute {
58            format: VertexFormat::Unorm8x4,
59            offset: 0,
60            shader_location: VERTEX_COLOR_SLOT,
61        }],
62    },
63    VertexBufferLayout {
64        array_stride: rend3::managers::VERTEX_JOINT_INDEX_SIZE as u64,
65        step_mode: VertexStepMode::Vertex,
66        attributes: &[VertexAttribute {
67            format: VertexFormat::Uint16x4,
68            offset: 0,
69            shader_location: VERTEX_JOINT_INDEX_SLOT,
70        }],
71    },
72    VertexBufferLayout {
73        array_stride: rend3::managers::VERTEX_JOINT_WEIGHT_SIZE as u64,
74        step_mode: VertexStepMode::Vertex,
75        attributes: &[VertexAttribute {
76            format: VertexFormat::Float32x4,
77            offset: 0,
78            shader_location: VERTEX_JOINT_WEIGHT_SLOT,
79        }],
80    },
81];
82
83/// Vertex buffer layouts used when GpuDriven.
84pub static GPU_VERTEX_BUFFERS: [VertexBufferLayout<'static>; 9] = [
85    VertexBufferLayout {
86        array_stride: rend3::managers::VERTEX_POSITION_SIZE as u64,
87        step_mode: VertexStepMode::Vertex,
88        attributes: &[VertexAttribute {
89            format: VertexFormat::Float32x3,
90            offset: 0,
91            shader_location: VERTEX_POSITION_SLOT,
92        }],
93    },
94    VertexBufferLayout {
95        array_stride: rend3::managers::VERTEX_NORMAL_SIZE as u64,
96        step_mode: VertexStepMode::Vertex,
97        attributes: &[VertexAttribute {
98            format: VertexFormat::Float32x3,
99            offset: 0,
100            shader_location: VERTEX_NORMAL_SLOT,
101        }],
102    },
103    VertexBufferLayout {
104        array_stride: rend3::managers::VERTEX_TANGENT_SIZE as u64,
105        step_mode: VertexStepMode::Vertex,
106        attributes: &[VertexAttribute {
107            format: VertexFormat::Float32x3,
108            offset: 0,
109            shader_location: VERTEX_TANGENT_SLOT,
110        }],
111    },
112    VertexBufferLayout {
113        array_stride: rend3::managers::VERTEX_UV_SIZE as u64,
114        step_mode: VertexStepMode::Vertex,
115        attributes: &[VertexAttribute {
116            format: VertexFormat::Float32x2,
117            offset: 0,
118            shader_location: VERTEX_UV0_SLOT,
119        }],
120    },
121    VertexBufferLayout {
122        array_stride: rend3::managers::VERTEX_UV_SIZE as u64,
123        step_mode: VertexStepMode::Vertex,
124        attributes: &[VertexAttribute {
125            format: VertexFormat::Float32x2,
126            offset: 0,
127            shader_location: VERTEX_UV1_SLOT,
128        }],
129    },
130    VertexBufferLayout {
131        array_stride: rend3::managers::VERTEX_COLOR_SIZE as u64,
132        step_mode: VertexStepMode::Vertex,
133        attributes: &[VertexAttribute {
134            format: VertexFormat::Unorm8x4,
135            offset: 0,
136            shader_location: VERTEX_COLOR_SLOT,
137        }],
138    },
139    VertexBufferLayout {
140        array_stride: rend3::managers::VERTEX_JOINT_INDEX_SIZE as u64,
141        step_mode: VertexStepMode::Vertex,
142        attributes: &[VertexAttribute {
143            format: VertexFormat::Uint16x4,
144            offset: 0,
145            shader_location: VERTEX_JOINT_INDEX_SLOT,
146        }],
147    },
148    VertexBufferLayout {
149        array_stride: rend3::managers::VERTEX_JOINT_WEIGHT_SIZE as u64,
150        step_mode: VertexStepMode::Vertex,
151        attributes: &[VertexAttribute {
152            format: VertexFormat::Uint16x4,
153            offset: 0,
154            shader_location: VERTEX_JOINT_WEIGHT_SLOT,
155        }],
156    },
157    VertexBufferLayout {
158        array_stride: 20,
159        step_mode: VertexStepMode::Instance,
160        attributes: &[VertexAttribute {
161            format: VertexFormat::Uint32,
162            offset: 16,
163            shader_location: VERTEX_OBJECT_INDEX_SLOT,
164        }],
165    },
166];