Panda3D
 All Classes Functions Variables Enumerations
lightAttrib.h
1 // Filename: lightAttrib.h
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 #ifndef LIGHTATTRIB_H
16 #define LIGHTATTRIB_H
17 
18 #include "pandabase.h"
19 
20 #include "light.h"
21 #include "renderAttrib.h"
22 #include "nodePath.h"
23 #include "ordered_vector.h"
24 #include "pmap.h"
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : LightAttrib
28 // Description : Indicates which set of lights should be considered
29 // "on" to illuminate geometry at this level and below.
30 // A LightAttrib can either add lights or remove lights
31 // from the total set of "on" lights.
32 ////////////////////////////////////////////////////////////////////
33 class EXPCL_PANDA_PGRAPH LightAttrib : public RenderAttrib {
34 protected:
35  INLINE LightAttrib();
36  INLINE LightAttrib(const LightAttrib &copy);
37 
38 PUBLISHED:
39 
40  // This is the old, deprecated interface to LightAttrib. Do not use
41  // any of these methods for new code; these methods will be removed
42  // soon.
43  enum Operation {
44  O_set,
45  O_add,
46  O_remove
47  };
48  static CPT(RenderAttrib) make(Operation op,
49  Light *light);
50  static CPT(RenderAttrib) make(Operation op,
51  Light *light1, Light *light2);
52  static CPT(RenderAttrib) make(Operation op,
53  Light *light1, Light *light2,
54  Light *light3);
55  static CPT(RenderAttrib) make(Operation op,
56  Light *light1, Light *light2,
57  Light *light3, Light *light4);
58  static CPT(RenderAttrib) make_default();
59 
60  Operation get_operation() const;
61 
62  int get_num_lights() const;
63  Light *get_light(int n) const;
64  bool has_light(Light *light) const;
65 
66  CPT(RenderAttrib) add_light(Light *light) const;
67  CPT(RenderAttrib) remove_light(Light *light) const;
68 
69 
70  // The following is the new, more general interface to the
71  // LightAttrib.
72  static CPT(RenderAttrib) make();
73  static CPT(RenderAttrib) make_all_off();
74 
75  INLINE int get_num_on_lights() const;
76  INLINE NodePath get_on_light(int n) const;
77  MAKE_SEQ(get_on_lights, get_num_on_lights, get_on_light);
78  INLINE bool has_on_light(const NodePath &light) const;
79 
80  INLINE int get_num_off_lights() const;
81  INLINE NodePath get_off_light(int n) const;
82  MAKE_SEQ(get_off_lights, get_num_off_lights, get_off_light);
83  INLINE bool has_off_light(const NodePath &light) const;
84  INLINE bool has_all_off() const;
85 
86  INLINE bool is_identity() const;
87 
88  CPT(RenderAttrib) add_on_light(const NodePath &light) const;
89  CPT(RenderAttrib) remove_on_light(const NodePath &light) const;
90  CPT(RenderAttrib) add_off_light(const NodePath &light) const;
91  CPT(RenderAttrib) remove_off_light(const NodePath &light) const;
92 
93  CPT(LightAttrib) filter_to_max(int max_lights) const;
94  NodePath get_most_important_light() const;
95 
96 public:
97  virtual void output(ostream &out) const;
98  virtual void write(ostream &out, int indent_level) const;
99 
100 protected:
101  virtual int compare_to_impl(const RenderAttrib *other) const;
102  virtual size_t get_hash_impl() const;
103  virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
104  virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
105  virtual CPT(RenderAttrib) get_auto_shader_attrib_impl(const RenderState *state) const;
106 
107 private:
108  INLINE void check_filtered() const;
109  void sort_on_lights();
110 
111 private:
112  typedef ov_set<NodePath> Lights;
113  Lights _on_lights, _off_lights;
114  bool _off_all_lights;
115 
117  Filtered _filtered;
118 
119  UpdateSeq _sort_seq;
120 
121  static CPT(RenderAttrib) _empty_attrib;
122  static CPT(RenderAttrib) _all_off_attrib;
123 
124 PUBLISHED:
125  static int get_class_slot() {
126  return _attrib_slot;
127  }
128  virtual int get_slot() const {
129  return get_class_slot();
130  }
131 
132 public:
133  // This data is only needed when reading from a bam file.
136  public:
137  // We hold a pointer to each of the PandaNodes on the on_list and
138  // off_list. We will later convert these to NodePaths in
139  // finalize().
140  int _num_off_lights;
141  int _num_on_lights;
142  NodeList _off_list;
143  NodeList _on_list;
144  };
145 
146 public:
147  static void register_with_read_factory();
148  virtual void write_datagram(BamWriter *manager, Datagram &dg);
149  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
150 
151  virtual void finalize(BamReader *manager);
152 
153 protected:
154  static TypedWritable *make_from_bam(const FactoryParams &params);
155  void fillin(DatagramIterator &scan, BamReader *manager);
156 
157 public:
158  static TypeHandle get_class_type() {
159  return _type_handle;
160  }
161  static void init_type() {
162  RenderAttrib::init_type();
163  register_type(_type_handle, "LightAttrib",
164  RenderAttrib::get_class_type());
165  _attrib_slot = register_slot(_type_handle, 20, make_default);
166  }
167  virtual TypeHandle get_type() const {
168  return get_class_type();
169  }
170  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
171 
172 private:
173  static TypeHandle _type_handle;
174  static int _attrib_slot;
175 };
176 
177 #include "lightAttrib.I"
178 
179 #endif
180 
static int register_slot(TypeHandle type_handle, int sort, RenderAttribRegistry::MakeDefaultFunc *make_default_func)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
Definition: renderAttrib.I:163
The abstract interface to all kinds of lights.
Definition: light.h:42
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:60
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
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-&gt;read_pointer() was called in fillin()...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
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
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
Indicates which set of lights should be considered &quot;on&quot; to illuminate geometry at this level and belo...
Definition: lightAttrib.h:33