Panda3D
Loading...
Searching...
No Matches
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
29class CullTraverser;
31class 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 */
41class EXPCL_PANDA_PGRAPH RenderEffects : public TypedWritableReferenceCount {
42protected:
43 RenderEffects();
44
45public:
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
56PUBLISHED:
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
95public:
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;
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
112private:
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
121private:
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;
126 typedef pset<const RenderEffects *, indirect_less<const RenderEffects *> > States;
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
135private:
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
170public:
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
178protected:
179 static TypedWritable *make_from_bam(const FactoryParams &params);
180 void fillin(DatagramIterator &scan, BamReader *manager);
181
182public:
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
196private:
197 static TypeHandle _type_handle;
198};
199
200INLINE 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
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
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...
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition lightMutex.h:41
A lightweight reentrant mutex.
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
virtual bool unref() const
Explicitly decrements the reference count.
This is the base class for a number of special render effects that may be set on scene graph nodes to...
This represents a unique collection of RenderEffect objects that correspond to a particular renderabl...
static void list_states(std::ostream &out)
Lists all of the RenderEffects in the cache to the output stream, one per line.
bool safe_to_combine() const
Returns true if all of the effects in this set can safely be shared with a sibling node that has the ...
ConstPointerTo< RenderEffects > add_effect(const RenderEffect *effect) const
Returns a new RenderEffects object that represents the same as the source state, with the new RenderE...
bool has_cull_callback() const
This function is provided as an optimization, to speed up the render-time checking for the existance ...
static int get_num_states()
Returns the total number of unique RenderEffects objects allocated in the world.
bool has_decal() const
This function is provided as an optimization, to speed up the render-time checking for the existance ...
ConstPointerTo< RenderEffects > remove_effect(TypeHandle type) const
Returns a new RenderEffects object that represents the same as the source state, with the indicated R...
static ConstPointerTo< RenderEffects > make(const RenderEffect *effect)
Returns a RenderEffects with one effect set.
int find_effect(TypeHandle type) const
Searches for an effect with the indicated type in the state, and returns its index if it is found,...
void adjust_transform(ConstPointerTo< TransformState > &net_transform, ConstPointerTo< TransformState > &node_transform, const PandaNode *node) const
Calls adjust_transform() on all effects.
bool has_adjust_transform() const
This function is provided as an optimization, to speed up the render-time checking for the existance ...
bool is_empty() const
Returns true if the state is empty, false otherwise.
static bool validate_states()
Ensures that the cache is still stored in sorted order.
bool has_show_tight_bounds() const
If has_show_bounds() returns true, this will return true if the ShowBoundsEffect in question requests...
const RenderEffect * get_effect(size_t n) const
Returns the nth effect in the state.
bool safe_to_transform() const
Returns true if all of the effects in this set can safely be transformed, and therefore the complete ...
size_t get_num_effects() const
Returns the number of separate effects indicated in the state.
static ConstPointerTo< RenderEffects > make_empty()
Returns a RenderEffects with no effects set.
void cull_callback(CullTraverser *trav, CullTraverserData &data, ConstPointerTo< TransformState > &node_transform, ConstPointerTo< RenderState > &node_state) const
Calls cull_callback() on all effects.
static TypedWritable * change_this(TypedWritable *old_ptr, BamReader *manager)
Called immediately after complete_pointers(), this gives the object a chance to adjust its own pointe...
bool has_show_bounds() const
This function is provided as an optimization, to speed up the render-time checking for the existance ...
virtual ConstPointerTo< TransformState > prepare_flatten_transform(const TransformState *net_transform) const
Preprocesses the accumulated transform that is about to be applied to (or through) this node due to a...
ConstPointerTo< RenderEffects > xform(const LMatrix4 &mat) const
Returns a new RenderEffects transformed by the indicated matrix.
size_t size() const
Returns the number of separate effects indicated in the state.
static void init_states()
Make sure the global _states map is allocated.
static void register_with_read_factory()
Tells the BamReader how to create objects of type RenderEffects.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition renderState.h:47
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
virtual bool require_fully_complete() const
Some objects require all of their nested pointers to have been completed before the objects themselve...
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.
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 STL function object class, this is intended to be used on any ordered collection of class objects ...
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.
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.
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.