From 2d887a630eb36d0c4e50a23c60dae8c1e0a8ca0f Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 9 Feb 2009 20:09:51 +0000 Subject: [PATCH] TexturePool.findTexture(), findAllTextures() --- panda/src/gobj/Sources.pp | 6 ++- panda/src/gobj/gobj_composite2.cxx | 1 + .../src/{pgraph => gobj}/textureCollection.I | 0 .../{pgraph => gobj}/textureCollection.cxx | 0 .../src/{pgraph => gobj}/textureCollection.h | 5 ++- panda/src/gobj/texturePool.I | 25 +++++++++++ panda/src/gobj/texturePool.cxx | 43 +++++++++++++++++++ panda/src/gobj/texturePool.h | 6 +++ panda/src/pgraph/Sources.pp | 3 -- panda/src/pgraph/pgraph_composite4.cxx | 1 - 10 files changed, 83 insertions(+), 7 deletions(-) rename panda/src/{pgraph => gobj}/textureCollection.I (100%) rename panda/src/{pgraph => gobj}/textureCollection.cxx (100%) rename panda/src/{pgraph => gobj}/textureCollection.h (92%) diff --git a/panda/src/gobj/Sources.pp b/panda/src/gobj/Sources.pp index ecec47af81..ae0c0e3808 100644 --- a/panda/src/gobj/Sources.pp +++ b/panda/src/gobj/Sources.pp @@ -55,6 +55,7 @@ simpleLru.h simpleLru.I \ sliderTable.I sliderTable.h \ texture.I texture.h \ + textureCollection.I textureCollection.h \ textureContext.I textureContext.h \ texturePeeker.I texturePeeker.h \ texturePool.I texturePool.h \ @@ -120,7 +121,9 @@ simpleAllocator.cxx \ simpleLru.cxx \ sliderTable.cxx \ - texture.cxx textureContext.cxx \ + texture.cxx \ + textureCollection.cxx \ + textureContext.cxx \ texturePeeker.cxx \ texturePool.cxx \ texturePoolFilter.cxx \ @@ -188,6 +191,7 @@ simpleLru.h simpleLru.I \ sliderTable.I sliderTable.h \ texture.I texture.h \ + textureCollection.I textureCollection.h \ textureContext.I textureContext.h \ texturePeeker.I texturePeeker.h \ texturePool.I texturePool.h \ diff --git a/panda/src/gobj/gobj_composite2.cxx b/panda/src/gobj/gobj_composite2.cxx index 0a95ca1c09..44489c29c4 100644 --- a/panda/src/gobj/gobj_composite2.cxx +++ b/panda/src/gobj/gobj_composite2.cxx @@ -13,6 +13,7 @@ #include "simpleLru.cxx" #include "sliderTable.cxx" #include "texture.cxx" +#include "textureCollection.cxx" #include "textureContext.cxx" #include "texturePeeker.cxx" #include "texturePool.cxx" diff --git a/panda/src/pgraph/textureCollection.I b/panda/src/gobj/textureCollection.I similarity index 100% rename from panda/src/pgraph/textureCollection.I rename to panda/src/gobj/textureCollection.I diff --git a/panda/src/pgraph/textureCollection.cxx b/panda/src/gobj/textureCollection.cxx similarity index 100% rename from panda/src/pgraph/textureCollection.cxx rename to panda/src/gobj/textureCollection.cxx diff --git a/panda/src/pgraph/textureCollection.h b/panda/src/gobj/textureCollection.h similarity index 92% rename from panda/src/pgraph/textureCollection.h rename to panda/src/gobj/textureCollection.h index 7a7edbdbea..39d8166c05 100644 --- a/panda/src/pgraph/textureCollection.h +++ b/panda/src/gobj/textureCollection.h @@ -21,9 +21,10 @@ //////////////////////////////////////////////////////////////////// // Class : TextureCollection -// Description : +// Description : Manages a list of Texture objects, as returned by +// TexturePool::find_all_textures(). //////////////////////////////////////////////////////////////////// -class EXPCL_PANDA_PGRAPH TextureCollection { +class EXPCL_PANDA_GOBJ TextureCollection { PUBLISHED: TextureCollection(); TextureCollection(const TextureCollection ©); diff --git a/panda/src/gobj/texturePool.I b/panda/src/gobj/texturePool.I index c91d658fb1..388559bf0f 100644 --- a/panda/src/gobj/texturePool.I +++ b/panda/src/gobj/texturePool.I @@ -248,6 +248,31 @@ list_contents() { get_global_ptr()->ns_list_contents(cout); } +//////////////////////////////////////////////////////////////////// +// Function: TexturePool::find_texture +// Access: Published, Static +// Description: Returns the first texture found in the pool that +// matches the indicated name (which may contain +// wildcards). Returns the texture if it is found, or +// NULL if it is not. +//////////////////////////////////////////////////////////////////// +INLINE Texture *TexturePool:: +find_texture(const string &name) { + return get_global_ptr()->ns_find_texture(name); +} + +//////////////////////////////////////////////////////////////////// +// Function: TexturePool::find_all_textures +// Access: Published, Static +// Description: Returns the set of all textures found in the pool +// that match the indicated name (which may contain +// wildcards). +//////////////////////////////////////////////////////////////////// +INLINE TextureCollection TexturePool:: +find_all_textures(const string &name) { + return get_global_ptr()->ns_find_all_textures(name); +} + //////////////////////////////////////////////////////////////////// // Function: TexturePool::set_fake_texture_image // Access: Published, Static diff --git a/panda/src/gobj/texturePool.cxx b/panda/src/gobj/texturePool.cxx index 9cdd558c5d..9712cc4e0e 100644 --- a/panda/src/gobj/texturePool.cxx +++ b/panda/src/gobj/texturePool.cxx @@ -854,6 +854,49 @@ ns_list_contents(ostream &out) const { out << "texture pool size - texture pool ram: " << total_size - total_ram_size << "\n"; } +//////////////////////////////////////////////////////////////////// +// Function: TexturePool::ns_find_texture +// Access: Private +// Description: The nonstatic implementation of find_texture(). +//////////////////////////////////////////////////////////////////// +Texture *TexturePool:: +ns_find_texture(const string &name) const { + MutexHolder holder(_lock); + GlobPattern glob(name); + + Textures::const_iterator ti; + for (ti = _textures.begin(); ti != _textures.end(); ++ti) { + Texture *tex = (*ti).second; + if (glob.matches(tex->get_name())) { + return tex; + } + } + + return NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: TexturePool::ns_find_all_textures +// Access: Private +// Description: The nonstatic implementation of find_all_textures(). +//////////////////////////////////////////////////////////////////// +TextureCollection TexturePool:: +ns_find_all_textures(const string &name) const { + MutexHolder holder(_lock); + TextureCollection result; + GlobPattern glob(name); + + Textures::const_iterator ti; + for (ti = _textures.begin(); ti != _textures.end(); ++ti) { + Texture *tex = (*ti).second; + if (glob.matches(tex->get_name())) { + result.add_texture(tex); + } + } + + return result; +} + //////////////////////////////////////////////////////////////////// // Function: TexturePool::resolve_filename // Access: Private diff --git a/panda/src/gobj/texturePool.h b/panda/src/gobj/texturePool.h index c83d3e742e..6f070154af 100644 --- a/panda/src/gobj/texturePool.h +++ b/panda/src/gobj/texturePool.h @@ -22,6 +22,7 @@ #include "loaderOptions.h" #include "pmutex.h" #include "pmap.h" +#include "textureCollection.h" class TexturePoolFilter; class BamCache; @@ -69,6 +70,9 @@ PUBLISHED: INLINE static void list_contents(ostream &out); INLINE static void list_contents(); + INLINE static Texture *find_texture(const string &name); + INLINE static TextureCollection find_all_textures(const string &name = "*"); + INLINE static void set_fake_texture_image(const Filename &filename); INLINE static void clear_fake_texture_image(); INLINE static bool has_fake_texture_image(); @@ -115,6 +119,8 @@ private: void ns_release_all_textures(); int ns_garbage_collect(); void ns_list_contents(ostream &out) const; + Texture *ns_find_texture(const string &name) const; + TextureCollection ns_find_all_textures(const string &name) const; void resolve_filename(Filename &new_filename, const Filename &orig_filename); diff --git a/panda/src/pgraph/Sources.pp b/panda/src/pgraph/Sources.pp index f03859c19d..5606caafa7 100644 --- a/panda/src/pgraph/Sources.pp +++ b/panda/src/pgraph/Sources.pp @@ -108,7 +108,6 @@ texProjectorEffect.I texProjectorEffect.h \ textureAttrib.I textureAttrib.h \ texGenAttrib.I texGenAttrib.h \ - textureCollection.I textureCollection.h \ textureStageCollection.I textureStageCollection.h \ transformState.I transformState.h \ transparencyAttrib.I transparencyAttrib.h \ @@ -211,7 +210,6 @@ texProjectorEffect.cxx \ textureAttrib.cxx \ texGenAttrib.cxx \ - textureCollection.cxx \ textureStageCollection.cxx \ transformState.cxx \ transparencyAttrib.cxx \ @@ -312,7 +310,6 @@ texProjectorEffect.I texProjectorEffect.h \ textureAttrib.I textureAttrib.h \ texGenAttrib.I texGenAttrib.h \ - textureCollection.I textureCollection.h \ textureStageCollection.I textureStageCollection.h \ transformState.I transformState.h \ transparencyAttrib.I transparencyAttrib.h \ diff --git a/panda/src/pgraph/pgraph_composite4.cxx b/panda/src/pgraph/pgraph_composite4.cxx index 532ba1c14c..f0afcecd3f 100644 --- a/panda/src/pgraph/pgraph_composite4.cxx +++ b/panda/src/pgraph/pgraph_composite4.cxx @@ -21,7 +21,6 @@ #include "texProjectorEffect.cxx" #include "textureAttrib.cxx" #include "texGenAttrib.cxx" -#include "textureCollection.cxx" #include "textureStageCollection.cxx" #include "transformState.cxx" #include "transparencyAttrib.cxx"