materialPool.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Filename: materialPool.h
  2. // Created by: drose (30Apr01)
  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 MATERIALPOOL_H
  19. #define MATERIALPOOL_H
  20. #include <pandabase.h>
  21. #include "material.h"
  22. #include <indirectCompareTo.h>
  23. #include <pointerTo.h>
  24. #include "pset.h"
  25. ////////////////////////////////////////////////////////////////////
  26. // Class : MaterialPool
  27. // Description : The MaterialPool (there is only one in the universe)
  28. // serves to unify different pointers to the same
  29. // Material, so we do not (a) waste memory with many
  30. // different Material objects that are all equivalent,
  31. // and (b) waste time switching the graphics engine
  32. // between different Material states that are really the
  33. // same thing.
  34. //
  35. // The idea is to create a temporary Material
  36. // representing the lighting state you want to apply,
  37. // then call get_material(), passing in your temporary
  38. // Material. The return value will be a constant
  39. // Material object that should be modified (because it
  40. // is now shared among many different geometries), that
  41. // is the same as the temporary Material pointer you
  42. // supplied but may be a different pointer.
  43. ////////////////////////////////////////////////////////////////////
  44. class EXPCL_PANDA MaterialPool {
  45. PUBLISHED:
  46. INLINE static const Material *get_material(const CPT(Material) &temp);
  47. INLINE static int garbage_collect();
  48. INLINE static void list_contents(ostream &out);
  49. private:
  50. INLINE MaterialPool();
  51. const Material *ns_get_material(const CPT(Material) &temp);
  52. int ns_garbage_collect();
  53. void ns_list_contents(ostream &out);
  54. static MaterialPool *get_ptr();
  55. static MaterialPool *_global_ptr;
  56. typedef pset< CPT(Material), IndirectCompareTo<Material> > Materials;
  57. Materials _materials;
  58. };
  59. #include "materialPool.I"
  60. #endif