From c89b596e05705f9a23f6c5cdf0b98ffd5f8f273c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 26 Jan 2021 01:15:18 +0200 Subject: [PATCH] Refresh vertex setup when loading vertices for a mesh Also add a better guard against performing OpenGL calls from the loading thread. --- source/mesh.cpp | 14 ++++++++++---- source/mesh.h | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/source/mesh.cpp b/source/mesh.cpp index 72936e66..51468f2f 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -208,8 +208,9 @@ void Mesh::unload() } -Mesh::Loader::Loader(Mesh &m): - DataFile::ObjectLoader(m) +Mesh::Loader::Loader(Mesh &m, bool g): + DataFile::ObjectLoader(m), + allow_gl_calls(g) { add("batch", &Loader::batch); add("vertices", &Loader::vertices); @@ -226,7 +227,11 @@ void Mesh::Loader::vertices(const vector &c) fmt = (fmt, *i); obj.vertices.reset(fmt); load_sub(obj.vertices); - obj.check_buffers(VERTEX_BUFFER); + if(allow_gl_calls) + { + obj.check_buffers(VERTEX_BUFFER); + obj.vtx_setup.set_vertex_array(obj.vertices); + } } void Mesh::Loader::batch(PrimitiveType p) @@ -274,12 +279,13 @@ bool Mesh::AsyncLoader::process() { // TODO use correct filename DataFile::Parser parser(io, "async"); - Loader loader(mesh); + Loader loader(mesh, false); loader.load(parser); } else if(phase==1) { mesh.resize_buffers(); + mesh.vtx_setup.set_vertex_array(vertices); vertex_updater = mesh.vertices.refresh_async(); if(!mesh.batches.empty()) index_updater = mesh.batches.front().refresh_async(); diff --git a/source/mesh.h b/source/mesh.h index b23510e1..57c87b7e 100644 --- a/source/mesh.h +++ b/source/mesh.h @@ -26,8 +26,11 @@ class Mesh: public Resource public: class Loader: public DataFile::ObjectLoader { + private: + bool allow_gl_calls; + public: - Loader(Mesh &); + Loader(Mesh &, bool = true); private: void vertices(const std::vector &); void batch(PrimitiveType); -- 2.45.2