Panda3D
 All Classes Functions Variables Enumerations
lightLensNode.cxx
1 // Filename: lightLensNode.cxx
2 // Created by: drose (26Mar02)
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 #include "lightLensNode.h"
16 #include "bamWriter.h"
17 #include "bamReader.h"
18 #include "datagram.h"
19 #include "datagramIterator.h"
20 #include "renderState.h"
21 #include "cullFaceAttrib.h"
22 #include "colorWriteAttrib.h"
23 
24 TypeHandle LightLensNode::_type_handle;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: LightLensNode::Constructor
28 // Access: Published
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 LightLensNode::
32 LightLensNode(const string &name, Lens *lens) :
33  Camera(name, lens)
34 {
35  set_active(false);
36  _shadow_caster = false;
37  _sb_xsize = 512;
38  _sb_ysize = 512;
39  _sb_sort = -10;
40  //set_initial_state(RenderState::make(ShaderAttrib::make_off(), 1000));
41  // Backface culling helps eliminating artifacts.
42  set_initial_state(RenderState::make(CullFaceAttrib::make_reverse(),
43  ColorWriteAttrib::make(ColorWriteAttrib::C_off)));
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: LightLensNode::Destructor
48 // Access: Published
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 LightLensNode::
52 ~LightLensNode() {
53  set_active(false);
54  clear_shadow_buffers();
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: LightLensNode::Copy Constructor
59 // Access: Protected
60 // Description:
61 ////////////////////////////////////////////////////////////////////
62 LightLensNode::
63 LightLensNode(const LightLensNode &copy) :
64  Light(copy),
65  Camera(copy)
66 {
67  _shadow_caster = false;
68  _sb_xsize = 512;
69  _sb_ysize = 512;
70  _sb_sort = -10;
71  // Backface culling helps eliminating artifacts.
72  set_initial_state(RenderState::make(CullFaceAttrib::make_reverse(),
73  ColorWriteAttrib::make(ColorWriteAttrib::C_off)));
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: LightLensNode::clear_shadow_buffers
78 // Access: Protected
79 // Description: Clears the shadow buffers, meaning they will be
80 // automatically recreated when the Shader Generator
81 // needs them.
82 ////////////////////////////////////////////////////////////////////
83 void LightLensNode::
84 clear_shadow_buffers() {
85  ShadowBuffers::iterator it;
86  for(it = _sbuffers.begin(); it != _sbuffers.end(); ++it) {
87  (*it).first->remove_window((*it).second);
88  }
89  _sbuffers.clear();
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: LightLensNode::as_node
94 // Access: Published, Virtual
95 // Description: Returns the Light object upcast to a PandaNode.
96 ////////////////////////////////////////////////////////////////////
99  return this;
100 }
101 
102 ////////////////////////////////////////////////////////////////////
103 // Function: LightLensNode::as_light
104 // Access: Public, Virtual
105 // Description: Cross-casts the node to a Light pointer, if it is one
106 // of the four kinds of Light nodes, or returns NULL if
107 // it is not.
108 ////////////////////////////////////////////////////////////////////
111  return this;
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: LightLensNode::output
116 // Access: Public, Virtual
117 // Description:
118 ////////////////////////////////////////////////////////////////////
119 void LightLensNode::
120 output(ostream &out) const {
121  LensNode::output(out);
122 }
123 
124 ////////////////////////////////////////////////////////////////////
125 // Function: LightLensNode::write
126 // Access: Public, Virtual
127 // Description:
128 ////////////////////////////////////////////////////////////////////
129 void LightLensNode::
130 write(ostream &out, int indent_level) const {
131  LensNode::write(out, indent_level);
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: LightLensNode::write_datagram
136 // Access: Public, Virtual
137 // Description: Writes the contents of this object to the datagram
138 // for shipping out to a Bam file.
139 ////////////////////////////////////////////////////////////////////
140 void LightLensNode::
142  Camera::write_datagram(manager, dg);
143  Light::write_datagram(manager, dg);
144 
145  dg.add_bool(_shadow_caster);
146  dg.add_int32(_sb_xsize);
147  dg.add_int32(_sb_ysize);
148  dg.add_int32(_sb_sort);
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function: LightLensNode::fillin
153 // Access: Protected
154 // Description: This internal function is called by make_from_bam to
155 // read in all of the relevant data from the BamFile for
156 // the new LightLensNode.
157 ////////////////////////////////////////////////////////////////////
158 void LightLensNode::
159 fillin(DatagramIterator &scan, BamReader *manager) {
160  Camera::fillin(scan, manager);
161  Light::fillin(scan, manager);
162 
163  bool shadow_caster = scan.get_bool();
164  int sb_xsize = scan.get_int32();
165  int sb_ysize = scan.get_int32();
166  int sb_sort = scan.get_int32();
167  set_shadow_caster(shadow_caster, sb_xsize, sb_ysize, sb_sort);
168 }
void set_shadow_caster(bool caster)
Sets the flag indicating whether this light should cast shadows or not.
Definition: lightLensNode.I:37
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
bool get_bool()
Extracts a boolean value.
A base class for any number of different kinds of lenses, linear and otherwise.
Definition: lens.h:45
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
PN_int32 get_int32()
Extracts a signed 32-bit integer.
void set_active(bool active)
Sets the active flag on the camera.
Definition: camera.I:23
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:316
void add_bool(bool value)
Adds a boolean value to the datagram.
Definition: datagram.I:118
virtual Light * as_light()
Cross-casts the node to a Light pointer, if it is one of the four kinds of Light nodes, or returns NULL if it is not.
A derivative of Light and of Camera.
Definition: lightLensNode.h:35
virtual PandaNode * as_node()
Returns the Light object upcast to a PandaNode.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void add_int32(PN_int32 value)
Adds a signed 32-bit integer to the datagram.
Definition: datagram.I:159
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
Definition: camera.h:37
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43