2
0
Эх сурвалжийг харах

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

rdb 4 жил өмнө
parent
commit
5eaa67fbc9

+ 23 - 0
panda/src/gobj/texturePool.I

@@ -33,6 +33,29 @@ verify_texture(const Filename &filename) {
   return load_texture(filename) != nullptr;
   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
  * 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
  * loaded, and returns the new texture.  If a texture with the same filename

+ 56 - 0
panda/src/gobj/texturePool.cxx

@@ -197,6 +197,62 @@ ns_has_texture(const Filename &orig_filename) {
   return false;
   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().
  * The nonstatic implementation of load_texture().
  */
  */

+ 16 - 0
panda/src/gobj/texturePool.h

@@ -38,6 +38,14 @@ class EXPCL_PANDA_GOBJ TexturePool {
 PUBLISHED:
 PUBLISHED:
   INLINE static bool has_texture(const Filename &filename);
   INLINE static bool has_texture(const Filename &filename);
   INLINE static bool verify_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,
   BLOCKING INLINE static Texture *load_texture(const Filename &filename,
                                                int primary_file_num_channels = 0,
                                                int primary_file_num_channels = 0,
                                                bool read_mipmaps = false,
                                                bool read_mipmaps = false,
@@ -96,6 +104,14 @@ private:
   TexturePool();
   TexturePool();
 
 
   bool ns_has_texture(const Filename &orig_filename);
   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,
   Texture *ns_load_texture(const Filename &orig_filename,
                            int primary_file_num_channels,
                            int primary_file_num_channels,
                            bool read_mipmaps,
                            bool read_mipmaps,