Panda3D
lightLensNode.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 lightLensNode.h
10  * @author drose
11  * @date 2002-03-26
12  */
13 
14 #ifndef LIGHTLENSNODE_H
15 #define LIGHTLENSNODE_H
16 
17 #include "pandabase.h"
18 
19 #include "light.h"
20 #include "camera.h"
22 #include "graphicsOutputBase.h"
23 #include "atomicAdjust.h"
24 
25 class ShaderGenerator;
27 
28 /**
29  * A derivative of Light and of Camera. The name might be misleading: it does
30  * not directly derive from LensNode, but through the Camera class. The
31  * Camera serves no purpose unless shadows are enabled.
32  */
33 class EXPCL_PANDA_PGRAPHNODES LightLensNode : public Light, public Camera {
34 PUBLISHED:
35  explicit LightLensNode(const std::string &name, Lens *lens = new PerspectiveLens());
36  virtual ~LightLensNode();
37 
38  INLINE bool has_specular_color() const;
39 
40  INLINE bool is_shadow_caster() const;
41  void set_shadow_caster(bool caster);
42  void set_shadow_caster(bool caster, int buffer_xsize, int buffer_ysize, int sort = -10);
43 
44  INLINE int get_shadow_buffer_sort() const;
45 
46  INLINE LVecBase2i get_shadow_buffer_size() const;
47  INLINE void set_shadow_buffer_size(const LVecBase2i &size);
48 
49  INLINE GraphicsOutputBase *get_shadow_buffer(GraphicsStateGuardianBase *gsg);
50 
51 PUBLISHED:
52  MAKE_PROPERTY(shadow_caster, is_shadow_caster);
53  MAKE_PROPERTY(shadow_buffer_size, get_shadow_buffer_size, set_shadow_buffer_size);
54 
55 public:
56  INLINE void mark_used_by_auto_shader() const;
57 
58 protected:
59  LightLensNode(const LightLensNode &copy);
60  void clear_shadow_buffers();
61  virtual void setup_shadow_map();
62 
63  LVecBase2i _sb_size;
64  bool _shadow_caster;
65  bool _has_specular_color;
66  int _sb_sort;
67  mutable bool _used_by_auto_shader = false;
68 
69  PT(Texture) _shadow_map;
70 
71  // This is really a map of GSG -> GraphicsOutput.
73  ShadowBuffers _sbuffers;
74 
75  // This counts how many LightAttribs in the world are referencing this
76  // LightLensNode object.
77  AtomicAdjust::Integer _attrib_count;
78 
79 public:
80  virtual void attrib_ref();
81  virtual void attrib_unref();
82 
83  virtual PandaNode *as_node();
84  virtual Light *as_light();
85 
86 PUBLISHED:
87  // We have to explicitly publish these because they resolve the multiple
88  // inheritance.
89  virtual void output(std::ostream &out) const;
90  virtual void write(std::ostream &out, int indent_level = 0) const;
91 
92 public:
93  virtual void write_datagram(BamWriter *manager, Datagram &dg);
94 
95 protected:
96  void fillin(DatagramIterator &scan, BamReader *manager);
97 
98 public:
99  static TypeHandle get_class_type() {
100  return _type_handle;
101  }
102  static void init_type() {
103  Light::init_type();
104  Camera::init_type();
105  register_type(_type_handle, "LightLensNode",
106  Light::get_class_type(),
107  Camera::get_class_type());
108  }
109  virtual TypeHandle get_type() const {
110  return get_class_type();
111  }
112  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
113 
114 private:
115  static TypeHandle _type_handle;
116 
117  friend class GraphicsStateGuardian;
118 };
119 
120 INLINE std::ostream &operator << (std::ostream &out, const LightLensNode &light) {
121  light.output(out);
122  return out;
123 }
124 
125 #include "lightLensNode.I"
126 
127 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
Definition: camera.h:35
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: camera.cxx:271
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
An abstract base class for GraphicsOutput, for all the usual reasons.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Encapsulates all the communication with a particular instance of a given rendering backend.
A base class for any number of different kinds of lenses, linear and otherwise.
Definition: lens.h:41
A derivative of Light and of Camera.
Definition: lightLensNode.h:33
The abstract interface to all kinds of lights.
Definition: light.h:38
virtual void attrib_ref()
This is called when the light is added to a LightAttrib.
Definition: light.cxx:166
virtual void attrib_unref()
This is called when the light is removed from a LightAttrib.
Definition: light.cxx:173
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
virtual Light * as_light()
Cross-casts the node to a Light pointer, if it is one of the four kinds of Light nodes,...
Definition: pandaNode.cxx:2095
A perspective-type lens: a normal camera.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:71
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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