From 839e04c5b583b51726207fc2508dce5c3afb3f04 Mon Sep 17 00:00:00 2001 From: Aaditya Dhruv Date: Fri, 30 Jan 2026 00:42:50 -0600 Subject: Add chunk_unloading on chunk Changes If we change a chunk, unload all chunks. This removes block GPU data (vbo, ebo, vao). We anyways redraw so we don't lose anything --- src/block.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/block.c') diff --git a/src/block.c b/src/block.c index 2197b2a..56db3f4 100644 --- a/src/block.c +++ b/src/block.c @@ -22,6 +22,12 @@ int block_init(vec3 pos, struct block* blk) { // Store buffer data into struct // Initialize vbo and ebo for block memcpy(blk->coords, pos, sizeof(vec3)); + block_load_gpu(blk); + block_update(blk); + return 0; +} + +void block_load_gpu(struct block* blk) { // ========== Constants of a block ================ // Local world coordinates float vertices[] = { @@ -122,8 +128,6 @@ int block_init(vec3 pos, struct block* blk) { //call is create_vbo. Since VAO is already bound, it gets bound to the OLD //VAO!! Always clear before use. glBindVertexArray(0); - block_update(blk); - return 0; } void block_update(struct block* blk) { @@ -172,3 +176,12 @@ void block_debug(struct block *blk) { glm_mat4_print(blk->model, stderr); } + +void block_unload(struct block *blk) { + // Clear VBO data + glDeleteBuffers(1, &blk->_vbo); + // Clear EBO data + glDeleteBuffers(1, &blk->_ebo); + // Clear VAO + glDeleteVertexArrays(1, &blk->_vao); +} -- cgit