delete meshes relative to deleted chunks
parent
bc3c5587f8
commit
4c46811a25
|
@ -26,8 +26,20 @@ namespace renderer{
|
||||||
|
|
||||||
buffers_allocated=true;
|
buffers_allocated=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deallocateBuffers(){
|
||||||
|
// Allocate buffers
|
||||||
|
glDeleteBuffers(1, &VBO);
|
||||||
|
glDeleteBuffers(1, &extentsBuffer);
|
||||||
|
glDeleteBuffers(1, &texinfoBuffer);
|
||||||
|
glDeleteVertexArrays(1, &VAO);
|
||||||
|
|
||||||
|
buffers_allocated=false;
|
||||||
|
}
|
||||||
} 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);
|
||||||
void render();
|
void render();
|
||||||
|
@ -39,6 +51,7 @@ namespace renderer{
|
||||||
|
|
||||||
Shader* getRenderShader();
|
Shader* getRenderShader();
|
||||||
ChunkMeshDataQueue& getMeshDataQueue();
|
ChunkMeshDataQueue& getMeshDataQueue();
|
||||||
|
IndexQueue& getDeleteIndexQueue();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,7 @@ namespace chunkmanager
|
||||||
Chunk::Chunk* c = a->second;
|
Chunk::Chunk* c = a->second;
|
||||||
if(chunks.erase(a)){
|
if(chunks.erase(a)){
|
||||||
nUnloaded++;
|
nUnloaded++;
|
||||||
|
renderer::getDeleteIndexQueue().push(index);
|
||||||
delete c;
|
delete c;
|
||||||
} else std::cout << "failed to delete " << index << std::endl;
|
} else std::cout << "failed to delete " << index << std::endl;
|
||||||
} else std::cout << "no such element found to delete\n";
|
} else std::cout << "no such element found to delete\n";
|
||||||
|
@ -200,17 +201,9 @@ namespace chunkmanager
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*std::cout << "time: " << glfwGetTime() << "\ntotal: " << chunks.size() << "\ngenerated: " << nGenerated << "\nmeshed: "
|
std::cout << "time: " << glfwGetTime() << "\ntotal: " << chunks.size() << "\ngenerated: " << nGenerated << "\nmeshed: "
|
||||||
<< nMeshed << "\nunloaded from prev loop: " << nUnloaded << "\nnew marked for
|
<< nMeshed << "\nunloaded from prev loop: " << nUnloaded << "\nnew marked for unload: " << nMarkUnload << std::endl;
|
||||||
unload: " << nMarkUnload << std::endl;
|
|
||||||
|
|
||||||
debug::window::set_parameter("update_chunks_total", (int) chunks.size());
|
|
||||||
debug::window::set_parameter("update_chunks_buckets", (int) chunks.bucket_count());
|
|
||||||
debug::window::set_parameter("update_chunks_freed", nUnloaded);
|
|
||||||
debug::window::set_parameter("update_chunks_generated", nGenerated);
|
|
||||||
debug::window::set_parameter("update_chunks_meshed", nMeshed);
|
|
||||||
debug::window::set_parameter("update_chunks_explored", nExplored);
|
|
||||||
debug::window::set_parameter("update_chunks_tobedeleted", 0);*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,18 +99,15 @@ namespace debug{
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ImGui::CollapsingHeader("Mesh")){
|
if(ImGui::CollapsingHeader("Mesh")){
|
||||||
ImGui::Text("Total chunks updated: %d",
|
ImGui::Text("Total chunk meshed: %d",
|
||||||
std::any_cast<int>(parameters.at("render_chunks_total")));
|
std::any_cast<int>(parameters.at("render_chunks_total")));
|
||||||
|
ImGui::Text("Of which renderable (not empty): %d",
|
||||||
|
std::any_cast<int>(parameters.at("render_chunks_renderable")));
|
||||||
ImGui::Text("Chunks rendered: %d",
|
ImGui::Text("Chunks rendered: %d",
|
||||||
std::any_cast<int>(parameters.at("render_chunks_rendered")));
|
std::any_cast<int>(parameters.at("render_chunks_rendered")));
|
||||||
ImGui::Text("Frustum culled: %d",
|
ImGui::Text("Frustum culled: %d",
|
||||||
std::any_cast<int>(parameters.at("render_chunks_culled")));
|
std::any_cast<int>(parameters.at("render_chunks_culled")));
|
||||||
ImGui::Text("Chunks out of view: %d",
|
ImGui::Text("Total vertices in the scene: %d",
|
||||||
std::any_cast<int>(parameters.at("render_chunks_oof")));
|
|
||||||
if(parameters.find("render_chunks_deleted") != parameters.end())
|
|
||||||
ImGui::Text("Chunks deleted: %d",
|
|
||||||
std::any_cast<int>(parameters.at("render_chunks_deleted")));
|
|
||||||
ImGui::Text("Vertices in the scene: %d",
|
|
||||||
std::any_cast<int>(parameters.at("render_chunks_vertices")));
|
std::any_cast<int>(parameters.at("render_chunks_vertices")));
|
||||||
ImGui::Checkbox("Wireframe",
|
ImGui::Checkbox("Wireframe",
|
||||||
std::any_cast<bool*>(parameters.at("wireframe_return")));
|
std::any_cast<bool*>(parameters.at("wireframe_return")));
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace renderer{
|
||||||
|
|
||||||
RenderTable ChunksToRender;
|
RenderTable ChunksToRender;
|
||||||
ChunkMeshDataQueue MeshDataQueue;
|
ChunkMeshDataQueue MeshDataQueue;
|
||||||
|
IndexQueue MeshDataToDelete;
|
||||||
|
|
||||||
Shader* theShader, *quadShader;
|
Shader* theShader, *quadShader;
|
||||||
GLuint chunkTexture;
|
GLuint chunkTexture;
|
||||||
|
@ -30,6 +31,7 @@ namespace renderer{
|
||||||
|
|
||||||
Shader* getRenderShader() { return theShader; }
|
Shader* getRenderShader() { return theShader; }
|
||||||
ChunkMeshDataQueue& getMeshDataQueue(){ return MeshDataQueue; }
|
ChunkMeshDataQueue& getMeshDataQueue(){ return MeshDataQueue; }
|
||||||
|
IndexQueue& getDeleteIndexQueue(){ return MeshDataToDelete; }
|
||||||
|
|
||||||
void init(GLFWwindow* window){
|
void init(GLFWwindow* window){
|
||||||
// Setup rendering
|
// Setup rendering
|
||||||
|
@ -140,8 +142,6 @@ namespace renderer{
|
||||||
theShader->use();
|
theShader->use();
|
||||||
theShader->setVec3("viewPos", cameraPos);
|
theShader->setVec3("viewPos", cameraPos);
|
||||||
|
|
||||||
// TODO: works but some stuff is rendered wrong (trees floating or inside the terrain,
|
|
||||||
// missing or malformed chunks)
|
|
||||||
ChunkMeshData* m;
|
ChunkMeshData* m;
|
||||||
while(MeshDataQueue.try_pop(m)){
|
while(MeshDataQueue.try_pop(m)){
|
||||||
RenderTable::accessor a;
|
RenderTable::accessor a;
|
||||||
|
@ -166,17 +166,26 @@ namespace renderer{
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement removal of chunks from rendering
|
// TODO: implement removal of chunks from rendering
|
||||||
std::cout << "chunks to render: " << ChunksToRender.size();
|
int32_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
|
||||||
for(RenderTable::iterator i = ChunksToRender.begin(); i != ChunksToRender.end(); i++){
|
for(RenderTable::iterator i = ChunksToRender.begin(); i != ChunksToRender.end(); i++){
|
||||||
RenderInfo* render_info = i->second;
|
RenderInfo* render_info = i->second;
|
||||||
|
|
||||||
total++;
|
|
||||||
if(render_info->num_vertices > 0)
|
if(render_info->num_vertices > 0)
|
||||||
{
|
{
|
||||||
|
total++;
|
||||||
|
|
||||||
// Increase total vertex count
|
// Increase total vertex count
|
||||||
vertices += render_info->num_vertices;
|
vertices += render_info->num_vertices;
|
||||||
|
@ -217,8 +226,9 @@ namespace renderer{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug::window::set_parameter("render_chunks_total", total);
|
debug::window::set_parameter("render_chunks_total", (int)(ChunksToRender.size()));
|
||||||
debug::window::set_parameter("render_chunks_rendered", toGpu);
|
debug::window::set_parameter("render_chunks_rendered", toGpu);
|
||||||
|
debug::window::set_parameter("render_chunks_renderable", total);
|
||||||
debug::window::set_parameter("render_chunks_culled", total-toGpu);
|
debug::window::set_parameter("render_chunks_culled", total-toGpu);
|
||||||
debug::window::set_parameter("render_chunks_vertices", vertices);
|
debug::window::set_parameter("render_chunks_vertices", vertices);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue