eggTextureCollection.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Filename: eggTextureCollection.h
  2. // Created by: drose (15Feb00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef EGGTEXTURECOLLECTION_H
  19. #define EGGTEXTURECOLLECTION_H
  20. #include <pandabase.h>
  21. #include "eggTexture.h"
  22. #include "eggGroupNode.h"
  23. #include "vector_PT_EggTexture.h"
  24. #include <string>
  25. #include "pmap.h"
  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. // This is a bit of private interface stuff that must be here as a
  36. // forward reference. This allows us to define the
  37. // EggTextureCollection as an STL container.
  38. private:
  39. typedef pmap<PT_EggTexture, int> Textures;
  40. typedef vector_PT_EggTexture OrderedTextures;
  41. public:
  42. typedef OrderedTextures::const_iterator iterator;
  43. typedef iterator const_iterator;
  44. typedef OrderedTextures::size_type size_type;
  45. typedef pmap<PT_EggTexture, PT_EggTexture > TextureReplacement;
  46. // Here begins the actual public interface to EggTextureCollection.
  47. public:
  48. EggTextureCollection();
  49. EggTextureCollection(const EggTextureCollection &copy);
  50. EggTextureCollection &operator = (const EggTextureCollection &copy);
  51. ~EggTextureCollection();
  52. void clear();
  53. int extract_textures(EggGroupNode *node);
  54. EggGroupNode::iterator insert_textures(EggGroupNode *node);
  55. EggGroupNode::iterator insert_textures(EggGroupNode *node, EggGroupNode::iterator position);
  56. int find_used_textures(EggNode *node);
  57. void remove_unused_textures(EggNode *node);
  58. int collapse_equivalent_textures(int eq, EggGroupNode *node);
  59. int collapse_equivalent_textures(int eq, TextureReplacement &removed);
  60. static void replace_textures(EggGroupNode *node,
  61. const TextureReplacement &replace);
  62. void uniquify_trefs();
  63. void sort_by_tref();
  64. // Can be used to traverse all the textures in the collection, in
  65. // order as last sorted.
  66. INLINE iterator begin() const;
  67. INLINE iterator end() const;
  68. INLINE bool empty() const;
  69. INLINE size_type size() const;
  70. bool add_texture(EggTexture *texture);
  71. bool remove_texture(EggTexture *texture);
  72. // create_unique_texture() creates a new texture if there is not
  73. // already one equivalent (according to eq, see
  74. // EggTexture::is_equivalent_to()) to the indicated texture, or
  75. // returns the existing one if there is.
  76. EggTexture *create_unique_texture(const EggTexture &copy, int eq);
  77. // Find a texture with a particular TRef name.
  78. EggTexture *find_tref(const string &tref_name) const;
  79. // Find a texture with a particular filename.
  80. EggTexture *find_filename(const Filename &filename) const;
  81. private:
  82. Textures _textures;
  83. OrderedTextures _ordered_textures;
  84. };
  85. #include "eggTextureCollection.I"
  86. #endif