15 #include "lightAttrib.h" 16 #include "pandaNode.h" 18 #include "graphicsStateGuardianBase.h" 19 #include "bamReader.h" 20 #include "bamWriter.h" 22 #include "datagramIterator.h" 23 #include "config_pgraph.h" 24 #include "attribNodeRegistry.h" 29 int LightAttrib::_attrib_slot;
42 nassertr(la != (
Light *)NULL && lb != (
Light *)NULL, a < b);
47 return la->get_class_priority() > lb->get_class_priority();
61 make(LightAttrib::Operation op,
Light *light) {
63 <<
"Using deprecated LightAttrib interface.\n";
69 attrib = make_all_off();
84 nassertr(
false, make());
98 make(LightAttrib::Operation op,
Light *light1,
Light *light2) {
100 <<
"Using deprecated LightAttrib interface.\n";
106 attrib = make_all_off();
124 nassertr(
false, make());
138 make(LightAttrib::Operation op,
Light *light1,
Light *light2,
141 <<
"Using deprecated LightAttrib interface.\n";
147 attrib = make_all_off();
168 nassertr(
false, make());
182 make(LightAttrib::Operation op,
Light *light1,
Light *light2,
185 <<
"Using deprecated LightAttrib interface.\n";
191 attrib = make_all_off();
215 nassertr(
false, make());
250 <<
"Using deprecated LightAttrib interface.\n";
255 }
else if (get_num_off_lights() == 0) {
276 <<
"Using deprecated LightAttrib interface.\n";
278 if (get_num_off_lights() == 0) {
279 return get_num_on_lights();
281 return get_num_off_lights();
298 <<
"Using deprecated LightAttrib interface.\n";
300 if (get_num_off_lights() == 0) {
301 return get_on_light(n).node()->as_light();
303 return get_off_light(n).node()->as_light();
321 <<
"Using deprecated LightAttrib interface.\n";
323 if (get_num_off_lights() == 0) {
324 return has_on_light(
NodePath(light->as_node()));
326 return has_off_light(
NodePath(light->as_node()));
340 add_light(
Light *light)
const {
342 <<
"Using deprecated LightAttrib interface.\n";
344 if (get_num_off_lights() == 0) {
345 return add_on_light(
NodePath(light->as_node()));
347 return add_off_light(
NodePath(light->as_node()));
362 remove_light(
Light *light)
const {
364 <<
"Using deprecated LightAttrib interface.\n";
366 if (get_num_off_lights() == 0) {
367 return remove_on_light(
NodePath(light->as_node()));
369 return remove_off_light(
NodePath(light->as_node()));
387 return _empty_attrib;
402 attrib->_off_all_lights =
true;
403 _all_off_attrib = return_new(attrib);
406 return _all_off_attrib;
417 add_on_light(
const NodePath &light)
const {
420 attrib->_on_lights.insert(light);
421 attrib->_off_lights.erase(light);
423 pair<Lights::iterator, bool> insert_result =
425 if (insert_result.second) {
427 attrib->_off_lights.erase(light);
430 return return_new(attrib);
441 remove_on_light(
const NodePath &light)
const {
444 attrib->_on_lights.erase(light);
445 return return_new(attrib);
456 add_off_light(
const NodePath &light)
const {
459 if (!_off_all_lights) {
460 attrib->_off_lights.insert(light);
462 attrib->_on_lights.erase(light);
463 return return_new(attrib);
474 remove_off_light(
const NodePath &light)
const {
477 attrib->_off_lights.erase(light);
478 return return_new(attrib);
495 filter_to_max(
int max_lights)
const {
496 if (max_lights < 0 || (
int)_on_lights.size() <= max_lights) {
505 Filtered::const_iterator fi;
506 fi = _filtered.find(max_lights);
507 if (fi != _filtered.end()) {
515 Lights priority_lights, ambient_lights;
518 Lights::const_iterator li;
519 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
530 sort(priority_lights.
begin(), priority_lights.
end(),
534 if ((
int)priority_lights.
size() > max_lights) {
535 priority_lights.erase(priority_lights.
begin() + max_lights,
536 priority_lights.
end());
540 for (li = ambient_lights.
begin(); li != ambient_lights.
end(); ++li) {
545 priority_lights.
sort();
549 attrib->_on_lights.
swap(priority_lights);
556 ((
LightAttrib *)
this)->_filtered[max_lights] = light_attrib;
569 get_most_important_light()
const {
574 Lights::const_iterator li;
575 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
579 if (best.
is_empty() || compare(np, best)) {
594 output(ostream &out)
const {
595 out << get_type() <<
":";
596 if (_off_lights.empty()) {
597 if (_on_lights.empty()) {
598 if (_off_all_lights) {
604 if (_off_all_lights) {
613 Lights::const_iterator fi;
614 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
623 if (!_on_lights.empty()) {
628 Lights::const_iterator li;
629 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
645 write(ostream &out,
int indent_level)
const {
646 indent(out, indent_level) << get_type() <<
":";
647 if (_off_lights.empty()) {
648 if (_on_lights.empty()) {
649 if (_off_all_lights) {
655 if (_off_all_lights) {
664 Lights::const_iterator fi;
665 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
667 indent(out, indent_level + 2) << light <<
"\n";
670 if (!_on_lights.empty()) {
671 indent(out, indent_level) <<
"on\n";
675 Lights::const_iterator li;
676 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
678 indent(out, indent_level + 2) << light <<
"\n";
700 DCAST_INTO_R(ta, other, 0);
702 if (_off_all_lights != ta->_off_all_lights) {
703 return (
int)_off_all_lights - (int)ta->_off_all_lights;
706 Lights::const_iterator li = _on_lights.begin();
707 Lights::const_iterator oli = ta->_on_lights.
begin();
709 while (li != _on_lights.end() && oli != ta->_on_lights.
end()) {
722 if (li != _on_lights.end()) {
725 if (oli != ta->_on_lights.
end()) {
729 Lights::const_iterator fi = _off_lights.begin();
730 Lights::const_iterator ofi = ta->_off_lights.
begin();
732 while (fi != _off_lights.end() && ofi != ta->_off_lights.
end()) {
745 if (fi != _off_lights.end()) {
748 if (ofi != ta->_off_lights.
end()) {
766 get_hash_impl()
const {
769 Lights::const_iterator li;
770 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
779 for (li = _off_lights.begin(); li != _off_lights.end(); ++li) {
807 DCAST_INTO_R(ta, other, 0);
809 if (ta->_off_all_lights) {
818 Lights::const_iterator ai = _on_lights.begin();
819 Lights::const_iterator bi = ta->_on_lights.
begin();
820 Lights::const_iterator ci = ta->_off_lights.
begin();
824 back_insert_iterator<Lights> result =
825 back_inserter(new_attrib->_on_lights);
827 while (ai != _on_lights.end() &&
828 bi != ta->_on_lights.
end() &&
829 ci != ta->_off_lights.
end()) {
838 }
else if ((*ci) < (*ai)) {
850 }
else if ((*bi) < (*ai)) {
866 while (ai != _on_lights.end() && bi != ta->_on_lights.
end()) {
874 }
else if ((*bi) < (*ai)) {
890 while (ai != _on_lights.end() && ci != ta->_off_lights.
end()) {
898 }
else if ((*ci) < (*ai)) {
911 while (ai != _on_lights.end()) {
917 while (bi != ta->_on_lights.
end()) {
923 return return_new(new_attrib);
949 get_auto_shader_attrib_impl(
const RenderState *state)
const {
993 Lights::const_iterator fi;
994 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
1006 Lights::const_iterator nti;
1007 for (nti = _on_lights.begin(); nti != _on_lights.end(); ++nti) {
1025 nassertr(aux != NULL, pi);
1028 aux->_off_list.reserve(aux->_num_off_lights);
1029 for (i = 0; i < aux->_num_off_lights; ++i) {
1031 DCAST_INTO_R(node, p_list[pi++], pi);
1032 aux->_off_list.push_back(node);
1035 aux->_on_list.reserve(aux->_num_on_lights);
1036 for (i = 0; i < aux->_num_on_lights; ++i) {
1038 DCAST_INTO_R(node, p_list[pi++], pi);
1039 aux->_on_list.push_back(node);
1056 nassertv(aux != NULL);
1057 nassertv(aux->_num_off_lights == (
int)aux->_off_list.size());
1058 nassertv(aux->_num_on_lights == (
int)aux->_on_list.size());
1062 _off_lights.reserve(aux->_off_list.size());
1063 NodeList::iterator ni;
1064 for (ni = aux->_off_list.begin(); ni != aux->_off_list.end(); ++ni) {
1066 int n = areg->find_node(node->get_type(), node->get_name());
1069 _off_lights.push_back(areg->get_node(n));
1073 _off_lights.push_back(
NodePath(node));
1078 _on_lights.reserve(aux->_on_list.size());
1079 for (ni = aux->_on_list.begin(); ni != aux->_on_list.end(); ++ni) {
1081 int n = areg->find_node(node->get_type(), node->get_name());
1084 _on_lights.push_back(areg->get_node(n));
1088 _on_lights.push_back(
NodePath(node));
1108 parse_params(params, scan, manager);
1109 attrib->fillin(scan, manager);
1125 RenderAttrib::fillin(scan, manager);
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 basic node of the scene graph or data graph.
The abstract interface to all kinds of lights.
bool get_bool()
Extracts a boolean value.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
bool is_empty() const
Returns true if the NodePath contains no nodes.
size_type_0 size() const
Returns the number of elements in the ordered vector.
This global object records NodePaths that are referenced by scene graph attribs, such as ClipPlaneAtt...
bool has_light(Light *light) const
Returns true if the indicated light is listed in the attrib, false otherwise.
int compare_to(const NodePath &other) const
Returns a number less than zero if this NodePath sorts before the other one, greater than zero if it ...
Base class for objects that can be written to and read from Bam files.
iterator_0 begin()
Returns the iterator that marks the first element in the ordered vector.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
void swap(ordered_vector< Key, Compare, Vector > &other)
Exchanges the contents of this vector and the other vector, in constant time (e.g., with a pointer swap).
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
void add_bool(bool value)
Adds a boolean value to the 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.
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()...
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
void read_pointers(DatagramIterator &scan, int count)
A convenience function to read a contiguous list of pointers.
string get_name() const
Returns the name of the referenced node.
void sort()
Maps to sort_unique().
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
static UpdateSeq get_sort_seq()
Returns a global sequence number that is incremented any time any Light in the world changes sort or ...
void push_back(const value_type_0 &key)
Adds the new element to the end of the vector without regard for proper sorting.
Operation get_operation() const
Returns the basic operation type of the LightAttrib.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
virtual bool is_ambient_light() const
Returns true if this is an AmbientLight, false if it is not a light, or it is some other kind of ligh...
Light * get_light(int n) const
Returns the nth light listed in the attribute.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
PandaNode * node() const
Returns the referenced node of the path.
AuxData * get_aux_data(TypedWritable *obj, const string &name) const
Returns the pointer previously associated with the bam reader by a previous call to set_aux_data()...
int get_num_lights() const
Returns the number of lights listed in the attribute.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
int get_priority() const
Returns the priority associated with this light.
A class to retrieve the individual data elements previously stored in a Datagram. ...
size_t add_hash(size_t hash) const
Adds the NodePath into the running hash.
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void set_aux_data(TypedWritable *obj, const string &name, AuxData *data)
Associates an arbitrary block of data with the indicated object (or NULL), and the indicated name...
static void register_with_read_factory()
Tells the BamReader how to create objects of type LightAttrib.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Indicates which set of lights should be considered "on" to illuminate geometry at this level and belo...
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...