mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-27 07:03:36 -04:00
gobj: Add TexturePool::get_texture() for querying tex from pool
This commit is contained in:
parent
5cad0eb973
commit
5eaa67fbc9
@ -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
|
||||
|
@ -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().
|
||||
*/
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user