Panda3D
 All Classes Functions Variables Enumerations
eggTextureCollection.h
1 // Filename: eggTextureCollection.h
2 // Created by: drose (15Feb00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef EGGTEXTURECOLLECTION_H
16 #define EGGTEXTURECOLLECTION_H
17 
18 #include "pandabase.h"
19 
20 #include "eggTexture.h"
21 #include "eggGroupNode.h"
22 #include "vector_PT_EggTexture.h"
23 
24 #include "pmap.h"
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : EggTextureCollection
28 // Description : This is a collection of textures by TRef name. It
29 // can extract the textures from an egg file and sort
30 // them all together; it can also manage the creation of
31 // unique textures and the assignment of unique TRef
32 // names.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDAEGG EggTextureCollection {
35 
36  // This is a bit of private interface stuff that must be here as a
37  // forward reference. This allows us to define the
38  // EggTextureCollection as an STL container.
39 
40 private:
42  typedef vector_PT_EggTexture OrderedTextures;
43 
44 public:
45  typedef OrderedTextures::const_iterator iterator;
46  typedef iterator const_iterator;
47  typedef OrderedTextures::size_type size_type;
48 
50 
51  // Here begins the actual public interface to EggTextureCollection.
52 
53 PUBLISHED:
56  EggTextureCollection &operator = (const EggTextureCollection &copy);
58 
59  void clear();
60 
61  int extract_textures(EggGroupNode *node);
62 
63  bool is_empty() const;
64  int get_num_textures() const;
65  EggTexture *get_texture(int index) const;
66  MAKE_SEQ(get_textures, get_num_textures, get_texture);
67 
68 public:
69  EggGroupNode::iterator insert_textures(EggGroupNode *node);
70  EggGroupNode::iterator insert_textures(EggGroupNode *node, EggGroupNode::iterator position);
71 
72 PUBLISHED:
73  int find_used_textures(EggNode *node);
74  void remove_unused_textures(EggNode *node);
75 
76  int collapse_equivalent_textures(int eq, EggGroupNode *node);
77  int collapse_equivalent_textures(int eq, TextureReplacement &removed);
78  static void replace_textures(EggGroupNode *node,
79  const TextureReplacement &replace);
80 
81  void uniquify_trefs();
82  void sort_by_tref();
83  void sort_by_basename();
84 
85 public:
86  // Can be used to traverse all the textures in the collection, in
87  // order as last sorted.
88  INLINE iterator begin() const;
89  INLINE iterator end() const;
90  INLINE bool empty() const;
91 
92 PUBLISHED:
93  INLINE EggTexture *operator [](size_type n) const;
94  INLINE size_type size() const;
95 
96  bool add_texture(EggTexture *texture);
97  bool remove_texture(EggTexture *texture);
98 
99  // create_unique_texture() creates a new texture if there is not
100  // already one equivalent (according to eq, see
101  // EggTexture::is_equivalent_to()) to the indicated texture, or
102  // returns the existing one if there is.
103  EggTexture *create_unique_texture(const EggTexture &copy, int eq);
104 
105  // Find a texture with a particular TRef name.
106  EggTexture *find_tref(const string &tref_name) const;
107 
108  // Find a texture with a particular filename.
109  EggTexture *find_filename(const Filename &filename) const;
110 
111 private:
112  Textures _textures;
113  OrderedTextures _ordered_textures;
114 };
115 
116 #include "eggTextureCollection.I"
117 
118 #endif
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:33
This is a collection of textures by TRef name.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:38