]> git.tdb.fi Git - libs/gl.git/commitdiff
Don't allocate storage when loading metadata for a managed texture
authorMikko Rasa <tdb@tdb.fi>
Thu, 1 Aug 2024 14:52:45 +0000 (17:52 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 1 Aug 2024 14:52:45 +0000 (17:52 +0300)
source/core/texture2d.cpp
source/core/texture2d.h

index aea88358254feab02c8669e1baad1919a6cbcc6b..76d498b8d5e4ac935027f763cd6b35ed9db55501 100644 (file)
@@ -35,6 +35,12 @@ Texture2D::~Texture2D()
 }
 
 void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv)
+{
+       set_storage(fmt, wd, ht, lv);
+       allocate();
+}
+
+void Texture2D::set_storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv)
 {
        if(width>0)
        {
@@ -51,8 +57,6 @@ void Texture2D::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned lv)
        n_levels = count_levels(max(width, height));
        if(lv>0)
                n_levels = min(n_levels, lv);
-
-       allocate();
 }
 
 void Texture2D::image(unsigned level, const void *data)
@@ -121,12 +125,14 @@ void Texture2D::Loader::init()
 
 void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h)
 {
-       obj.storage(fmt, w, h);
+       storage_levels(fmt, w, h, 0);
 }
 
 void Texture2D::Loader::storage_levels(PixelFormat fmt, unsigned w, unsigned h, unsigned l)
 {
-       obj.storage(fmt, w, h, l);
+       obj.set_storage(fmt, w, h, l);
+       if(!obj.manager)
+               obj.allocate();
 }
 
 
@@ -225,9 +231,10 @@ bool Texture2D::AsyncLoader::process()
                {
                        unsigned w = image.get_width();
                        unsigned h = image.get_height();
-                       texture.storage(pixelformat_from_image(image, texture.use_srgb_format), w, h);
+                       texture.set_storage(pixelformat_from_image(image, texture.use_srgb_format), w, h, 0);
                }
 
+               texture.allocate();
                transfer = texture.sub_image_async(0, 0, 0, texture.width, texture.height);
        }
        else if(phase==2)
index 722da906e70cd23c9db52b566ed45f3596962794..266b91c1af0c20ec573a62f8076ae494a17d8781 100644 (file)
@@ -76,6 +76,10 @@ public:
        cannot be changed once set. */
        void storage(PixelFormat, unsigned wd, unsigned ht, unsigned lv = 0);
 
+private:
+       void set_storage(PixelFormat, unsigned, unsigned, unsigned);
+
+public:
        void image(unsigned level, const void *) override;
 
        /** Replaces a rectangular region of the texture.  Allocated storage must