Panda3D

Loading...
Searching...
No Matches
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
35PUBLISHED:
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
129PUBLISHED:
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
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
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
LightAttrib::get_off_light
get_off_light
Returns the nth light turned off by the attribute, sorted in arbitrary (pointer) order.
Definition lightAttrib.h:80
LightAttrib::get_ambient_contribution
LColor get_ambient_contribution() const
Returns the total contribution of all the ambient lights.
Definition lightAttrib.cxx:560
LightAttrib::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type LightAttrib.
Definition lightAttrib.cxx:963
LightAttrib::get_num_lights
int get_num_lights() const
Returns the number of lights listed in the attribute.
Definition lightAttrib.cxx:288
LightAttrib::has_all_off
bool has_all_off() const
Returns true if this attrib turns off all lights (although it may also turn some on).
Definition lightAttrib.I:100
LightAttrib::add_light
ConstPointerTo< RenderAttrib > add_light(Light *light) const
Returns a new LightAttrib, just like this one, but with the indicated light added to the list of ligh...
Definition lightAttrib.cxx:345
LightAttrib::get_num_off_lights
get_num_off_lights
Returns the number of lights that are turned off by the attribute.
Definition lightAttrib.h:80
LightAttrib::get_most_important_light
NodePath get_most_important_light() const
Returns the most important light (that is, the light with the highest priority) in the LightAttrib,...
Definition lightAttrib.cxx:546
LightAttrib::remove_light
ConstPointerTo< RenderAttrib > remove_light(Light *light) const
Returns a new LightAttrib, just like this one, but with the indicated light removed from the list of ...
Definition lightAttrib.cxx:363
LightAttrib::make_all_off
static ConstPointerTo< RenderAttrib > make_all_off()
Constructs a new LightAttrib object that turns off all lights (and hence disables lighting).
Definition lightAttrib.cxx:393
LightAttrib::make
static ConstPointerTo< RenderAttrib > make(Operation op, Light *light)
Constructs a new LightAttrib object that turns on (or off, according to op) the indicated light(s).
Definition lightAttrib.cxx:95
LightAttrib::get_num_on_lights
get_num_on_lights
Returns the number of lights that are turned on by the attribute.
Definition lightAttrib.h:74
LightAttrib::has_any_on_light
bool has_any_on_light() const
Returns true if any light is turned on by the attrib, false otherwise.
Definition lightAttrib.I:63
LightAttrib::add_off_light
ConstPointerTo< RenderAttrib > add_off_light(const NodePath &light) const
Returns a new LightAttrib, just like this one, but with the indicated light added to the list of ligh...
Definition lightAttrib.cxx:482
LightAttrib::has_off_light
bool has_off_light(const NodePath &light) const
Returns true if the indicated light is turned off by the attrib, false otherwise.
Definition lightAttrib.I:90
LightAttrib::has_light
bool has_light(Light *light) const
Returns true if the indicated light is listed in the attrib, false otherwise.
Definition lightAttrib.cxx:327
LightAttrib::add_on_light
ConstPointerTo< RenderAttrib > add_on_light(const NodePath &light) const
Returns a new LightAttrib, just like this one, but with the indicated light added to the list of ligh...
Definition lightAttrib.cxx:410
LightAttrib::has_on_light
bool has_on_light(const NodePath &light) const
Returns true if the indicated light is turned on by the attrib, false otherwise.
Definition lightAttrib.I:55
LightAttrib::remove_on_light
ConstPointerTo< RenderAttrib > remove_on_light(const NodePath &light) const
Returns a new LightAttrib, just like this one, but with the indicated light removed from the list of ...
Definition lightAttrib.cxx:434
LightAttrib::is_identity
bool is_identity() const
Returns true if this is an identity attrib: it does not change the set of lights in use.
Definition lightAttrib.I:109
LightAttrib::make_default
static ConstPointerTo< RenderAttrib > make_default()
Returns a RenderAttrib that corresponds to whatever the standard default properties for render attrib...
Definition lightAttrib.cxx:249
LightAttrib::get_operation
Operation get_operation() const
Returns the basic operation type of the LightAttrib.
Definition lightAttrib.cxx:265
LightAttrib::replace_off_light
ConstPointerTo< RenderAttrib > replace_off_light(const NodePath &source, const NodePath &dest) const
Returns a new LightAttrib, just like this one, but with the indicated light replaced with the given o...
Definition lightAttrib.cxx:514
LightAttrib::get_num_non_ambient_lights
size_t get_num_non_ambient_lights() const
Returns the number of non-ambient lights that are turned on by this attribute.
Definition lightAttrib.I:35
LightAttrib::replace_on_light
ConstPointerTo< RenderAttrib > replace_on_light(const NodePath &source, const NodePath &dest) const
Returns a new LightAttrib, just like this one, but with the indicated light replaced with the given o...
Definition lightAttrib.cxx:451
LightAttrib::get_light
Light * get_light(int n) const
Returns the nth light listed in the attribute.
Definition lightAttrib.cxx:307
LightAttrib::get_on_light
get_on_light
Returns the nth light turned on by the attribute, sorted in render order.
Definition lightAttrib.h:74
LightAttrib::remove_off_light
ConstPointerTo< RenderAttrib > remove_off_light(const NodePath &light) const
Returns a new LightAttrib, just like this one, but with the indicated light removed from the list of ...
Definition lightAttrib.cxx:502
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
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::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
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
Definition ordered_vector.h:269
plist
This is our own Panda specialization on the default STL list.
Definition plist.h:35
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.