From 7f13b0abaa76a5e90674d5733f8162f02ceab693 Mon Sep 17 00:00:00 2001 From: Aaditya Dhruv Date: Sat, 31 Jan 2026 03:22:27 -0600 Subject: Rework chunk rendering to get a 100x performance boost! - Switching to semi-chunk mesh rendering just 100x the framerate, it was running at around 100fps for 3 CHUNK_DISTANCE, and pushing it above would make it drop to 30. Now it runs at 9000 frames per second with CHUNK_DISTANCE of 8, probably can push it even more - What is bizarre is this is just from the reduction in draw calls, I still need to implement face culling for invisible blocks (simple) and frustrum culling (using AABB) or maybe octrees - Block is way way more simplifed, it's just metadata about a coordinate in the chunk block array - All rendering and mesh generation code is handled by chunks. There is a VAO, single VBO and EBO for each chunk. The data buffer is loaded into the GPU with a chunk_load, and it stays like that until it is loaded again. chunk_load is called if we move chunks, in engine_update. Here we unload existing chunks, then load the new ones --- src/engine.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/engine.h') diff --git a/src/engine.h b/src/engine.h index e7ffdaa..567d9a5 100644 --- a/src/engine.h +++ b/src/engine.h @@ -9,7 +9,7 @@ // We want a square around curr_chunk, and a side of the square will be 1 // (center chunk) + 2 * CHUNK_DISTANCE (either side of center) // loaded chunks = (1 + CHUNK_DISTANCE * 2)^2 -#define CHUNK_DISTANCE 3 +#define CHUNK_DISTANCE 5 struct engine { struct window* window; @@ -31,7 +31,7 @@ int engine_init(struct engine* engine); /** * Take all objects in the engine, apply the shader pipeline and draw on the window - * Apply block, chunk and camera updates as well. This is the main game loop + * Apply chunk and camera updates as well. This is the main game loop * * @param engine The target engine */ -- cgit