renderer: do not send empty meshes to the gpu only at creation

I feel never sending empty meshes to the GPU is the cause of the bug causing floating quads near
chunk borders when a block is placed and then destroyed.
When destroying a block in a chunk, if nearby empty chunk meshes are not updated, the old mesh is
kept, which includes a quad at the border
pull/14/head^2
EmaMaker 2023-10-04 13:55:32 +02:00
parent 8544620899
commit 9b5939d256
1 changed files with 28 additions and 24 deletions

View File

@ -151,6 +151,11 @@ namespace renderer{
render_info = a->second; render_info = a->second;
render_info->position = m->position; render_info->position = m->position;
render_info->num_vertices = m->num_vertices; render_info->num_vertices = m->num_vertices;
// Always updated the mesh, even if it's empty
// This should solve the problem of having floating quads when destroying a block
// near chunk borders
send_chunk_to_gpu(m, render_info);
}else{ }else{
render_info = new RenderInfo(); render_info = new RenderInfo();
render_info->index = m->index; render_info->index = m->index;
@ -158,9 +163,11 @@ namespace renderer{
render_info->num_vertices = m->num_vertices; render_info->num_vertices = m->num_vertices;
ChunksToRender.emplace(a, std::make_pair(render_info->index, render_info)); ChunksToRender.emplace(a, std::make_pair(render_info->index, render_info));
// Only send the mesh to the GPU if it's not empty
if(render_info->num_vertices > 0) send_chunk_to_gpu(m, render_info);
} }
send_chunk_to_gpu(m, render_info);
chunkmesher::getMeshDataQueue().push(m); chunkmesher::getMeshDataQueue().push(m);
} }
@ -253,8 +260,6 @@ namespace renderer{
} }
void send_chunk_to_gpu(ChunkMeshData* mesh_data, RenderInfo* render_info) void send_chunk_to_gpu(ChunkMeshData* mesh_data, RenderInfo* render_info)
{
if (render_info->num_vertices > 0)
{ {
if(!render_info->buffers_allocated) render_info->allocateBuffers(); if(!render_info->buffers_allocated) render_info->allocateBuffers();
@ -283,7 +288,6 @@ namespace renderer{
glBindVertexArray(0); glBindVertexArray(0);
} }
}
void framebuffer_size_callback(GLFWwindow *window, int width, int height){ void framebuffer_size_callback(GLFWwindow *window, int width, int height){