Use iterators for the generalization of the ground vertex and fragment shaders

This commit is contained in:
2022-10-24 23:10:03 +02:00
parent b1710f7f71
commit 2984d147fa
3 changed files with 21 additions and 19 deletions
+19 -17
View File
@@ -65,30 +65,32 @@ fn main() {
glium::texture::SrgbTexture2d::new(&display, image).unwrap()
});
let mut uniform_sampler_2d_str: String = "".to_string();
for i in 1..BIOMES_NUMBER {
uniform_sampler_2d_str += &format!(", tex{}", i);
}
let uniform_sampler_2d_str = (0..BIOMES_NUMBER)
.map(|i| format!("tex{}", i))
.collect::<Vec<String>>()
.join(", ");
let mut switch_v_biome_str: String = "".to_string();
for i in 0..BIOMES_NUMBER {
switch_v_biome_str += &format!(
"
let switch_v_biome_str = (0..BIOMES_NUMBER)
.map(|i| {
format!(
"
case {}u:
f_color = texture(tex{}, v_tex_coords);
break;
",
i, i
);
}
switch_v_biome_str += &format!(
"
i, i
)
})
.collect::<Vec<String>>()
.join("")
+ &format!(
"
default: // case {}u:
f_color = texture(tex{}, v_tex_coords);
",
BIOMES_NUMBER - 1,
BIOMES_NUMBER - 1
);
BIOMES_NUMBER - 1,
BIOMES_NUMBER - 1
);
let fragment = &format!(
"
@@ -99,7 +101,7 @@ fn main() {
out vec4 f_color;
uniform sampler2D tex0{};
uniform sampler2D {};
void main() {{
switch (v_biome) {{