diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index c754ce84b0..3cd11090e1 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -2675,6 +2675,28 @@ adjust_size(int &x_size, int &y_size, const string &name, return false; } +//////////////////////////////////////////////////////////////////// +// Function: Texture::ensure_loader_type +// Access: Public, Virtual +// Description: May be called prior to calling read_txo() or any +// bam-related Texture-creating callback, to ensure that +// the proper dynamic libraries for a Texture of the +// current class type, and the indicated filename, have +// been already loaded. +// +// This is a low-level function that should not normally +// need to be called directly by the user. +// +// Note that for best results you must first create a +// Texture object of the appropriate class type for your +// filename, for instance with +// TexturePool::make_texture(). +//////////////////////////////////////////////////////////////////// +void Texture:: +ensure_loader_type(const Filename &filename) { + // For a plain Texture type, this doesn't need to do anything. +} + //////////////////////////////////////////////////////////////////// // Function: Texture::reconsider_dirty // Access: Protected, Virtual diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 04842a5c32..73307e02da 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -520,6 +520,8 @@ public: INLINE bool adjust_this_size(int &x_size, int &y_size, const string &name, bool for_padding) const; + virtual void ensure_loader_type(const Filename &filename); + protected: class CData; diff --git a/panda/src/gobj/texturePool.cxx b/panda/src/gobj/texturePool.cxx index ae313ebe01..92cae15cbb 100644 --- a/panda/src/gobj/texturePool.cxx +++ b/panda/src/gobj/texturePool.cxx @@ -1090,6 +1090,17 @@ try_load_cache(PT(Texture) &tex, BamCache *cache, const Filename &filename, // The texture was not supplied by a texture filter. See if it // can be found in the on-disk cache, if it is active. if ((cache->get_cache_textures() || cache->get_cache_compressed_textures()) && !textures_header_only) { + + // Call ns_make_texture() on the file extension and create a + // dummy texture object we can call ensure_loaded_type() on. We + // don't need to keep this object around after this call, since + // we'll be creating a new one below. I know this is a bit + // hacky. + string ext = downcase(filename.get_extension()); + PT(Texture) dummy = ns_make_texture(ext); + dummy->ensure_loader_type(filename); + dummy.clear(); + record = cache->lookup(filename, "txo"); if (record != (BamCacheRecord *)NULL) { if (record->has_data()) { diff --git a/panda/src/grutil/movieTexture.cxx b/panda/src/grutil/movieTexture.cxx index a5cfd7b876..9ab38fe4c5 100644 --- a/panda/src/grutil/movieTexture.cxx +++ b/panda/src/grutil/movieTexture.cxx @@ -18,6 +18,7 @@ #include "movieVideo.h" #include "movieVideoCursor.h" +#include "movieTypeRegistry.h" #include "movieTexture.h" #include "clockObject.h" #include "config_gobj.h" @@ -125,6 +126,32 @@ MovieTexture:: clear(); } +//////////////////////////////////////////////////////////////////// +// Function: MovieTexture::ensure_loader_type +// Access: Public, Virtual +// Description: May be called prior to calling read_txo() or any +// bam-related Texture-creating callback, to ensure that +// the proper dynamic libraries for a Texture of the +// current class type, and the indicated filename, have +// been already loaded. +// +// This is a low-level function that should not normally +// need to be called directly by the user. +// +// Note that for best results you must first create a +// Texture object of the appropriate class type for your +// filename, for instance with +// TexturePool::make_texture(). +//////////////////////////////////////////////////////////////////// +void MovieTexture:: +ensure_loader_type(const Filename &filename) { + // Creating a MovieVideo of the appropriate type is a slightly hacky + // way to ensure the appropriate libraries are loaded. We can let + // the MovieVideo we create immediately destruct. + MovieTypeRegistry *reg = MovieTypeRegistry::get_global_ptr(); + PT(MovieVideo) video = reg->make_video(filename); +} + //////////////////////////////////////////////////////////////////// // Function: MovieTexture::make_texture // Access: Public, Static diff --git a/panda/src/grutil/movieTexture.h b/panda/src/grutil/movieTexture.h index 99b469bf1f..8dd78481ca 100644 --- a/panda/src/grutil/movieTexture.h +++ b/panda/src/grutil/movieTexture.h @@ -64,6 +64,8 @@ PUBLISHED: void unsynchronize(); public: + virtual void ensure_loader_type(const Filename &filename); + static PT(Texture) make_texture(); virtual bool has_cull_callback() const; virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const;