Panda3D

lightAttrib.h

00001 // Filename: lightAttrib.h
00002 // Created by:  drose (26Mar02)
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 LIGHTATTRIB_H
00016 #define LIGHTATTRIB_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "light.h"
00021 #include "renderAttrib.h"
00022 #include "nodePath.h"
00023 #include "ordered_vector.h"
00024 #include "pmap.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : LightAttrib
00028 // Description : Indicates which set of lights should be considered
00029 //               "on" to illuminate geometry at this level and below.
00030 //               A LightAttrib can either add lights or remove lights
00031 //               from the total set of "on" lights.
00032 ////////////////////////////////////////////////////////////////////
00033 class EXPCL_PANDA_PGRAPH LightAttrib : public RenderAttrib {
00034 protected:
00035   INLINE LightAttrib();
00036   INLINE LightAttrib(const LightAttrib &copy);
00037 
00038 PUBLISHED:
00039 
00040   // This is the old, deprecated interface to LightAttrib.  Do not use
00041   // any of these methods for new code; these methods will be removed
00042   // soon.
00043   enum Operation {
00044     O_set,
00045     O_add,
00046     O_remove
00047   };
00048   static CPT(RenderAttrib) make(Operation op, 
00049                                 Light *light);
00050   static CPT(RenderAttrib) make(Operation op, 
00051                                 Light *light1, Light *light2);
00052   static CPT(RenderAttrib) make(Operation op, 
00053                                 Light *light1, Light *light2,
00054                                 Light *light3);
00055   static CPT(RenderAttrib) make(Operation op, 
00056                                 Light *light1, Light *light2,
00057                                 Light *light3, Light *light4);
00058   static CPT(RenderAttrib) make_default();
00059 
00060   Operation get_operation() const;
00061 
00062   int get_num_lights() const;
00063   Light *get_light(int n) const;
00064   bool has_light(Light *light) const;
00065 
00066   CPT(RenderAttrib) add_light(Light *light) const;
00067   CPT(RenderAttrib) remove_light(Light *light) const;
00068 
00069 
00070   // The following is the new, more general interface to the
00071   // LightAttrib.
00072   static CPT(RenderAttrib) make();
00073   static CPT(RenderAttrib) make_all_off();
00074 
00075   INLINE int get_num_on_lights() const;
00076   INLINE NodePath get_on_light(int n) const;
00077   MAKE_SEQ(get_on_lights, get_num_on_lights, get_on_light);
00078   INLINE bool has_on_light(const NodePath &light) const;
00079 
00080   INLINE int get_num_off_lights() const;
00081   INLINE NodePath get_off_light(int n) const;
00082   MAKE_SEQ(get_off_lights, get_num_off_lights, get_off_light);
00083   INLINE bool has_off_light(const NodePath &light) const;
00084   INLINE bool has_all_off() const;
00085 
00086   INLINE bool is_identity() const;
00087 
00088   CPT(RenderAttrib) add_on_light(const NodePath &light) const;
00089   CPT(RenderAttrib) remove_on_light(const NodePath &light) const;
00090   CPT(RenderAttrib) add_off_light(const NodePath &light) const;
00091   CPT(RenderAttrib) remove_off_light(const NodePath &light) const;
00092 
00093   CPT(LightAttrib) filter_to_max(int max_lights) const;
00094   NodePath get_most_important_light() const;
00095 
00096 public:
00097   virtual void output(ostream &out) const;
00098   virtual void write(ostream &out, int indent_level) const;
00099 
00100 protected:
00101   virtual int compare_to_impl(const RenderAttrib *other) const;
00102   virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
00103   virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
00104 
00105 private:
00106   INLINE void check_filtered() const;
00107   void sort_on_lights();
00108 
00109 private:
00110   typedef ov_set<NodePath> Lights;
00111   Lights _on_lights, _off_lights;
00112   bool _off_all_lights;
00113 
00114   typedef pmap< int, CPT(LightAttrib) > Filtered;
00115   Filtered _filtered;
00116 
00117   UpdateSeq _sort_seq;
00118 
00119   static CPT(RenderAttrib) _empty_attrib;
00120   static CPT(RenderAttrib) _all_off_attrib;
00121 
00122 PUBLISHED:
00123   static int get_class_slot() {
00124     return _attrib_slot;
00125   }
00126   virtual int get_slot() const {
00127     return get_class_slot();
00128   }
00129 
00130 public:
00131   // This data is only needed when reading from a bam file.
00132   typedef pvector<PT(PandaNode) > NodeList;
00133   class BamAuxData : public BamReader::AuxData {
00134   public:
00135     // We hold a pointer to each of the PandaNodes on the on_list and
00136     // off_list.  We will later convert these to NodePaths in
00137     // finalize().
00138     int _num_off_lights;
00139     int _num_on_lights;
00140     NodeList _off_list;
00141     NodeList _on_list;
00142   };
00143 
00144 public:
00145   static void register_with_read_factory();
00146   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00147   virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
00148 
00149   virtual void finalize(BamReader *manager);
00150 
00151 protected:
00152   static TypedWritable *make_from_bam(const FactoryParams &params);
00153   void fillin(DatagramIterator &scan, BamReader *manager);
00154   
00155 public:
00156   static TypeHandle get_class_type() {
00157     return _type_handle;
00158   }
00159   static void init_type() {
00160     RenderAttrib::init_type();
00161     register_type(_type_handle, "LightAttrib",
00162                   RenderAttrib::get_class_type());
00163     _attrib_slot = register_slot(_type_handle, 20, make_default);
00164   }
00165   virtual TypeHandle get_type() const {
00166     return get_class_type();
00167   }
00168   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00169 
00170 private:
00171   static TypeHandle _type_handle;
00172   static int _attrib_slot;
00173 };
00174 
00175 #include "lightAttrib.I"
00176 
00177 #endif
00178 
 All Classes Functions Variables Enumerations