Merge pull request #99376 from clayjohn/basisu-defer-init

Defer initializing BasisU encoder until it is needed
This commit is contained in:
Thaddeus Crews 2024-11-18 09:23:35 -06:00
commit 1c1e833a43
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84

View File

@ -38,13 +38,12 @@
#include <transcoder/basisu_transcoder.h> #include <transcoder/basisu_transcoder.h>
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
#include <encoder/basisu_comp.h> #include <encoder/basisu_comp.h>
static Mutex init_mutex;
static bool initialized = false;
#endif #endif
void basis_universal_init() { void basis_universal_init() {
#ifdef TOOLS_ENABLED
basisu::basisu_encoder_init();
#endif
basist::basisu_transcoder_init(); basist::basisu_transcoder_init();
} }
@ -80,6 +79,13 @@ inline void _basisu_pad_mipmap(const uint8_t *p_image_mip_data, Vector<uint8_t>
} }
Vector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Image::UsedChannels p_channels) { Vector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Image::UsedChannels p_channels) {
init_mutex.lock();
if (!initialized) {
basisu::basisu_encoder_init();
initialized = true;
}
init_mutex.unlock();
uint64_t start_time = OS::get_singleton()->get_ticks_msec(); uint64_t start_time = OS::get_singleton()->get_ticks_msec();
Ref<Image> image = p_image->duplicate(); Ref<Image> image = p_image->duplicate();