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