renderEffects.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 "transformState.h"
  22. #include "renderState.h"
  23. #include "renderEffect.h"
  24. #include "typedWritableReferenceCount.h"
  25. #include "pointerTo.h"
  26. #include "ordered_vector.h"
  27. class CullTraverser;
  28. class CullTraverserData;
  29. class FactoryParams;
  30. ////////////////////////////////////////////////////////////////////
  31. // Class : RenderEffects
  32. // Description : This represents a unique collection of RenderEffect
  33. // objects that correspond to a particular renderable
  34. // state.
  35. //
  36. // You should not attempt to create or modify a
  37. // RenderEffects object directly. Instead, call one of
  38. // the make() functions to create one for you. And
  39. // instead of modifying a RenderEffects object, create a
  40. // new one.
  41. ////////////////////////////////////////////////////////////////////
  42. class EXPCL_PANDA RenderEffects : public TypedWritableReferenceCount {
  43. protected:
  44. RenderEffects();
  45. private:
  46. RenderEffects(const RenderEffects &copy);
  47. void operator = (const RenderEffects &copy);
  48. public:
  49. virtual ~RenderEffects();
  50. bool safe_to_transform() const;
  51. bool safe_to_combine() const;
  52. CPT(RenderEffects) xform(const LMatrix4f &mat) const;
  53. PUBLISHED:
  54. bool operator < (const RenderEffects &other) const;
  55. INLINE bool is_empty() const;
  56. INLINE int get_num_effects() const;
  57. INLINE const RenderEffect *get_effect(int n) const;
  58. int find_effect(TypeHandle type) const;
  59. static CPT(RenderEffects) make_empty();
  60. static CPT(RenderEffects) make(const RenderEffect *effect);
  61. static CPT(RenderEffects) make(const RenderEffect *effect1,
  62. const RenderEffect *effect2);
  63. static CPT(RenderEffects) make(const RenderEffect *effect1,
  64. const RenderEffect *effect2,
  65. const RenderEffect *effect3);
  66. static CPT(RenderEffects) make(const RenderEffect *effect1,
  67. const RenderEffect *effect2,
  68. const RenderEffect *effect3,
  69. const RenderEffect *effect4);
  70. CPT(RenderEffects) add_effect(const RenderEffect *effect) const;
  71. CPT(RenderEffects) remove_effect(TypeHandle type) const;
  72. const RenderEffect *get_effect(TypeHandle type) const;
  73. void output(ostream &out) const;
  74. void write(ostream &out, int indent_level) const;
  75. static int get_num_states();
  76. static void list_states(ostream &out);
  77. static bool validate_states();
  78. public:
  79. INLINE bool has_decal() const;
  80. INLINE bool has_show_bounds() const;
  81. INLINE bool has_cull_callback() const;
  82. void cull_callback(CullTraverser *trav, CullTraverserData &data,
  83. CPT(TransformState) &node_transform,
  84. CPT(RenderState) &node_state) const;
  85. private:
  86. static CPT(RenderEffects) return_new(RenderEffects *state);
  87. void determine_decal();
  88. void determine_show_bounds();
  89. void determine_cull_callback();
  90. private:
  91. typedef pset<const RenderEffects *, indirect_less<const RenderEffects *> > States;
  92. static States *_states;
  93. static CPT(RenderEffects) _empty_state;
  94. // This iterator records the entry corresponding to this RenderEffects
  95. // object in the above global set. We keep the iterator around so
  96. // we can remove it when the RenderEffects destructs.
  97. States::iterator _saved_entry;
  98. private:
  99. // This is the actual data within the RenderEffects: a set of
  100. // RenderEffects.
  101. class Effect {
  102. public:
  103. INLINE Effect(const RenderEffect *effect);
  104. INLINE Effect();
  105. INLINE Effect(TypeHandle type);
  106. INLINE Effect(const Effect &copy);
  107. INLINE void operator = (const Effect &copy);
  108. INLINE bool operator < (const Effect &other) const;
  109. INLINE int compare_to(const Effect &other) const;
  110. TypeHandle _type;
  111. CPT(RenderEffect) _effect;
  112. };
  113. typedef ov_set<Effect> Effects;
  114. Effects _effects;
  115. enum Flags {
  116. F_checked_decal = 0x0001,
  117. F_has_decal = 0x0002,
  118. F_checked_show_bounds = 0x0004,
  119. F_has_show_bounds = 0x0008,
  120. F_checked_cull_callback = 0x0010,
  121. F_has_cull_callback = 0x0020,
  122. };
  123. int _flags;
  124. public:
  125. static void register_with_read_factory();
  126. virtual void write_datagram(BamWriter *manager, Datagram &dg);
  127. virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
  128. static TypedWritable *change_this(TypedWritable *old_ptr, BamReader *manager);
  129. virtual void finalize();
  130. protected:
  131. static TypedWritable *make_from_bam(const FactoryParams &params);
  132. void fillin(DatagramIterator &scan, BamReader *manager);
  133. public:
  134. static TypeHandle get_class_type() {
  135. return _type_handle;
  136. }
  137. static void init_type() {
  138. TypedWritableReferenceCount::init_type();
  139. register_type(_type_handle, "RenderEffects",
  140. TypedWritableReferenceCount::get_class_type());
  141. }
  142. virtual TypeHandle get_type() const {
  143. return get_class_type();
  144. }
  145. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  146. private:
  147. static TypeHandle _type_handle;
  148. };
  149. INLINE ostream &operator << (ostream &out, const RenderEffects &state) {
  150. state.output(out);
  151. return out;
  152. }
  153. #include "renderEffects.I"
  154. #endif