gobj: Add TexturePool::get_texture() for querying tex from pool

This commit is contained in:
rdb 2021-11-28 14:00:59 +01:00
parent 5cad0eb973
commit 5eaa67fbc9
3 changed files with 95 additions and 0 deletions

View File

@ -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

View File

@ -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().
*/

View File

@ -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,