renderEffects.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // Filename: renderEffects.h
  2. // Created by: drose (14Mar02)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, 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://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef RENDEREFFECTS_H
  19. #define RENDEREFFECTS_H
  20. #include "pandabase.h"
  21. #include "renderEffect.h"
  22. #include "typedWritableReferenceCount.h"
  23. #include "pointerTo.h"
  24. #include "indirectLess.h"
  25. #include "ordered_vector.h"
  26. class BillboardEffect;
  27. class CompassEffect;
  28. class FactoryParams;
  29. ////////////////////////////////////////////////////////////////////
  30. // Class : RenderEffects
  31. // Description : This represents a unique collection of RenderEffect
  32. // objects that correspond to a particular renderable
  33. // state.
  34. //
  35. // You should not attempt to create or modify a
  36. // RenderEffects object directly. Instead, call one of
  37. // the make() functions to create one for you. And
  38. // instead of modifying a RenderEffects object, create a
  39. // new one.
  40. ////////////////////////////////////////////////////////////////////
  41. class EXPCL_PANDA RenderEffects : public TypedWritableReferenceCount {
  42. protected:
  43. RenderEffects();
  44. private:
  45. RenderEffects(const RenderEffects &copy);
  46. void operator = (const RenderEffects &copy);
  47. public:
  48. virtual ~RenderEffects();
  49. bool operator < (const RenderEffects &other) const;
  50. bool safe_to_transform() const;
  51. bool safe_to_combine() const;
  52. CPT(RenderEffects) xform(const LMatrix4f &mat) const;
  53. PUBLISHED:
  54. INLINE bool is_empty() const;
  55. INLINE int get_num_effects() const;
  56. INLINE const RenderEffect *get_effect(int n) const;
  57. int find_effect(TypeHandle type) const;
  58. static CPT(RenderEffects) make_empty();
  59. static CPT(RenderEffects) make(const RenderEffect *effect);
  60. static CPT(RenderEffects) make(const RenderEffect *effect1,
  61. const RenderEffect *effect2);
  62. static CPT(RenderEffects) make(const RenderEffect *effect1,
  63. const RenderEffect *effect2,
  64. const RenderEffect *effect3);
  65. static CPT(RenderEffects) make(const RenderEffect *effect1,
  66. const RenderEffect *effect2,
  67. const RenderEffect *effect3,
  68. const RenderEffect *effect4);
  69. CPT(RenderEffects) add_effect(const RenderEffect *effect) const;
  70. CPT(RenderEffects) remove_effect(TypeHandle type) const;
  71. const RenderEffect *get_effect(TypeHandle type) const;
  72. void output(ostream &out) const;
  73. void write(ostream &out, int indent_level) const;
  74. public:
  75. INLINE const BillboardEffect *get_billboard() const;
  76. INLINE bool has_decal() const;
  77. INLINE const CompassEffect *get_compass() const;
  78. INLINE bool has_show_bounds() const;
  79. private:
  80. static CPT(RenderEffects) return_new(RenderEffects *state);
  81. void determine_billboard();
  82. void determine_decal();
  83. void determine_compass();
  84. void determine_show_bounds();
  85. private:
  86. typedef pset<const RenderEffects *, IndirectLess<RenderEffects> > States;
  87. static States _states;
  88. static CPT(RenderEffects) _empty_state;
  89. // This iterator records the entry corresponding to this RenderEffects
  90. // object in the above global set. We keep the iterator around so
  91. // we can remove it when the RenderEffects destructs.
  92. States::iterator _saved_entry;
  93. private:
  94. // This is the actual data within the RenderEffects: a set of
  95. // RenderEffects.
  96. class Effect {
  97. public:
  98. INLINE Effect(const RenderEffect *effect);
  99. INLINE Effect();
  100. INLINE Effect(TypeHandle type);
  101. INLINE Effect(const Effect &copy);
  102. INLINE void operator = (const Effect &copy);
  103. INLINE bool operator < (const Effect &other) const;
  104. INLINE int compare_to(const Effect &other) const;
  105. TypeHandle _type;
  106. CPT(RenderEffect) _effect;
  107. };
  108. typedef ov_set<Effect> Effects;
  109. Effects _effects;
  110. // We cache the pointer to some critical effects stored in the
  111. // state, if they exist.
  112. const BillboardEffect *_billboard;
  113. const CompassEffect *_compass;
  114. enum Flags {
  115. F_checked_billboard = 0x0001,
  116. F_checked_decal = 0x0002,
  117. F_has_decal = 0x0004,
  118. F_checked_show_bounds = 0x0008,
  119. F_has_show_bounds = 0x0010,
  120. F_checked_compass = 0x0020,
  121. };
  122. short _flags;
  123. public:
  124. static void register_with_read_factory();
  125. virtual void write_datagram(BamWriter *manager, Datagram &dg);
  126. virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
  127. static TypedWritable *change_this(TypedWritable *old_ptr, BamReader *manager);
  128. virtual void finalize();
  129. protected:
  130. static TypedWritable *make_from_bam(const FactoryParams &params);
  131. void fillin(DatagramIterator &scan, BamReader *manager);
  132. public:
  133. static TypeHandle get_class_type() {
  134. return _type_handle;
  135. }
  136. static void init_type() {
  137. TypedWritableReferenceCount::init_type();
  138. register_type(_type_handle, "RenderEffects",
  139. TypedWritableReferenceCount::get_class_type());
  140. }
  141. virtual TypeHandle get_type() const {
  142. return get_class_type();
  143. }
  144. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  145. private:
  146. static TypeHandle _type_handle;
  147. };
  148. INLINE ostream &operator << (ostream &out, const RenderEffects &state) {
  149. state.output(out);
  150. return out;
  151. }
  152. #include "renderEffects.I"
  153. #endif