]> git.tdb.fi Git - libs/gl.git/commitdiff
Refresh vertex setup when loading vertices for a mesh
authorMikko Rasa <tdb@tdb.fi>
Mon, 25 Jan 2021 23:15:18 +0000 (01:15 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 25 Jan 2021 23:15:18 +0000 (01:15 +0200)
Also add a better guard against performing OpenGL calls from the loading
thread.

source/mesh.cpp
source/mesh.h

index 72936e66fb535a2e0020a896040221df2c60b777..51468f2f85f850cd7b59405b97e7e2ff17e32432 100644 (file)
@@ -208,8 +208,9 @@ void Mesh::unload()
 }
 
 
-Mesh::Loader::Loader(Mesh &m):
-       DataFile::ObjectLoader<Mesh>(m)
+Mesh::Loader::Loader(Mesh &m, bool g):
+       DataFile::ObjectLoader<Mesh>(m),
+       allow_gl_calls(g)
 {
        add("batch",    &Loader::batch);
        add("vertices", &Loader::vertices);
@@ -226,7 +227,11 @@ void Mesh::Loader::vertices(const vector<VertexComponent> &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();
index b23510e10b14485e8b9c531aee28f8a171d7bea3..57c87b7e42986ac31f94092612c373159b633a7a 100644 (file)
@@ -26,8 +26,11 @@ class Mesh: public Resource
 public:
        class Loader: public DataFile::ObjectLoader<Mesh>
        {
+       private:
+               bool allow_gl_calls;
+
        public:
-               Loader(Mesh &);
+               Loader(Mesh &, bool = true);
        private:
                void vertices(const std::vector<VertexComponent> &);
                void batch(PrimitiveType);