Panda3D

lightAttrib.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 lightAttrib.h
10 * @author drose
11 * @date 2002-03-26
12 */
13
14 #ifndef LIGHTATTRIB_H
15 #define LIGHTATTRIB_H
16
17 #include "pandabase.h"
18
19 #include "light.h"
20 #include "renderAttrib.h"
21 #include "nodePath.h"
22 #include "ordered_vector.h"
23 #include "pmap.h"
24
25 /**
26 * Indicates which set of lights should be considered "on" to illuminate
27 * geometry at this level and below. A LightAttrib can either add lights or
28 * remove lights from the total set of "on" lights.
29 */
30 class EXPCL_PANDA_PGRAPH LightAttrib : public RenderAttrib {
31 protected:
32 INLINE LightAttrib();
33 LightAttrib(const LightAttrib &copy);
34
35 PUBLISHED:
36 virtual ~LightAttrib();
37
38 // This is the old, deprecated interface to LightAttrib. Do not use any of
39 // these methods for new code; these methods will be removed soon.
40 enum Operation {
41 O_set,
42 O_add,
43 O_remove
44 };
45 static CPT(RenderAttrib) make(Operation op,
46 Light *light);
47 static CPT(RenderAttrib) make(Operation op,
48 Light *light1, Light *light2);
49 static CPT(RenderAttrib) make(Operation op,
50 Light *light1, Light *light2,
51 Light *light3);
52 static CPT(RenderAttrib) make(Operation op,
53 Light *light1, Light *light2,
54 Light *light3, Light *light4);
55 static CPT(RenderAttrib) make_default();
56
57 Operation get_operation() const;
58
59 int get_num_lights() const;
60 Light *get_light(int n) const;
61 bool has_light(Light *light) const;
62
63 CPT(RenderAttrib) add_light(Light *light) const;
64 CPT(RenderAttrib) remove_light(Light *light) const;
65
66
67 // The following is the new, more general interface to the LightAttrib.
68 static CPT(RenderAttrib) make();
69 static CPT(RenderAttrib) make_all_off();
70
71 INLINE size_t get_num_on_lights() const;
72 INLINE size_t get_num_non_ambient_lights() const;
73 INLINE NodePath get_on_light(size_t n) const;
74 MAKE_SEQ(get_on_lights, get_num_on_lights, get_on_light);
75 INLINE bool has_on_light(const NodePath &light) const;
76 INLINE bool has_any_on_light() const;
77
78 INLINE size_t get_num_off_lights() const;
79 INLINE NodePath get_off_light(size_t n) const;
80 MAKE_SEQ(get_off_lights, get_num_off_lights, get_off_light);
81 INLINE bool has_off_light(const NodePath &light) const;
82 INLINE bool has_all_off() const;
83
84 INLINE bool is_identity() const;
85
86 CPT(RenderAttrib) add_on_light(const NodePath &light) const;
87 CPT(RenderAttrib) remove_on_light(const NodePath &light) const;
88 CPT(RenderAttrib) replace_on_light(const NodePath &source, const NodePath &dest) const;
89 CPT(RenderAttrib) add_off_light(const NodePath &light) const;
90 CPT(RenderAttrib) remove_off_light(const NodePath &light) const;
91 CPT(RenderAttrib) replace_off_light(const NodePath &source, const NodePath &dest) const;
92
93 NodePath get_most_important_light() const;
94 LColor get_ambient_contribution() const;
95
96 MAKE_SEQ_PROPERTY(on_lights, get_num_on_lights, get_on_light);
97 MAKE_SEQ_PROPERTY(off_lights, get_num_off_lights, get_off_light);
98
99 public:
100 virtual void output(std::ostream &out) const;
101 virtual void write(std::ostream &out, int indent_level) const;
102
103 protected:
104 virtual int compare_to_impl(const RenderAttrib *other) const;
105 virtual size_t get_hash_impl() const;
106 virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
107 virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
108
109 private:
110 INLINE void check_sorted() const;
111 void sort_on_lights();
112
113 private:
114 typedef ov_set<NodePath> Lights;
115 Lights _on_lights, _off_lights;
116 bool _off_all_lights;
117
118 // These are sorted in descending order of priority, with the ambient lights
119 // sorted last.
120 typedef pvector<NodePath> OrderedLights;
121 OrderedLights _sorted_on_lights;
122 size_t _num_non_ambient_lights;
123
124 UpdateSeq _sort_seq;
125
126 static CPT(RenderAttrib) _empty_attrib;
127 static CPT(RenderAttrib) _all_off_attrib;
128
129 PUBLISHED:
130 static int get_class_slot() {
131 return _attrib_slot;
132 }
133 virtual int get_slot() const {
134 return get_class_slot();
135 }
136 MAKE_PROPERTY(class_slot, get_class_slot);
137
138 public:
139 // This data is only needed when reading from a bam file.
140 typedef pvector<PT(PandaNode) > NodeList;
141 class BamAuxData : public BamReader::AuxData {
142 public:
143 // We hold a pointer to each of the PandaNodes on the on_list and
144 // off_list. We will later convert these to NodePaths in finalize().
145 int _num_off_lights;
146 int _num_on_lights;
147 NodeList _off_list;
148 NodeList _on_list;
149 };
150
151 public:
152 static void register_with_read_factory();
153 virtual void write_datagram(BamWriter *manager, Datagram &dg);
154 virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
155
156 virtual void finalize(BamReader *manager);
157
158 protected:
159 static TypedWritable *make_from_bam(const FactoryParams &params);
160 void fillin(DatagramIterator &scan, BamReader *manager);
161
162 public:
163 static TypeHandle get_class_type() {
164 return _type_handle;
165 }
166 static void init_type() {
167 RenderAttrib::init_type();
168 register_type(_type_handle, "LightAttrib",
169 RenderAttrib::get_class_type());
170 _attrib_slot = register_slot(_type_handle, 20, new LightAttrib);
171 }
172 virtual TypeHandle get_type() const {
173 return get_class_type();
174 }
175 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
176
177 private:
178 static TypeHandle _type_handle;
179 static int _attrib_slot;
180 };
181
182 #include "lightAttrib.I"
183
184 #endif
BamReader::AuxData
Definition: bamReader.h:228
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
LightAttrib::BamAuxData
Definition: lightAttrib.h:141
LightAttrib
Indicates which set of lights should be considered "on" to illuminate geometry at this level and belo...
Definition: lightAttrib.h:30
Light
The abstract interface to all kinds of lights.
Definition: light.h:38
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
PandaNode
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
RenderAttrib
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
RenderAttrib::finalize
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
Definition: renderAttrib.cxx:565
RenderAttrib::write_datagram
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: renderAttrib.cxx:527
RenderAttrib::register_slot
static int register_slot(TypeHandle type_handle, int sort, RenderAttrib *default_attrib)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
Definition: renderAttrib.I:101
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
TypedWritable::complete_pointers
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
Definition: typedWritable.cxx:81
UpdateSeq
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
ov_set< NodePath >
plist
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
pvector< NodePath >
lightAttrib.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
light.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
nodePath.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ordered_vector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
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
renderAttrib.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.