Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/egg/eggTextureCollection.h

Go to the documentation of this file.
00001 // Filename: eggTextureCollection.h
00002 // Created by:  drose (15Feb00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef EGGTEXTURECOLLECTION_H
00020 #define EGGTEXTURECOLLECTION_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include "eggTexture.h"
00025 #include "eggGroupNode.h"
00026 #include "vector_PT_EggTexture.h"
00027 
00028 #include <string>
00029 #include "pmap.h"
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : EggTextureCollection
00033 // Description : This is a collection of textures by TRef name.  It
00034 //               can extract the textures from an egg file and sort
00035 //               them all together; it can also manage the creation of
00036 //               unique textures and the assignment of unique TRef
00037 //               names.
00038 ////////////////////////////////////////////////////////////////////
00039 class EXPCL_PANDAEGG EggTextureCollection {
00040 
00041   // This is a bit of private interface stuff that must be here as a
00042   // forward reference.  This allows us to define the
00043   // EggTextureCollection as an STL container.
00044 
00045 private:
00046   typedef pmap<PT_EggTexture, int> Textures;
00047   typedef vector_PT_EggTexture OrderedTextures;
00048 
00049 public:
00050   typedef OrderedTextures::const_iterator iterator;
00051   typedef iterator const_iterator;
00052   typedef OrderedTextures::size_type size_type;
00053 
00054   typedef pmap<PT_EggTexture,  PT_EggTexture > TextureReplacement;
00055 
00056   // Here begins the actual public interface to EggTextureCollection.
00057 
00058 public:
00059   EggTextureCollection();
00060   EggTextureCollection(const EggTextureCollection &copy);
00061   EggTextureCollection &operator = (const EggTextureCollection &copy);
00062   ~EggTextureCollection();
00063 
00064   void clear();
00065 
00066   int extract_textures(EggGroupNode *node);
00067   EggGroupNode::iterator insert_textures(EggGroupNode *node);
00068   EggGroupNode::iterator insert_textures(EggGroupNode *node, EggGroupNode::iterator position);
00069 
00070   int find_used_textures(EggNode *node);
00071   void remove_unused_textures(EggNode *node);
00072 
00073   int collapse_equivalent_textures(int eq, EggGroupNode *node);
00074   int collapse_equivalent_textures(int eq, TextureReplacement &removed);
00075   static void replace_textures(EggGroupNode *node,
00076                                const TextureReplacement &replace);
00077 
00078   void uniquify_trefs();
00079   void sort_by_tref();
00080 
00081   // Can be used to traverse all the textures in the collection, in
00082   // order as last sorted.
00083   INLINE iterator begin() const;
00084   INLINE iterator end() const;
00085   INLINE bool empty() const;
00086   INLINE size_type size() const;
00087 
00088   bool add_texture(EggTexture *texture);
00089   bool remove_texture(EggTexture *texture);
00090 
00091   // create_unique_texture() creates a new texture if there is not
00092   // already one equivalent (according to eq, see
00093   // EggTexture::is_equivalent_to()) to the indicated texture, or
00094   // returns the existing one if there is.
00095   EggTexture *create_unique_texture(const EggTexture &copy, int eq);
00096 
00097   // Find a texture with a particular TRef name.
00098   EggTexture *find_tref(const string &tref_name) const;
00099 
00100   // Find a texture with a particular filename.
00101   EggTexture *find_filename(const Filename &filename) const;
00102 
00103 private:
00104   Textures _textures;
00105   OrderedTextures _ordered_textures;
00106 };
00107 
00108 #include "eggTextureCollection.I"
00109 
00110 #endif

Generated on Fri May 2 00:38:01 2003 for Panda by doxygen1.3