Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pgraph/renderEffects.h

Go to the documentation of this file.
00001 // Filename: renderEffects.h
00002 // Created by:  drose (14Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef RENDEREFFECTS_H
00020 #define RENDEREFFECTS_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "renderEffect.h"
00025 #include "typedWritableReferenceCount.h"
00026 #include "pointerTo.h"
00027 #include "indirectLess.h"
00028 #include "ordered_vector.h"
00029 
00030 class BillboardEffect;
00031 class CompassEffect;
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 RenderEffects : public TypedWritableReferenceCount {
00047 protected:
00048   RenderEffects();
00049 
00050 private:
00051   RenderEffects(const RenderEffects &copy);
00052   void operator = (const RenderEffects &copy);
00053 
00054 public:
00055   virtual ~RenderEffects();
00056 
00057   bool operator < (const RenderEffects &other) const;
00058 
00059   bool safe_to_transform() const;
00060   bool safe_to_combine() const;
00061   CPT(RenderEffects) xform(const LMatrix4f &mat) const;
00062 
00063 PUBLISHED:
00064   INLINE bool is_empty() const;
00065   INLINE int get_num_effects() const;
00066   INLINE const RenderEffect *get_effect(int n) const;
00067 
00068   int find_effect(TypeHandle type) const;
00069 
00070   static CPT(RenderEffects) make_empty();
00071   static CPT(RenderEffects) make(const RenderEffect *effect);
00072   static CPT(RenderEffects) make(const RenderEffect *effect1,
00073                                  const RenderEffect *effect2);
00074   static CPT(RenderEffects) make(const RenderEffect *effect1,
00075                                  const RenderEffect *effect2,
00076                                  const RenderEffect *effect3);
00077   static CPT(RenderEffects) make(const RenderEffect *effect1,
00078                                  const RenderEffect *effect2,
00079                                  const RenderEffect *effect3,
00080                                  const RenderEffect *effect4);
00081 
00082   CPT(RenderEffects) add_effect(const RenderEffect *effect) const;
00083   CPT(RenderEffects) remove_effect(TypeHandle type) const;
00084 
00085   const RenderEffect *get_effect(TypeHandle type) const;
00086 
00087   void output(ostream &out) const;
00088   void write(ostream &out, int indent_level) const;
00089 
00090 public:
00091   INLINE const BillboardEffect *get_billboard() const;
00092   INLINE bool has_decal() const;
00093   INLINE const CompassEffect *get_compass() const;
00094   INLINE bool has_show_bounds() const;
00095 
00096 private:
00097   static CPT(RenderEffects) return_new(RenderEffects *state);
00098   void determine_billboard();
00099   void determine_decal();
00100   void determine_compass();
00101   void determine_show_bounds();
00102 
00103 private:
00104   typedef pset<const RenderEffects *, IndirectLess<RenderEffects> > States;
00105   static States _states;
00106   static CPT(RenderEffects) _empty_state;
00107 
00108   // This iterator records the entry corresponding to this RenderEffects
00109   // object in the above global set.  We keep the iterator around so
00110   // we can remove it when the RenderEffects destructs.
00111   States::iterator _saved_entry;
00112 
00113 private:
00114   // This is the actual data within the RenderEffects: a set of
00115   // RenderEffects.
00116   class Effect {
00117   public:
00118     INLINE Effect(const RenderEffect *effect);
00119     INLINE Effect();
00120     INLINE Effect(TypeHandle type);
00121     INLINE Effect(const Effect &copy);
00122     INLINE void operator = (const Effect &copy);
00123     INLINE bool operator < (const Effect &other) const;
00124     INLINE int compare_to(const Effect &other) const;
00125 
00126     TypeHandle _type;
00127     CPT(RenderEffect) _effect;
00128   };
00129   typedef ov_set<Effect> Effects;
00130   Effects _effects;
00131 
00132   // We cache the pointer to some critical effects stored in the
00133   // state, if they exist.
00134   const BillboardEffect *_billboard;
00135   const CompassEffect *_compass;
00136 
00137   enum Flags {
00138     F_checked_billboard    = 0x0001,
00139     F_checked_decal        = 0x0002,
00140     F_has_decal            = 0x0004,
00141     F_checked_show_bounds  = 0x0008,
00142     F_has_show_bounds      = 0x0010,
00143     F_checked_compass      = 0x0020,
00144   };
00145   short _flags;
00146 
00147 public:
00148   static void register_with_read_factory();
00149   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00150   virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
00151   static TypedWritable *change_this(TypedWritable *old_ptr, BamReader *manager);
00152   virtual void finalize();
00153 
00154 protected:
00155   static TypedWritable *make_from_bam(const FactoryParams &params);
00156   void fillin(DatagramIterator &scan, BamReader *manager);
00157   
00158 public:
00159   static TypeHandle get_class_type() {
00160     return _type_handle;
00161   }
00162   static void init_type() {
00163     TypedWritableReferenceCount::init_type();
00164     register_type(_type_handle, "RenderEffects",
00165                   TypedWritableReferenceCount::get_class_type());
00166   }
00167   virtual TypeHandle get_type() const {
00168     return get_class_type();
00169   }
00170   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00171 
00172 private:
00173   static TypeHandle _type_handle;
00174 };
00175 
00176 INLINE ostream &operator << (ostream &out, const RenderEffects &state) {
00177   state.output(out);
00178   return out;
00179 }
00180 
00181 #include "renderEffects.I"
00182 
00183 #endif
00184 

Generated on Fri May 2 00:42:16 2003 for Panda by doxygen1.3