Panda3D
renderEffects.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 renderEffects.h
10  * @author drose
11  * @date 2002-03-14
12  */
13 
14 #ifndef RENDEREFFECTS_H
15 #define RENDEREFFECTS_H
16 
17 #include "pandabase.h"
18 
19 #include "transformState.h"
20 #include "renderState.h"
21 
22 #include "renderEffect.h"
24 #include "pointerTo.h"
25 #include "ordered_vector.h"
26 #include "lightReMutex.h"
27 #include "lightMutex.h"
28 
29 class CullTraverser;
30 class CullTraverserData;
31 class FactoryParams;
32 
33 /**
34  * This represents a unique collection of RenderEffect objects that correspond
35  * to a particular renderable state.
36  *
37  * You should not attempt to create or modify a RenderEffects object directly.
38  * Instead, call one of the make() functions to create one for you. And
39  * instead of modifying a RenderEffects object, create a new one.
40  */
41 class EXPCL_PANDA_PGRAPH RenderEffects : public TypedWritableReferenceCount {
42 protected:
43  RenderEffects();
44 
45 public:
46  RenderEffects(const RenderEffects &copy) = delete;
47  virtual ~RenderEffects();
48 
49  RenderEffects &operator = (const RenderEffects &copy) = delete;
50 
51  bool safe_to_transform() const;
52  virtual CPT(TransformState) prepare_flatten_transform(const TransformState *net_transform) const;
53  bool safe_to_combine() const;
54  CPT(RenderEffects) xform(const LMatrix4 &mat) const;
55 
56 PUBLISHED:
57  bool operator < (const RenderEffects &other) const;
58 
59  INLINE bool is_empty() const;
60  INLINE size_t get_num_effects() const;
61  INLINE const RenderEffect *get_effect(size_t n) const;
62 
63  INLINE size_t size() const;
64  INLINE const RenderEffect *operator [] (size_t n) const;
65  INLINE const RenderEffect *operator [] (TypeHandle type) const;
66 
67  int find_effect(TypeHandle type) const;
68 
69  static CPT(RenderEffects) make_empty();
70  static CPT(RenderEffects) make(const RenderEffect *effect);
71  static CPT(RenderEffects) make(const RenderEffect *effect1,
72  const RenderEffect *effect2);
73  static CPT(RenderEffects) make(const RenderEffect *effect1,
74  const RenderEffect *effect2,
75  const RenderEffect *effect3);
76  static CPT(RenderEffects) make(const RenderEffect *effect1,
77  const RenderEffect *effect2,
78  const RenderEffect *effect3,
79  const RenderEffect *effect4);
80 
81  CPT(RenderEffects) add_effect(const RenderEffect *effect) const;
82  CPT(RenderEffects) remove_effect(TypeHandle type) const;
83 
84  const RenderEffect *get_effect(TypeHandle type) const;
85 
86  virtual bool unref() const;
87 
88  void output(std::ostream &out) const;
89  void write(std::ostream &out, int indent_level) const;
90 
91  static int get_num_states();
92  static void list_states(std::ostream &out);
93  static bool validate_states();
94 
95 public:
96  INLINE bool has_decal() const;
97  INLINE bool has_show_bounds() const;
98  INLINE bool has_show_tight_bounds() const;
99 
100  INLINE bool has_cull_callback() const;
101  void cull_callback(CullTraverser *trav, CullTraverserData &data,
102  CPT(TransformState) &node_transform,
103  CPT(RenderState) &node_state) const;
104 
105  INLINE bool has_adjust_transform() const;
106  void adjust_transform(CPT(TransformState) &net_transform,
107  CPT(TransformState) &node_transform,
108  const PandaNode *node) const;
109 
110  static void init_states();
111 
112 private:
113  static CPT(RenderEffects) return_new(RenderEffects *state);
114  void release_new();
115 
116  void determine_decal();
117  void determine_show_bounds();
118  void determine_cull_callback();
119  void determine_adjust_transform();
120 
121 private:
122  // This mutex protects _states. It also protects any modification to the
123  // cache, which is encoded in _composition_cache and
124  // _invert_composition_cache.
125  static LightReMutex *_states_lock;
127  static States *_states;
128  static CPT(RenderEffects) _empty_state;
129 
130  // This iterator records the entry corresponding to this RenderEffects
131  // object in the above global set. We keep the iterator around so we can
132  // remove it when the RenderEffects destructs.
133  States::iterator _saved_entry;
134 
135 private:
136  // This is the actual data within the RenderEffects: a set of RenderEffects.
137  class Effect {
138  public:
139  INLINE Effect(const RenderEffect *effect);
140  INLINE Effect();
141  INLINE Effect(TypeHandle type);
142  INLINE Effect(const Effect &copy);
143  INLINE void operator = (const Effect &copy);
144  INLINE bool operator < (const Effect &other) const;
145  INLINE int compare_to(const Effect &other) const;
146 
147  TypeHandle _type;
148  CPT(RenderEffect) _effect;
149  };
150  typedef ov_set<Effect> Effects;
151  Effects _effects;
152 
153  enum Flags {
154  F_checked_decal = 0x0001,
155  F_has_decal = 0x0002,
156  F_checked_show_bounds = 0x0004,
157  F_has_show_bounds = 0x0008,
158  F_has_show_tight_bounds = 0x0010,
159  F_checked_cull_callback = 0x0020,
160  F_has_cull_callback = 0x0040,
161  F_checked_adjust_transform = 0x0080,
162  F_has_adjust_transform = 0x0100,
163  };
164  int _flags;
165 
166  // This mutex protects _flags, and all of the above computed values.
167  LightMutex _lock;
168 
169 
170 public:
171  static void register_with_read_factory();
172  virtual void write_datagram(BamWriter *manager, Datagram &dg);
173  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
174  virtual bool require_fully_complete() const;
175  static TypedWritable *change_this(TypedWritable *old_ptr, BamReader *manager);
176  virtual void finalize(BamReader *manager);
177 
178 protected:
179  static TypedWritable *make_from_bam(const FactoryParams &params);
180  void fillin(DatagramIterator &scan, BamReader *manager);
181 
182 public:
183  static TypeHandle get_class_type() {
184  return _type_handle;
185  }
186  static void init_type() {
187  TypedWritableReferenceCount::init_type();
188  register_type(_type_handle, "RenderEffects",
189  TypedWritableReferenceCount::get_class_type());
190  }
191  virtual TypeHandle get_type() const {
192  return get_class_type();
193  }
194  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
195 
196 private:
197  static TypeHandle _type_handle;
198 };
199 
200 INLINE std::ostream &operator << (std::ostream &out, const RenderEffects &state) {
201  state.output(out);
202  return out;
203 }
204 
205 #include "renderEffects.I"
206 
207 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
Indicates a coordinate-system transform on vertices.
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A lightweight reentrant mutex.
Definition: lightReMutex.h:30
This collects together the pieces of data that are accumulated for each node while walking the scene ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
This is the base class for a number of special render effects that may be set on scene graph nodes to...
Definition: renderEffect.h:48
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.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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().
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
virtual bool require_fully_complete() const
Some objects require all of their nested pointers to have been completed before the objects themselve...
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:73
This is our own Panda specialization on the default STL set.
Definition: pset.h:49
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:81
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:39
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
This represents a unique collection of RenderEffect objects that correspond to a particular renderabl...
Definition: renderEffects.h:41
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
virtual bool unref() const
Explicitly decrements the reference count.