Panda3D
 All Classes Functions Variables Enumerations
light.h
1 // Filename: light.h
2 // Created by: mike (09Jan97)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef LIGHT_H
16 #define LIGHT_H
17 
18 #include "pandabase.h"
19 
20 #include "referenceCount.h"
21 #include "luse.h"
22 #include "cycleData.h"
23 #include "cycleDataReader.h"
24 #include "cycleDataLockedReader.h"
25 #include "cycleDataWriter.h"
26 #include "pipelineCycler.h"
27 #include "updateSeq.h"
28 #include "geomNode.h"
29 
30 class NodePath;
31 class PandaNode;
33 
34 ////////////////////////////////////////////////////////////////////
35 // Class : Light
36 // Description : The abstract interface to all kinds of lights. The
37 // actual light objects also inherit from PandaNode, and
38 // can therefore be added to the scene graph at some
39 // arbitrary point to define the coordinate system of
40 // effect.
41 ////////////////////////////////////////////////////////////////////
42 class EXPCL_PANDA_PGRAPH Light {
43 PUBLISHED:
44  INLINE Light();
45  INLINE Light(const Light &copy);
46  virtual ~Light();
47 
48  virtual PandaNode *as_node()=0;
49  virtual bool is_ambient_light() const;
50 
51  INLINE const LColor &get_color() const;
52  INLINE void set_color(const LColor &color);
53 
54  virtual PN_stdfloat get_exponent() const;
55  virtual const LColor &get_specular_color() const;
56  virtual const LVecBase3 &get_attenuation() const;
57 
58  INLINE void set_priority(int priority);
59  INLINE int get_priority() const;
60  virtual int get_class_priority() const=0;
61 
62 public:
63  virtual void output(ostream &out) const=0;
64  virtual void write(ostream &out, int indent_level) const=0;
65  virtual void bind(GraphicsStateGuardianBase *gsg, const NodePath &light,
66  int light_id)=0;
67 
68  virtual bool get_vector_to_light(LVector3 &result,
69  const LPoint3 &from_object_point,
70  const LMatrix4 &to_object_space);
71 
72  GeomNode *get_viz();
73 
74  INLINE static UpdateSeq get_sort_seq();
75 
76 protected:
77  virtual void fill_viz_geom(GeomNode *viz_geom);
78  INLINE void mark_viz_stale();
79 
80  // This enumerated class defines the relative class priority of
81  // different kinds of lights. This hierarchy is only used to
82  // resolve multiple lights of the same priority specified by
83  // set_priority(). In general, the first items in this list have a
84  // lesser priority than later items.
85  enum ClassPriority {
86  CP_ambient_priority,
87  CP_point_priority,
88  CP_directional_priority,
89  CP_spot_priority,
90  };
91 
92 private:
93  // The priority is not cycled, because there's no real reason to do
94  // so, and cycling it makes it difficult to synchronize with the
95  // LightAttribs.
96  int _priority;
97  static UpdateSeq _sort_seq;
98 
99  // This is the data that must be cycled between pipeline stages.
100  class EXPCL_PANDA_PGRAPH CData : public CycleData {
101  public:
102  INLINE CData();
103  INLINE CData(const CData &copy);
104  virtual CycleData *make_copy() const;
105  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
106  virtual void fillin(DatagramIterator &scan, BamReader *manager);
107  virtual TypeHandle get_parent_type() const {
108  return Light::get_class_type();
109  }
110 
111  LColor _color;
112 
113  PT(GeomNode) _viz_geom;
114  bool _viz_geom_stale;
115  };
116 
117  PipelineCycler<CData> _cycler;
121 
122 protected:
123  void write_datagram(BamWriter *manager, Datagram &dg);
124  void fillin(DatagramIterator &scan, BamReader *manager);
125 
126 public:
127  static TypeHandle get_class_type() {
128  return _type_handle;
129  }
130  static void init_type() {
131  ReferenceCount::init_type();
132  register_type(_type_handle, "Light",
133  ReferenceCount::get_class_type());
134  }
135  virtual TypeHandle get_type() const {
136  return get_class_type();
137  }
138 
139 private:
140  static TypeHandle _type_handle;
141 };
142 
143 INLINE ostream &operator << (ostream &out, const Light &light) {
144  light.output(out);
145  return out;
146 }
147 
148 #include "light.I"
149 
150 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
The abstract interface to all kinds of lights.
Definition: light.h:42
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class&#39;s make_from_bam() method to read in all...
Definition: cycleData.cxx:68
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A class to retrieve the individual data elements previously stored in a Datagram. ...
virtual void write_datagram(BamWriter *, Datagram &) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: cycleData.cxx:34
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37