renderer: also delete meshes of old chunks

EmaMaker 2023-10-04 13:02:10 +02:00
parent 1d36a84f93
commit 86f906912e
3 changed files with 19 additions and 1 deletions

View File

@ -39,6 +39,7 @@ namespace renderer{
}
} RenderInfo;
typedef oneapi::tbb::concurrent_queue<int32_t> IndexQueue;
void init(GLFWwindow* window);
void send_chunk_to_gpu(ChunkMeshData* mesh_data, RenderInfo* render_info);
@ -51,6 +52,8 @@ namespace renderer{
Shader* getRenderShader();
ChunkMeshDataQueue& getMeshDataQueue();
IndexQueue& getDeleteIndexQueue();
};

View File

@ -116,6 +116,7 @@ namespace chunkmanager
// Using the key doesn't work
if(chunks.erase(a)){
nUnloaded++;
renderer::getDeleteIndexQueue().push(index);
delete c;
} else {
c->setState(Chunk::CHUNK_STATE_IN_DELETING_QUEUE, false);

View File

@ -17,12 +17,14 @@ namespace renderer{
RenderTable ChunksToRender;
ChunkMeshDataQueue MeshDataQueue;
IndexQueue MeshDataToDelete;
Shader* theShader, *quadShader;
GLuint chunkTexture;
Shader* getRenderShader() { return theShader; }
ChunkMeshDataQueue& getMeshDataQueue(){ return MeshDataQueue; }
IndexQueue& getDeleteIndexQueue(){ return MeshDataToDelete; }
GLuint renderTexFrameBuffer, renderTex, renderTexDepthBuffer, quadVAO, quadVBO;
int screenWidth, screenHeight;
@ -139,6 +141,7 @@ namespace renderer{
theShader->use();
theShader->setVec3("viewPos", cameraPos);
/* Process incoming mesh data */
ChunkMeshData* m;
while(MeshDataQueue.try_pop(m)){
RenderTable::accessor a;
@ -161,7 +164,18 @@ namespace renderer{
chunkmesher::getMeshDataQueue().push(m);
}
// TODO: implement removal of chunks from rendering
/* Process chunks to be removed */
chunk_index_t queue_index;
while(MeshDataToDelete.try_pop(queue_index)){
RenderTable::accessor a;
if(ChunksToRender.find(a, queue_index)){
RenderInfo* render_info = a->second;
render_info->deallocateBuffers();
delete render_info;
ChunksToRender.erase(a);
}
}
/* Render the chunks */
// parallel_for cannot be used since all the rendering needs to happen in a single thread