renderer: also delete meshes of old chunks
parent
7c82a71dd0
commit
ba95db4678
|
@ -39,6 +39,7 @@ namespace renderer{
|
||||||
}
|
}
|
||||||
} RenderInfo;
|
} RenderInfo;
|
||||||
|
|
||||||
|
typedef oneapi::tbb::concurrent_queue<int32_t> IndexQueue;
|
||||||
|
|
||||||
void init(GLFWwindow* window);
|
void init(GLFWwindow* window);
|
||||||
void send_chunk_to_gpu(ChunkMeshData* mesh_data, RenderInfo* render_info);
|
void send_chunk_to_gpu(ChunkMeshData* mesh_data, RenderInfo* render_info);
|
||||||
|
@ -51,6 +52,8 @@ namespace renderer{
|
||||||
|
|
||||||
Shader* getRenderShader();
|
Shader* getRenderShader();
|
||||||
ChunkMeshDataQueue& getMeshDataQueue();
|
ChunkMeshDataQueue& getMeshDataQueue();
|
||||||
|
IndexQueue& getDeleteIndexQueue();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,7 @@ namespace chunkmanager
|
||||||
// Using the key doesn't work
|
// Using the key doesn't work
|
||||||
if(chunks.erase(a)){
|
if(chunks.erase(a)){
|
||||||
nUnloaded++;
|
nUnloaded++;
|
||||||
|
renderer::getDeleteIndexQueue().push(index);
|
||||||
delete c;
|
delete c;
|
||||||
} else {
|
} else {
|
||||||
c->setState(Chunk::CHUNK_STATE_IN_DELETING_QUEUE, false);
|
c->setState(Chunk::CHUNK_STATE_IN_DELETING_QUEUE, false);
|
||||||
|
|
|
@ -17,12 +17,14 @@ namespace renderer{
|
||||||
|
|
||||||
RenderTable ChunksToRender;
|
RenderTable ChunksToRender;
|
||||||
ChunkMeshDataQueue MeshDataQueue;
|
ChunkMeshDataQueue MeshDataQueue;
|
||||||
|
IndexQueue MeshDataToDelete;
|
||||||
|
|
||||||
Shader* theShader, *quadShader;
|
Shader* theShader, *quadShader;
|
||||||
GLuint chunkTexture;
|
GLuint chunkTexture;
|
||||||
|
|
||||||
Shader* getRenderShader() { return theShader; }
|
Shader* getRenderShader() { return theShader; }
|
||||||
ChunkMeshDataQueue& getMeshDataQueue(){ return MeshDataQueue; }
|
ChunkMeshDataQueue& getMeshDataQueue(){ return MeshDataQueue; }
|
||||||
|
IndexQueue& getDeleteIndexQueue(){ return MeshDataToDelete; }
|
||||||
|
|
||||||
GLuint renderTexFrameBuffer, renderTex, renderTexDepthBuffer, quadVAO, quadVBO;
|
GLuint renderTexFrameBuffer, renderTex, renderTexDepthBuffer, quadVAO, quadVBO;
|
||||||
int screenWidth, screenHeight;
|
int screenWidth, screenHeight;
|
||||||
|
@ -139,6 +141,7 @@ namespace renderer{
|
||||||
theShader->use();
|
theShader->use();
|
||||||
theShader->setVec3("viewPos", cameraPos);
|
theShader->setVec3("viewPos", cameraPos);
|
||||||
|
|
||||||
|
/* Process incoming mesh data */
|
||||||
ChunkMeshData* m;
|
ChunkMeshData* m;
|
||||||
while(MeshDataQueue.try_pop(m)){
|
while(MeshDataQueue.try_pop(m)){
|
||||||
RenderTable::accessor a;
|
RenderTable::accessor a;
|
||||||
|
@ -161,7 +164,18 @@ namespace renderer{
|
||||||
chunkmesher::getMeshDataQueue().push(m);
|
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 */
|
/* Render the chunks */
|
||||||
// parallel_for cannot be used since all the rendering needs to happen in a single thread
|
// parallel_for cannot be used since all the rendering needs to happen in a single thread
|
||||||
|
|
Loading…
Reference in New Issue