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 */
30class EXPCL_PANDA_PGRAPH LightAttrib : public RenderAttrib {
31protected:
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
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
99public:
100 virtual void output(std::ostream &out) const;
101 virtual void write(std::ostream &out, int indent_level) const;
102
103protected:
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
109private:
110 INLINE void check_sorted() const;
111 void sort_on_lights();
112
113private:
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
138public:
139 // This data is only needed when reading from a bam file.
140 typedef pvector<PT(PandaNode) > NodeList;
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
151public:
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
158protected:
159 static TypedWritable *make_from_bam(const FactoryParams &params);
160 void fillin(DatagramIterator &scan, BamReader *manager);
161
162public:
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
177private:
178 static TypeHandle _type_handle;
179 static int _attrib_slot;
180};
181
182#include "lightAttrib.I"
183
184#endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
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 instance of this class is passed to the Factory when requesting it to do its business and construc...
Indicates which set of lights should be considered "on" to illuminate geometry at this level and belo...
Definition lightAttrib.h:30
get_off_light
Returns the nth light turned off by the attribute, sorted in arbitrary (pointer) order.
Definition lightAttrib.h:80
LColor get_ambient_contribution() const
Returns the total contribution of all the ambient lights.
static void register_with_read_factory()
Tells the BamReader how to create objects of type LightAttrib.
int get_num_lights() const
Returns the number of lights listed in the attribute.
bool has_all_off() const
Returns true if this attrib turns off all lights (although it may also turn some on).
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...
get_num_off_lights
Returns the number of lights that are turned off by the attribute.
Definition lightAttrib.h:80
NodePath get_most_important_light() const
Returns the most important light (that is, the light with the highest priority) in the LightAttrib,...
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 ...
static ConstPointerTo< RenderAttrib > make_all_off()
Constructs a new LightAttrib object that turns off all lights (and hence disables lighting).
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).
get_num_on_lights
Returns the number of lights that are turned on by the attribute.
Definition lightAttrib.h:74
bool has_any_on_light() const
Returns true if any light is turned on by the attrib, false otherwise.
Definition lightAttrib.I:63
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...
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
bool has_light(Light *light) const
Returns true if the indicated light is listed in the attrib, false otherwise.
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...
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
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 ...
bool is_identity() const
Returns true if this is an identity attrib: it does not change the set of lights in use.
static ConstPointerTo< RenderAttrib > make_default()
Returns a RenderAttrib that corresponds to whatever the standard default properties for render attrib...
Operation get_operation() const
Returns the basic operation type of the LightAttrib.
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...
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
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...
Light * get_light(int n) const
Returns the nth light listed in the attribute.
get_on_light
Returns the nth light turned on by the attribute, sorted in render order.
Definition lightAttrib.h:74
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 ...
The abstract interface to all kinds of lights.
Definition light.h:38
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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 ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
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().
This is a sequence number that increments monotonically.
Definition updateSeq.h:37
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
This is our own Panda specialization on the default STL list.
Definition plist.h:35
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.
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(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.