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/block.h | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) (limited to 'src/block.h') diff --git a/src/block.h b/src/block.h index ad81c47..d8e75d7 100644 --- a/src/block.h +++ b/src/block.h @@ -1,38 +1,13 @@ #pragma once -#include "cglm/types.h" -#include "glad/glad.h" -#include "shader.h" -#include "texture.h" +enum BLOCK_ID { + BLOCK_GRASS, +}; struct block { - vec3 coords; - GLuint _vao; - GLuint _vbo; - GLuint _ebo; - GLuint _tbo; - int _vertex_count; - mat4 model; - float angle; + enum BLOCK_ID block_id; }; /** - * Create a "block" object, which is the building blocks of this world. - * Blocks belong in chunks, and chunks belong in worlds. vec3 pos here is the coordinates of the block in WORLD space. - * However, a common method to render these blocks will be that the chunk will set the coordinates in "chunk space", and - * on a chunk_load, we will translate the blocks to wherever the chunk is loaded - * - * - */ -int block_init(vec3 pos, struct block* blk); -int block_draw(struct block* blk, struct shader* shader, struct texture* texture); -void block_debug(struct block* blk); -void block_update(struct block* blk); - -/** - * Remove GPU related data of a block. This is usually called by chunk_unload + * A block struct defines what kind of block we will be rendering. It's the metadata of the block array in a chunk * */ -void block_unload(struct block* blk); -/** - * Load GPU data of a block - */ -void block_load_gpu(struct block* blk); +int block_init(struct block* blk, enum BLOCK_ID block_id); -- cgit