Use altitude: f32 and index: u32 instead of respectively position: vec3 and tex_coords: vec2

It reduces GPU memory usage from 20-21MiB to 16-17MiB.
This commit is contained in:
2022-10-17 01:38:18 +02:00
parent e6e30712b0
commit 02e28b2bc8
2 changed files with 48 additions and 19 deletions
+23 -15
View File
@@ -59,12 +59,12 @@ where
pub fn load_ground(display: &Display) -> VertexBufferAny {
#[derive(Copy, Clone)]
struct Vertex {
position: [f32; 3],
altitude: f32,
normal: [f32; 3],
tex_coords: [f32; 2],
index: u32,
}
implement_vertex!(Vertex, position, normal, tex_coords);
implement_vertex!(Vertex, altitude, normal, index);
let mut vertex_data: Vec<Vertex> = Vec::new();
@@ -72,6 +72,8 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
let lines: Vec<&str> = contents.split('\n').collect();
let mut index: u32 = 0;
for lines_index in 0..lines.len() - 1 {
let line = lines[lines_index];
let next_line = lines[lines_index + 1];
@@ -88,42 +90,48 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
// First triangle.
vertex_data.push(Vertex {
position: [lines_index as f32, column, columns_index as f32],
altitude: column,
normal: [0.0, 0.0, 1.0],
tex_coords: [0.0, 0.0],
index,
});
index += 1;
vertex_data.push(Vertex {
position: [lines_index as f32, column_right, (columns_index + 1) as f32],
altitude: column_right,
normal: [0.0, 0.0, 1.0],
tex_coords: [0.0, 1.0],
index,
});
index += 1;
vertex_data.push(Vertex {
position: [(lines_index + 1) as f32, column_below, columns_index as f32],
altitude: column_below,
normal: [0.0, 0.0, 1.0],
tex_coords: [1.0, 0.0],
index,
});
index += 1;
// Second triangle.
vertex_data.push(Vertex {
position: [(lines_index + 1) as f32, column_below, columns_index as f32],
altitude: column_below,
normal: [0.0, 0.0, 1.0],
tex_coords: [1.0, 0.0],
index,
});
index += 1;
vertex_data.push(Vertex {
position: [lines_index as f32, column_right, (columns_index + 1) as f32],
altitude: column_right,
normal: [0.0, 0.0, 1.0],
tex_coords: [0.0, 1.0],
index,
});
index += 1;
vertex_data.push(Vertex {
position: [(lines_index + 1) as f32, column_below_right, (columns_index + 1) as f32],
altitude: column_below_right,
normal: [0.0, 0.0, 1.0],
tex_coords: [1.0, 1.0],
index,
});
index += 1;
}
}