diff --git a/panda/src/gobj/texturePool.I b/panda/src/gobj/texturePool.I index 1c25485f51..c04627d75c 100644 --- a/panda/src/gobj/texturePool.I +++ b/panda/src/gobj/texturePool.I @@ -33,6 +33,29 @@ verify_texture(const Filename &filename) { return load_texture(filename) != nullptr; } +/** + * Returns the texture that has already been previously loaded, or NULL + * otherwise. + */ +INLINE Texture *TexturePool:: +get_texture(const Filename &filename, int primary_file_num_channels, + bool read_mipmaps) { + return get_global_ptr()->ns_get_texture(filename, primary_file_num_channels, + read_mipmaps); +} + +/** + * Returns the texture that has already been previously loaded, or NULL + * otherwise. + */ +INLINE Texture *TexturePool:: +get_texture(const Filename &filename, const Filename &alpha_filename, + int primary_file_num_channels, int alpha_file_channel, + bool read_mipmaps) { + return get_global_ptr()->ns_get_texture(filename, primary_file_num_channels, + read_mipmaps); +} + /** * Loads the given filename up into a texture, if it has not already been * loaded, and returns the new texture. If a texture with the same filename diff --git a/panda/src/gobj/texturePool.cxx b/panda/src/gobj/texturePool.cxx index c09df1d9e3..40c67b9c92 100644 --- a/panda/src/gobj/texturePool.cxx +++ b/panda/src/gobj/texturePool.cxx @@ -197,6 +197,62 @@ ns_has_texture(const Filename &orig_filename) { return false; } +/** + * The nonstatic implementation of get_texture(). + */ +Texture *TexturePool:: +ns_get_texture(const Filename &orig_filename, int primary_file_num_channels, + bool read_mipmaps) { + LookupKey key; + key._primary_file_num_channels = primary_file_num_channels; + { + MutexHolder holder(_lock); + resolve_filename(key._fullpath, orig_filename, read_mipmaps, LoaderOptions()); + + Textures::const_iterator ti; + ti = _textures.find(key); + if (ti != _textures.end()) { + // This texture was previously loaded. + Texture *tex = (*ti).second; + nassertr(!tex->get_fullpath().empty(), tex); + return tex; + } + } + + return nullptr; +} + +/** + * The nonstatic implementation of get_texture(). + */ +Texture *TexturePool:: +ns_get_texture(const Filename &orig_filename, + const Filename &orig_alpha_filename, + int primary_file_num_channels, + int alpha_file_channel, + bool read_mipmaps) { + LookupKey key; + key._primary_file_num_channels = primary_file_num_channels; + key._alpha_file_channel = alpha_file_channel; + { + MutexHolder holder(_lock); + LoaderOptions options; + resolve_filename(key._fullpath, orig_filename, read_mipmaps, options); + resolve_filename(key._alpha_fullpath, orig_alpha_filename, read_mipmaps, options); + + Textures::const_iterator ti; + ti = _textures.find(key); + if (ti != _textures.end()) { + // This texture was previously loaded. + Texture *tex = (*ti).second; + nassertr(!tex->get_fullpath().empty(), tex); + return tex; + } + } + + return nullptr; +} + /** * The nonstatic implementation of load_texture(). */ diff --git a/panda/src/gobj/texturePool.h b/panda/src/gobj/texturePool.h index de6812e4d5..388dc415bf 100644 --- a/panda/src/gobj/texturePool.h +++ b/panda/src/gobj/texturePool.h @@ -38,6 +38,14 @@ class EXPCL_PANDA_GOBJ TexturePool { PUBLISHED: INLINE static bool has_texture(const Filename &filename); INLINE static bool verify_texture(const Filename &filename); + INLINE static Texture *get_texture(const Filename &filename, + int primary_file_num_channels = 0, + bool read_mipmaps = false); + INLINE static Texture *get_texture(const Filename &filename, + const Filename &alpha_filename, + int primary_file_num_channels = 0, + int alpha_file_channel = 0, + bool read_mipmaps = false); BLOCKING INLINE static Texture *load_texture(const Filename &filename, int primary_file_num_channels = 0, bool read_mipmaps = false, @@ -96,6 +104,14 @@ private: TexturePool(); bool ns_has_texture(const Filename &orig_filename); + Texture *ns_get_texture(const Filename &filename, + int primary_file_num_channels = 0, + bool read_mipmaps = false); + Texture *ns_get_texture(const Filename &filename, + const Filename &alpha_filename, + int primary_file_num_channels = 0, + int alpha_file_channel = 0, + bool read_mipmaps = false); Texture *ns_load_texture(const Filename &orig_filename, int primary_file_num_channels, bool read_mipmaps,