00001 // Filename: renderEffects.I 00002 // Created by: drose (14Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: RenderEffects::Effect::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE RenderEffects::Effect:: 00022 Effect(const RenderEffect *effect) : 00023 _type(effect->get_type()), 00024 _effect(effect) 00025 { 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: RenderEffects::Effect::Constructor 00030 // Access: Public 00031 // Description: This constructor is only used when reading the 00032 // RenderEffects from a bam file. At this point, the 00033 // effect pointer is unknown. 00034 //////////////////////////////////////////////////////////////////// 00035 INLINE RenderEffects::Effect:: 00036 Effect() { 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function: RenderEffects::Effect::Constructor 00041 // Access: Public 00042 // Description: This constructor makes an invalid Effect with no 00043 // RenderEffect pointer; its purpose is just to make an 00044 // object we can use to look up a particular type in the 00045 // Effect set. 00046 //////////////////////////////////////////////////////////////////// 00047 INLINE RenderEffects::Effect:: 00048 Effect(TypeHandle type) : 00049 _type(type), 00050 _effect(NULL) 00051 { 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: RenderEffects::Effect::Copy Constructor 00056 // Access: Public 00057 // Description: 00058 //////////////////////////////////////////////////////////////////// 00059 INLINE RenderEffects::Effect:: 00060 Effect(const Effect ©) : 00061 _type(copy._type), 00062 _effect(copy._effect) 00063 { 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: RenderEffects::Effect::Copy Assignment Operator 00068 // Access: Public 00069 // Description: 00070 //////////////////////////////////////////////////////////////////// 00071 INLINE void RenderEffects::Effect:: 00072 operator = (const Effect ©) { 00073 _type = copy._type; 00074 _effect = copy._effect; 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: RenderEffects::Effect::operator < 00079 // Access: Public 00080 // Description: This is used by the Effects set to uniquify 00081 // RenderEffects by type. Only one RenderEffect of a 00082 // given type is allowed in the set. This ordering must 00083 // also match the ordering reported by compare_to(). 00084 //////////////////////////////////////////////////////////////////// 00085 INLINE bool RenderEffects::Effect:: 00086 operator < (const Effect &other) const { 00087 return _type < other._type; 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: RenderEffects::Effect::compare_to 00092 // Access: Public 00093 // Description: Provides an indication of whether a particular 00094 // effect is equivalent to another one, for purposes 00095 // of generating unique RenderEffects. This should 00096 // compare all properties of the Effect, but it is 00097 // important that the type is compared first, to be 00098 // consistent with the ordering defined by operator <. 00099 //////////////////////////////////////////////////////////////////// 00100 INLINE int RenderEffects::Effect:: 00101 compare_to(const Effect &other) const { 00102 if (_type != other._type) { 00103 return _type.get_index() - other._type.get_index(); 00104 } 00105 if (_effect != other._effect) { 00106 return _effect < other._effect ? -1 : 1; 00107 } 00108 return 0; 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: RenderEffects::is_empty 00113 // Access: Published 00114 // Description: Returns true if the state is empty, false otherwise. 00115 //////////////////////////////////////////////////////////////////// 00116 INLINE bool RenderEffects:: 00117 is_empty() const { 00118 return _effects.empty(); 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: RenderEffects::get_num_effects 00123 // Access: Published 00124 // Description: Returns the number of separate effects indicated 00125 // in the state. 00126 //////////////////////////////////////////////////////////////////// 00127 INLINE int RenderEffects:: 00128 get_num_effects() const { 00129 return _effects.size(); 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: RenderEffects::get_effect 00134 // Access: Published 00135 // Description: Returns the nth effect in the state. 00136 //////////////////////////////////////////////////////////////////// 00137 INLINE const RenderEffect *RenderEffects:: 00138 get_effect(int n) const { 00139 nassertr(n >= 0 && n < (int)_effects.size(), NULL); 00140 return _effects[n]._effect; 00141 } 00142 00143 //////////////////////////////////////////////////////////////////// 00144 // Function: RenderEffects::has_decal 00145 // Access: Public 00146 // Description: This function is provided as an optimization, to 00147 // speed up the render-time checking for the existance 00148 // of a DecalEffect on this state. It returns true if a 00149 // DecalEffect exists, false otherwise. Note that since 00150 // there is no additional information stored on the 00151 // DecalEffect, there's no point in returning it if it 00152 // exists. 00153 //////////////////////////////////////////////////////////////////// 00154 INLINE bool RenderEffects:: 00155 has_decal() const { 00156 if ((_flags & F_checked_decal) == 0) { 00157 // We pretend this function is const, even though it transparently 00158 // modifies the internal decal cache. 00159 ((RenderEffects *)this)->determine_decal(); 00160 } 00161 return ((_flags & F_has_decal) != 0); 00162 } 00163 00164 //////////////////////////////////////////////////////////////////// 00165 // Function: RenderEffects::has_show_bounds 00166 // Access: Public 00167 // Description: This function is provided as an optimization, to 00168 // speed up the render-time checking for the existance 00169 // of a ShowBoundsEffect on this state. It returns true 00170 // if a ShowBoundsEffect exists, false otherwise. Note 00171 // that since there is no additional information stored 00172 // on the ShowBoundsEffect, there's no point in 00173 // returning it if it exists. 00174 //////////////////////////////////////////////////////////////////// 00175 INLINE bool RenderEffects:: 00176 has_show_bounds() const { 00177 if ((_flags & F_checked_show_bounds) == 0) { 00178 // We pretend this function is const, even though it transparently 00179 // modifies the internal show_bounds cache. 00180 ((RenderEffects *)this)->determine_show_bounds(); 00181 } 00182 return ((_flags & F_has_show_bounds) != 0); 00183 } 00184 00185 //////////////////////////////////////////////////////////////////// 00186 // Function: RenderEffects::has_show_tight_bounds 00187 // Access: Public 00188 // Description: If has_show_bounds() returns true, this will return 00189 // true if the ShowBoundsEffect in question requests 00190 // showing a "tight" bound. 00191 //////////////////////////////////////////////////////////////////// 00192 INLINE bool RenderEffects:: 00193 has_show_tight_bounds() const { 00194 if ((_flags & F_checked_show_bounds) == 0) { 00195 // We pretend this function is const, even though it transparently 00196 // modifies the internal show_bounds cache. 00197 ((RenderEffects *)this)->determine_show_bounds(); 00198 } 00199 return ((_flags & F_has_show_tight_bounds) != 0); 00200 } 00201 00202 //////////////////////////////////////////////////////////////////// 00203 // Function: RenderEffects::has_cull_callback 00204 // Access: Public 00205 // Description: This function is provided as an optimization, to 00206 // speed up the render-time checking for the existance 00207 // of an effect with a cull_callback on this state. 00208 //////////////////////////////////////////////////////////////////// 00209 INLINE bool RenderEffects:: 00210 has_cull_callback() const { 00211 if ((_flags & F_checked_cull_callback) == 0) { 00212 // We pretend this function is const, even though it transparently 00213 // modifies the internal cull_callback cache. 00214 ((RenderEffects *)this)->determine_cull_callback(); 00215 } 00216 return ((_flags & F_has_cull_callback) != 0); 00217 } 00218 00219 //////////////////////////////////////////////////////////////////// 00220 // Function: RenderEffects::has_adjust_transform 00221 // Access: Public 00222 // Description: This function is provided as an optimization, to 00223 // speed up the render-time checking for the existance 00224 // of an effect with a compute_adjust_transform on this 00225 // state. 00226 //////////////////////////////////////////////////////////////////// 00227 INLINE bool RenderEffects:: 00228 has_adjust_transform() const { 00229 if ((_flags & F_checked_adjust_transform) == 0) { 00230 // We pretend this function is const, even though it transparently 00231 // modifies the internal adjust_transform cache. 00232 ((RenderEffects *)this)->determine_adjust_transform(); 00233 } 00234 return ((_flags & F_has_adjust_transform) != 0); 00235 }