From c9821a4b9d113f2b6d75eb91a30d4b911ac819fd Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 1 Aug 2024 17:52:45 +0300 Subject: [PATCH] Don't allocate storage when loading metadata for a managed texture --- source/core/texture2d.cpp | 17 ++++++++++++----- source/core/texture2d.h | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/source/core/texture2d.cpp b/source/core/texture2d.cpp index aea88358..76d498b8 100644 --- a/source/core/texture2d.cpp +++ b/source/core/texture2d.cpp @@ -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) diff --git a/source/core/texture2d.h b/source/core/texture2d.h index 722da906..266b91c1 100644 --- a/source/core/texture2d.h +++ b/source/core/texture2d.h @@ -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 -- 2.45.2