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