00001 // Filename: light.h 00002 // Created by: mike (09Jan97) 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 LIGHT_H 00020 #define LIGHT_H 00021 00022 #include "pandabase.h" 00023 00024 #include "referenceCount.h" 00025 #include "luse.h" 00026 #include "cycleData.h" 00027 #include "cycleDataReader.h" 00028 #include "cycleDataWriter.h" 00029 #include "pipelineCycler.h" 00030 #include "geomNode.h" 00031 00032 class PandaNode; 00033 class GraphicsStateGuardianBase; 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Class : Light 00037 // Description : The abstract interface to all kinds of lights. The 00038 // actual light objects also inherit from PandaNode, and 00039 // can therefore be added to the scene graph at some 00040 // arbitrary point to define the coordinate system of 00041 // effect. 00042 //////////////////////////////////////////////////////////////////// 00043 class EXPCL_PANDA Light : virtual public ReferenceCount { 00044 // We inherit from ReferenceCount instead of TypedReferenceCount so 00045 // that LightNode does not inherit from TypedObject twice. Note 00046 // that we also inherit virtually from ReferenceCount for the same 00047 // reason. 00048 PUBLISHED: 00049 INLINE Light(); 00050 INLINE Light(const Light ©); 00051 virtual ~Light(); 00052 00053 virtual PandaNode *as_node()=0; 00054 00055 INLINE const Colorf &get_color() const; 00056 INLINE void set_color(const Colorf &color); 00057 00058 public: 00059 virtual void output(ostream &out) const=0; 00060 virtual void write(ostream &out, int indent_level) const=0; 00061 virtual void bind(GraphicsStateGuardianBase *gsg, int light_id)=0; 00062 00063 GeomNode *get_viz(); 00064 00065 protected: 00066 virtual void fill_viz_geom(GeomNode *viz_geom); 00067 INLINE void mark_viz_stale(); 00068 00069 private: 00070 // This is the data that must be cycled between pipeline stages. 00071 class EXPCL_PANDA CData : public CycleData { 00072 public: 00073 INLINE CData(); 00074 INLINE CData(const CData ©); 00075 virtual CycleData *make_copy() const; 00076 virtual void write_datagram(BamWriter *manager, Datagram &dg) const; 00077 virtual void fillin(DatagramIterator &scan, BamReader *manager); 00078 00079 Colorf _color; 00080 00081 PT(GeomNode) _viz_geom; 00082 bool _viz_geom_stale; 00083 }; 00084 00085 PipelineCycler<CData> _cycler; 00086 typedef CycleDataReader<CData> CDReader; 00087 typedef CycleDataWriter<CData> CDWriter; 00088 00089 protected: 00090 void write_datagram(BamWriter *manager, Datagram &dg); 00091 void fillin(DatagramIterator &scan, BamReader *manager); 00092 00093 public: 00094 static TypeHandle get_class_type() { 00095 return _type_handle; 00096 } 00097 static void init_type() { 00098 ReferenceCount::init_type(); 00099 register_type(_type_handle, "Light", 00100 ReferenceCount::get_class_type()); 00101 } 00102 virtual TypeHandle get_type() const { 00103 return get_class_type(); 00104 } 00105 00106 private: 00107 static TypeHandle _type_handle; 00108 }; 00109 00110 INLINE ostream &operator << (ostream &out, const Light &light) { 00111 light.output(out); 00112 return out; 00113 } 00114 00115 #include "light.I" 00116 00117 #endif