Panda3D
|
00001 // Filename: light.h 00002 // Created by: mike (09Jan97) 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 LIGHT_H 00016 #define LIGHT_H 00017 00018 #include "pandabase.h" 00019 00020 #include "referenceCount.h" 00021 #include "luse.h" 00022 #include "cycleData.h" 00023 #include "cycleDataReader.h" 00024 #include "cycleDataLockedReader.h" 00025 #include "cycleDataWriter.h" 00026 #include "pipelineCycler.h" 00027 #include "updateSeq.h" 00028 #include "geomNode.h" 00029 00030 class NodePath; 00031 class PandaNode; 00032 class GraphicsStateGuardianBase; 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Class : Light 00036 // Description : The abstract interface to all kinds of lights. The 00037 // actual light objects also inherit from PandaNode, and 00038 // can therefore be added to the scene graph at some 00039 // arbitrary point to define the coordinate system of 00040 // effect. 00041 //////////////////////////////////////////////////////////////////// 00042 class EXPCL_PANDA_PGRAPH Light : virtual public ReferenceCount { 00043 // We inherit from ReferenceCount instead of TypedReferenceCount so 00044 // that LightNode does not inherit from TypedObject twice. Note 00045 // that we also inherit virtually from ReferenceCount for the same 00046 // reason. 00047 PUBLISHED: 00048 INLINE Light(); 00049 INLINE Light(const Light ©); 00050 virtual ~Light(); 00051 00052 virtual PandaNode *as_node()=0; 00053 virtual bool is_ambient_light() const; 00054 00055 INLINE const LColor &get_color() const; 00056 INLINE void set_color(const LColor &color); 00057 00058 INLINE void set_priority(int priority); 00059 INLINE int get_priority() const; 00060 virtual int get_class_priority() const=0; 00061 00062 public: 00063 virtual void output(ostream &out) const=0; 00064 virtual void write(ostream &out, int indent_level) const=0; 00065 virtual void bind(GraphicsStateGuardianBase *gsg, const NodePath &light, 00066 int light_id)=0; 00067 00068 virtual bool get_vector_to_light(LVector3 &result, 00069 const LPoint3 &from_object_point, 00070 const LMatrix4 &to_object_space); 00071 00072 GeomNode *get_viz(); 00073 00074 INLINE static UpdateSeq get_sort_seq(); 00075 00076 protected: 00077 virtual void fill_viz_geom(GeomNode *viz_geom); 00078 INLINE void mark_viz_stale(); 00079 00080 // This enumerated class defines the relative class priority of 00081 // different kinds of lights. This hierarchy is only used to 00082 // resolve multiple lights of the same priority specified by 00083 // set_priority(). In general, the first items in this list have a 00084 // lesser priority than later items. 00085 enum ClassPriority { 00086 CP_ambient_priority, 00087 CP_point_priority, 00088 CP_directional_priority, 00089 CP_spot_priority, 00090 }; 00091 00092 private: 00093 // The priority is not cycled, because there's no real reason to do 00094 // so, and cycling it makes it difficult to synchronize with the 00095 // LightAttribs. 00096 int _priority; 00097 static UpdateSeq _sort_seq; 00098 00099 // This is the data that must be cycled between pipeline stages. 00100 class EXPCL_PANDA_PGRAPH CData : public CycleData { 00101 public: 00102 INLINE CData(); 00103 INLINE CData(const CData ©); 00104 virtual CycleData *make_copy() const; 00105 virtual void write_datagram(BamWriter *manager, Datagram &dg) const; 00106 virtual void fillin(DatagramIterator &scan, BamReader *manager); 00107 virtual TypeHandle get_parent_type() const { 00108 return Light::get_class_type(); 00109 } 00110 00111 LColor _color; 00112 00113 PT(GeomNode) _viz_geom; 00114 bool _viz_geom_stale; 00115 }; 00116 00117 PipelineCycler<CData> _cycler; 00118 typedef CycleDataReader<CData> CDReader; 00119 typedef CycleDataLockedReader<CData> CDLockedReader; 00120 typedef CycleDataWriter<CData> CDWriter; 00121 00122 protected: 00123 void write_datagram(BamWriter *manager, Datagram &dg); 00124 void fillin(DatagramIterator &scan, BamReader *manager); 00125 00126 public: 00127 static TypeHandle get_class_type() { 00128 return _type_handle; 00129 } 00130 static void init_type() { 00131 ReferenceCount::init_type(); 00132 register_type(_type_handle, "Light", 00133 ReferenceCount::get_class_type()); 00134 } 00135 virtual TypeHandle get_type() const { 00136 return get_class_type(); 00137 } 00138 00139 private: 00140 static TypeHandle _type_handle; 00141 }; 00142 00143 INLINE ostream &operator << (ostream &out, const Light &light) { 00144 light.output(out); 00145 return out; 00146 } 00147 00148 #include "light.I" 00149 00150 #endif