renderEffects.I 9.1 KB

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