Panda3D
renderEffects.I
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.I
10  * @author drose
11  * @date 2002-03-14
12  */
13 
14 /**
15  *
16  */
17 INLINE RenderEffects::Effect::
18 Effect(const RenderEffect *effect) :
19  _type(effect->get_type()),
20  _effect(effect)
21 {
22 }
23 
24 /**
25  * This constructor is only used when reading the RenderEffects from a bam
26  * file. At this point, the effect pointer is unknown.
27  */
28 INLINE RenderEffects::Effect::
29 Effect() {
30 }
31 
32 /**
33  * This constructor makes an invalid Effect with no RenderEffect pointer; its
34  * purpose is just to make an object we can use to look up a particular type
35  * in the Effect set.
36  */
37 INLINE RenderEffects::Effect::
38 Effect(TypeHandle type) :
39  _type(type),
40  _effect(nullptr)
41 {
42 }
43 
44 /**
45  *
46  */
47 INLINE RenderEffects::Effect::
48 Effect(const Effect &copy) :
49  _type(copy._type),
50  _effect(copy._effect)
51 {
52 }
53 
54 /**
55  *
56  */
57 INLINE void RenderEffects::Effect::
58 operator = (const Effect &copy) {
59  _type = copy._type;
60  _effect = copy._effect;
61 }
62 
63 /**
64  * This is used by the Effects set to uniquify RenderEffects by type. Only
65  * one RenderEffect of a given type is allowed in the set. This ordering must
66  * also match the ordering reported by compare_to().
67  */
68 INLINE bool RenderEffects::Effect::
69 operator < (const Effect &other) const {
70  return _type < other._type;
71 }
72 
73 /**
74  * Provides an indication of whether a particular effect is equivalent to
75  * another one, for purposes of generating unique RenderEffects. This should
76  * compare all properties of the Effect, but it is important that the type is
77  * compared first, to be consistent with the ordering defined by operator <.
78  */
79 INLINE int RenderEffects::Effect::
80 compare_to(const Effect &other) const {
81  if (_type != other._type) {
82  return _type.get_index() - other._type.get_index();
83  }
84  if (_effect != other._effect) {
85  return _effect < other._effect ? -1 : 1;
86  }
87  return 0;
88 }
89 
90 /**
91  * Returns true if the state is empty, false otherwise.
92  */
93 INLINE bool RenderEffects::
94 is_empty() const {
95  return _effects.empty();
96 }
97 
98 /**
99  * Returns the number of separate effects indicated in the state.
100  * @deprecated in Python, use len(effects) instead, or effects.size() in C++.
101  */
102 INLINE size_t RenderEffects::
104  return _effects.size();
105 }
106 
107 /**
108  * Returns the nth effect in the state.
109  */
110 INLINE const RenderEffect *RenderEffects::
111 get_effect(size_t n) const {
112  nassertr(n < _effects.size(), nullptr);
113  return _effects[n]._effect;
114 }
115 
116 /**
117  * Returns the number of separate effects indicated in the state.
118  */
119 INLINE size_t RenderEffects::
120 size() const {
121  return _effects.size();
122 }
123 
124 /**
125  * Returns the nth effect in the state.
126  */
127 INLINE const RenderEffect *RenderEffects::
128 operator [](size_t n) const {
129  nassertr(n < _effects.size(), nullptr);
130  return _effects[n]._effect;
131 }
132 
133 /**
134  * Returns the effect in the state with the given type.
135  */
136 INLINE const RenderEffect *RenderEffects::
137 operator [](TypeHandle type) const {
138  return get_effect(type);
139 }
140 
141 /**
142  * This function is provided as an optimization, to speed up the render-time
143  * checking for the existance of a DecalEffect on this state. It returns true
144  * if a DecalEffect exists, false otherwise. Note that since there is no
145  * additional information stored on the DecalEffect, there's no point in
146  * returning it if it exists.
147  */
148 INLINE bool RenderEffects::
149 has_decal() const {
150  if ((_flags & F_checked_decal) == 0) {
151  // We pretend this function is const, even though it transparently
152  // modifies the internal decal cache.
153  ((RenderEffects *)this)->determine_decal();
154  }
155  return ((_flags & F_has_decal) != 0);
156 }
157 
158 /**
159  * This function is provided as an optimization, to speed up the render-time
160  * checking for the existance of a ShowBoundsEffect on this state. It returns
161  * true if a ShowBoundsEffect exists, false otherwise. Note that since there
162  * is no additional information stored on the ShowBoundsEffect, there's no
163  * point in returning it if it exists.
164  */
165 INLINE bool RenderEffects::
167  if ((_flags & F_checked_show_bounds) == 0) {
168  // We pretend this function is const, even though it transparently
169  // modifies the internal show_bounds cache.
170  ((RenderEffects *)this)->determine_show_bounds();
171  }
172  return ((_flags & F_has_show_bounds) != 0);
173 }
174 
175 /**
176  * If has_show_bounds() returns true, this will return true if the
177  * ShowBoundsEffect in question requests showing a "tight" bound.
178  */
179 INLINE bool RenderEffects::
181  if ((_flags & F_checked_show_bounds) == 0) {
182  // We pretend this function is const, even though it transparently
183  // modifies the internal show_bounds cache.
184  ((RenderEffects *)this)->determine_show_bounds();
185  }
186  return ((_flags & F_has_show_tight_bounds) != 0);
187 }
188 
189 /**
190  * This function is provided as an optimization, to speed up the render-time
191  * checking for the existance of an effect with a cull_callback on this state.
192  */
193 INLINE bool RenderEffects::
195  if ((_flags & F_checked_cull_callback) == 0) {
196  // We pretend this function is const, even though it transparently
197  // modifies the internal cull_callback cache.
198  ((RenderEffects *)this)->determine_cull_callback();
199  }
200  return ((_flags & F_has_cull_callback) != 0);
201 }
202 
203 /**
204  * This function is provided as an optimization, to speed up the render-time
205  * checking for the existance of an effect with a compute_adjust_transform on
206  * this state.
207  */
208 INLINE bool RenderEffects::
210  if ((_flags & F_checked_adjust_transform) == 0) {
211  // We pretend this function is const, even though it transparently
212  // modifies the internal adjust_transform cache.
213  ((RenderEffects *)this)->determine_adjust_transform();
214  }
215  return ((_flags & F_has_adjust_transform) != 0);
216 }
bool is_empty() const
Returns true if the state is empty, false otherwise.
Definition: renderEffects.I:94
size_type_0 size() const
Returns the number of elements in the ordered vector.
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
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
bool has_cull_callback() const
This function is provided as an optimization, to speed up the render-time checking for the existance ...
bool has_show_bounds() const
This function is provided as an optimization, to speed up the render-time checking for the existance ...
bool has_adjust_transform() const
This function is provided as an optimization, to speed up the render-time checking for the existance ...
bool has_decal() const
This function is provided as an optimization, to speed up the render-time checking for the existance ...
const RenderEffect * get_effect(size_t n) const
Returns the nth effect in the state.
size_t size() const
Returns the number of separate effects indicated in the state.
size_t get_num_effects() const
Returns the number of separate effects indicated in the state.
const RenderEffect * operator [](size_t n) const
Returns the nth effect in the state.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This represents a unique collection of RenderEffect objects that correspond to a particular renderabl...
Definition: renderEffects.h:41
bool has_show_tight_bounds() const
If has_show_bounds() returns true, this will return true if the ShowBoundsEffect in question requests...