Fix #2: Optimize ground rendering using triangle strip

This commit is contained in:
2022-10-23 01:52:24 +02:00
parent f028ad7bb7
commit 76d64b6660
3 changed files with 81 additions and 64 deletions
+17 -18
View File
@@ -83,30 +83,26 @@ fn main() {
const uint TILE_SIZE = 4u;
void main() {
uint index_mod = index % 6u;
uint index_div = index / 6u;
uint index_mod_502 = index % 502u;
uint index_div_502 = index / 502u;
uint index_div_502_mod_2 = index_div_502 % 2u;
uint index_mod_502_div_2 = index_mod_502 / 2u;
uint z = index_div / 250u;
uint x = index_div % 250u;
uint x = index_div_502_mod_2 == 0u ? index_mod_502_div_2 : 250u - index_mod_502_div_2;
uint z = index_div_502 + index % 2u;
switch (index_mod) {
switch (index % 4u) {
case 0u:
v_tex_coords = vec2(0, 0);
v_tex_coords = vec2(index_div_502_mod_2, 0);
break;
case 1u:
case 4u:
v_tex_coords = vec2(0, 1);
x++;
v_tex_coords = vec2(index_div_502_mod_2, 1);
break;
case 2u:
case 3u:
v_tex_coords = vec2(1, 0);
z++;
v_tex_coords = vec2(1u - index_div_502_mod_2, 0);
break;
default: // case 5u
v_tex_coords = vec2(1, 1);
x++;
z++;
default: // case 3u
v_tex_coords = vec2(1u - index_div_502_mod_2, 1);
break;
}
v_biome = biome;
@@ -187,8 +183,11 @@ fn main() {
case 17u:
f_color = texture(tex17, v_tex_coords);
break;
default: // case 18u:
case 18u:
f_color = texture(tex18, v_tex_coords);
break;
default: // case 19u:
f_color = vec4(0.0, 0.0, 0.0, 1.0);
}
}
"
@@ -246,7 +245,7 @@ fn main() {
target
.draw(
&vertex_buffer,
&glium::index::NoIndices(glium::index::PrimitiveType::TrianglesList),
&glium::index::NoIndices(glium::index::PrimitiveType::TriangleStrip),
&program,
&uniforms,
&params,