Panda3D
|
00001 // Filename: renderEffects.h 00002 // Created by: drose (14Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef RENDEREFFECTS_H 00016 #define RENDEREFFECTS_H 00017 00018 #include "pandabase.h" 00019 00020 #include "transformState.h" 00021 #include "renderState.h" 00022 00023 #include "renderEffect.h" 00024 #include "typedWritableReferenceCount.h" 00025 #include "pointerTo.h" 00026 #include "ordered_vector.h" 00027 #include "lightReMutex.h" 00028 #include "lightMutex.h" 00029 00030 class CullTraverser; 00031 class CullTraverserData; 00032 class FactoryParams; 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Class : RenderEffects 00036 // Description : This represents a unique collection of RenderEffect 00037 // objects that correspond to a particular renderable 00038 // state. 00039 // 00040 // You should not attempt to create or modify a 00041 // RenderEffects object directly. Instead, call one of 00042 // the make() functions to create one for you. And 00043 // instead of modifying a RenderEffects object, create a 00044 // new one. 00045 //////////////////////////////////////////////////////////////////// 00046 class EXPCL_PANDA_PGRAPH RenderEffects : public TypedWritableReferenceCount { 00047 protected: 00048 RenderEffects(); 00049 00050 private: 00051 RenderEffects(const RenderEffects ©); 00052 void operator = (const RenderEffects ©); 00053 00054 public: 00055 virtual ~RenderEffects(); 00056 00057 bool safe_to_transform() const; 00058 virtual CPT(TransformState) prepare_flatten_transform(const TransformState *net_transform) const; 00059 bool safe_to_combine() const; 00060 CPT(RenderEffects) xform(const LMatrix4 &mat) const; 00061 00062 PUBLISHED: 00063 bool operator < (const RenderEffects &other) const; 00064 00065 INLINE bool is_empty() const; 00066 INLINE int get_num_effects() const; 00067 INLINE const RenderEffect *get_effect(int n) const; 00068 00069 int find_effect(TypeHandle type) const; 00070 00071 static CPT(RenderEffects) make_empty(); 00072 static CPT(RenderEffects) make(const RenderEffect *effect); 00073 static CPT(RenderEffects) make(const RenderEffect *effect1, 00074 const RenderEffect *effect2); 00075 static CPT(RenderEffects) make(const RenderEffect *effect1, 00076 const RenderEffect *effect2, 00077 const RenderEffect *effect3); 00078 static CPT(RenderEffects) make(const RenderEffect *effect1, 00079 const RenderEffect *effect2, 00080 const RenderEffect *effect3, 00081 const RenderEffect *effect4); 00082 00083 CPT(RenderEffects) add_effect(const RenderEffect *effect) const; 00084 CPT(RenderEffects) remove_effect(TypeHandle type) const; 00085 00086 const RenderEffect *get_effect(TypeHandle type) const; 00087 00088 virtual bool unref() const; 00089 00090 void output(ostream &out) const; 00091 void write(ostream &out, int indent_level) const; 00092 00093 static int get_num_states(); 00094 static void list_states(ostream &out); 00095 static bool validate_states(); 00096 00097 public: 00098 INLINE bool has_decal() const; 00099 INLINE bool has_show_bounds() const; 00100 INLINE bool has_show_tight_bounds() const; 00101 00102 INLINE bool has_cull_callback() const; 00103 void cull_callback(CullTraverser *trav, CullTraverserData &data, 00104 CPT(TransformState) &node_transform, 00105 CPT(RenderState) &node_state) const; 00106 00107 INLINE bool has_adjust_transform() const; 00108 void adjust_transform(CPT(TransformState) &net_transform, 00109 CPT(TransformState) &node_transform, 00110 PandaNode *node) const; 00111 00112 static void init_states(); 00113 00114 private: 00115 static CPT(RenderEffects) return_new(RenderEffects *state); 00116 void release_new(); 00117 00118 void determine_decal(); 00119 void determine_show_bounds(); 00120 void determine_cull_callback(); 00121 void determine_adjust_transform(); 00122 00123 private: 00124 // This mutex protects _states. It also protects any modification 00125 // to the cache, which is encoded in _composition_cache and 00126 // _invert_composition_cache. 00127 static LightReMutex *_states_lock; 00128 typedef pset<const RenderEffects *, indirect_less<const RenderEffects *> > States; 00129 static States *_states; 00130 static CPT(RenderEffects) _empty_state; 00131 00132 // This iterator records the entry corresponding to this RenderEffects 00133 // object in the above global set. We keep the iterator around so 00134 // we can remove it when the RenderEffects destructs. 00135 States::iterator _saved_entry; 00136 00137 private: 00138 // This is the actual data within the RenderEffects: a set of 00139 // RenderEffects. 00140 class Effect { 00141 public: 00142 INLINE Effect(const RenderEffect *effect); 00143 INLINE Effect(); 00144 INLINE Effect(TypeHandle type); 00145 INLINE Effect(const Effect ©); 00146 INLINE void operator = (const Effect ©); 00147 INLINE bool operator < (const Effect &other) const; 00148 INLINE int compare_to(const Effect &other) const; 00149 00150 TypeHandle _type; 00151 CPT(RenderEffect) _effect; 00152 }; 00153 typedef ov_set<Effect> Effects; 00154 Effects _effects; 00155 00156 enum Flags { 00157 F_checked_decal = 0x0001, 00158 F_has_decal = 0x0002, 00159 F_checked_show_bounds = 0x0004, 00160 F_has_show_bounds = 0x0008, 00161 F_has_show_tight_bounds = 0x0010, 00162 F_checked_cull_callback = 0x0020, 00163 F_has_cull_callback = 0x0040, 00164 F_checked_adjust_transform = 0x0080, 00165 F_has_adjust_transform = 0x0100, 00166 }; 00167 int _flags; 00168 00169 // This mutex protects _flags, and all of the above computed values. 00170 LightMutex _lock; 00171 00172 00173 public: 00174 static void register_with_read_factory(); 00175 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00176 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00177 virtual bool require_fully_complete() const; 00178 static TypedWritable *change_this(TypedWritable *old_ptr, BamReader *manager); 00179 virtual void finalize(BamReader *manager); 00180 00181 protected: 00182 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00183 void fillin(DatagramIterator &scan, BamReader *manager); 00184 00185 public: 00186 static TypeHandle get_class_type() { 00187 return _type_handle; 00188 } 00189 static void init_type() { 00190 TypedWritableReferenceCount::init_type(); 00191 register_type(_type_handle, "RenderEffects", 00192 TypedWritableReferenceCount::get_class_type()); 00193 } 00194 virtual TypeHandle get_type() const { 00195 return get_class_type(); 00196 } 00197 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00198 00199 private: 00200 static TypeHandle _type_handle; 00201 }; 00202 00203 INLINE ostream &operator << (ostream &out, const RenderEffects &state) { 00204 state.output(out); 00205 return out; 00206 } 00207 00208 #include "renderEffects.I" 00209 00210 #endif 00211