delete meshes relative to deleted chunks
parent
bc3c5587f8
commit
4c46811a25
|
@ -26,8 +26,20 @@ namespace renderer{
|
|||
|
||||
buffers_allocated=true;
|
||||
}
|
||||
|
||||
void deallocateBuffers(){
|
||||
// Allocate buffers
|
||||
glDeleteBuffers(1, &VBO);
|
||||
glDeleteBuffers(1, &extentsBuffer);
|
||||
glDeleteBuffers(1, &texinfoBuffer);
|
||||
glDeleteVertexArrays(1, &VAO);
|
||||
|
||||
buffers_allocated=false;
|
||||
}
|
||||
} RenderInfo;
|
||||
|
||||
typedef oneapi::tbb::concurrent_queue<int32_t> IndexQueue;
|
||||
|
||||
void init(GLFWwindow* window);
|
||||
void send_chunk_to_gpu(ChunkMeshData* mesh_data, RenderInfo* render_info);
|
||||
void render();
|
||||
|
@ -39,6 +51,7 @@ namespace renderer{
|
|||
|
||||
Shader* getRenderShader();
|
||||
ChunkMeshDataQueue& getMeshDataQueue();
|
||||
IndexQueue& getDeleteIndexQueue();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -108,6 +108,7 @@ namespace chunkmanager
|
|||
Chunk::Chunk* c = a->second;
|
||||
if(chunks.erase(a)){
|
||||
nUnloaded++;
|
||||
renderer::getDeleteIndexQueue().push(index);
|
||||
delete c;
|
||||
} else std::cout << "failed to delete " << index << std::endl;
|
||||
} 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: "
|
||||
<< nMeshed << "\nunloaded from prev loop: " << nUnloaded << "\nnew marked for
|
||||
unload: " << nMarkUnload << std::endl;
|
||||
std::cout << "time: " << glfwGetTime() << "\ntotal: " << chunks.size() << "\ngenerated: " << nGenerated << "\nmeshed: "
|
||||
<< nMeshed << "\nunloaded from prev loop: " << nUnloaded << "\nnew marked for 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")){
|
||||
ImGui::Text("Total chunks updated: %d",
|
||||
ImGui::Text("Total chunk meshed: %d",
|
||||
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",
|
||||
std::any_cast<int>(parameters.at("render_chunks_rendered")));
|
||||
ImGui::Text("Frustum culled: %d",
|
||||
std::any_cast<int>(parameters.at("render_chunks_culled")));
|
||||
ImGui::Text("Chunks out of view: %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",
|
||||
ImGui::Text("Total vertices in the scene: %d",
|
||||
std::any_cast<int>(parameters.at("render_chunks_vertices")));
|
||||
ImGui::Checkbox("Wireframe",
|
||||
std::any_cast<bool*>(parameters.at("wireframe_return")));
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace renderer{
|
|||
|
||||
RenderTable ChunksToRender;
|
||||
ChunkMeshDataQueue MeshDataQueue;
|
||||
IndexQueue MeshDataToDelete;
|
||||
|
||||
Shader* theShader, *quadShader;
|
||||
GLuint chunkTexture;
|
||||
|
@ -30,6 +31,7 @@ namespace renderer{
|
|||
|
||||
Shader* getRenderShader() { return theShader; }
|
||||
ChunkMeshDataQueue& getMeshDataQueue(){ return MeshDataQueue; }
|
||||
IndexQueue& getDeleteIndexQueue(){ return MeshDataToDelete; }
|
||||
|
||||
void init(GLFWwindow* window){
|
||||
// Setup rendering
|
||||
|
@ -140,8 +142,6 @@ namespace renderer{
|
|||
theShader->use();
|
||||
theShader->setVec3("viewPos", cameraPos);
|
||||
|
||||
// TODO: works but some stuff is rendered wrong (trees floating or inside the terrain,
|
||||
// missing or malformed chunks)
|
||||
ChunkMeshData* m;
|
||||
while(MeshDataQueue.try_pop(m)){
|
||||
RenderTable::accessor a;
|
||||
|
@ -166,17 +166,26 @@ namespace renderer{
|
|||
}
|
||||
|
||||
// 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
|
||||
// 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++){
|
||||
RenderInfo* render_info = i->second;
|
||||
|
||||
total++;
|
||||
if(render_info->num_vertices > 0)
|
||||
{
|
||||
total++;
|
||||
|
||||
// Increase total vertex count
|
||||
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_renderable", total);
|
||||
debug::window::set_parameter("render_chunks_culled", total-toGpu);
|
||||
debug::window::set_parameter("render_chunks_vertices", vertices);
|
||||
|
||||
|
|
Loading…
Reference in New Issue