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