From 9ed19bfc0e6384184d5bd009f2f71db70f280b47 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Thu, 26 Jan 2023 03:54:41 +0100 Subject: [PATCH] skip drawing empty chunks --- src/world/render.rs | 26 ++++++++++++++------------ src/world/worldgen.rs | 8 +------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/world/render.rs b/src/world/render.rs index 70e6132..ce5c115 100644 --- a/src/world/render.rs +++ b/src/world/render.rs @@ -73,18 +73,20 @@ pub fn draw_world( if let Some(key) = chunk.mesh_index { let mesh = meshes.get(key).expect("Mesh index pointing to nothing"); let world_position = (position.as_vec3() * CHUNK_SIZE as f32).to_array(); - target.0.draw( - &mesh.vertex_buffer, - &mesh.index_buffer, - &program.0, - &uniform! { - position_offset: world_position, - view: view, - perspective: perspective, - tex: texture_sampler - }, - &draw_parameters - ).unwrap(); + if mesh.index_buffer.len() > 0 { //maybe this is a bit hacky? + target.0.draw( + &mesh.vertex_buffer, + &mesh.index_buffer, + &program.0, + &uniform! { + position_offset: world_position, + view: view, + perspective: perspective, + tex: texture_sampler + }, + &draw_parameters + ).unwrap(); + } } } } diff --git a/src/world/worldgen.rs b/src/world/worldgen.rs index fa72ca6..1079975 100644 --- a/src/world/worldgen.rs +++ b/src/world/worldgen.rs @@ -6,19 +6,13 @@ use super::{ pub fn generate_world(position: IVec3, _seed: u32) -> BlockData { let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]); + //TODO actual world generation if position.y == -1 { for x in 0..CHUNK_SIZE { for z in 0..CHUNK_SIZE { blocks[x][0][z] = Block::Grass; } } - } else { - blocks[0][0][0] = Block::Stone; - blocks[1][0][0] = Block::Stone; - blocks[0][1][0] = Block::Stone; - blocks[0][2][0] = Block::Stone; - blocks[0][0][1] = Block::Stone; } - //TODO actual world generation blocks }