Panda3D
|
00001 // Filename: cullableObject.I 00002 // Created by: drose (04Mar02) 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 // Function: CullableObject::Constructor 00017 // Access: Public 00018 // Description: Creates an empty CullableObject whose pointers can be 00019 // filled in later. 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE CullableObject:: 00022 CullableObject() : 00023 _fancy(false) 00024 { 00025 } 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function: CullableObject::Constructor 00029 // Access: Public 00030 // Description: Creates a CullableObject based the indicated geom, 00031 // with the indicated render state and transform. 00032 //////////////////////////////////////////////////////////////////// 00033 INLINE CullableObject:: 00034 CullableObject(const Geom *geom, const RenderState *state, 00035 const TransformState *net_transform, 00036 const TransformState *modelview_transform, 00037 const GraphicsStateGuardianBase *gsg) : 00038 _geom(geom), 00039 _state(state), 00040 _net_transform(net_transform), 00041 _modelview_transform(modelview_transform), 00042 _internal_transform(gsg->get_cs_transform()->compose(modelview_transform)), 00043 _fancy(false) 00044 { 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: CullableObject::Constructor 00049 // Access: Public 00050 // Description: Creates a CullableObject based the indicated geom, 00051 // with the indicated render state and transform. 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE CullableObject:: 00054 CullableObject(const Geom *geom, const RenderState *state, 00055 const TransformState *net_transform, 00056 const TransformState *modelview_transform, 00057 const TransformState *internal_transform) : 00058 _geom(geom), 00059 _state(state), 00060 _net_transform(net_transform), 00061 _modelview_transform(modelview_transform), 00062 _internal_transform(internal_transform), 00063 _fancy(false) 00064 { 00065 } 00066 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: CullableObject::Copy Constructor 00070 // Access: Public 00071 // Description: Copies the CullableObject, but does not copy its 00072 // children (decals). 00073 //////////////////////////////////////////////////////////////////// 00074 INLINE CullableObject:: 00075 CullableObject(const CullableObject ©) : 00076 _geom(copy._geom), 00077 _munger(copy._munger), 00078 _munged_data(copy._munged_data), 00079 _state(copy._state), 00080 _net_transform(copy._net_transform), 00081 _modelview_transform(copy._modelview_transform), 00082 _internal_transform(copy._internal_transform), 00083 _fancy(false) 00084 { 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: CullableObject::Copy Assignment Operator 00089 // Access: Public 00090 // Description: Copies the CullableObject, but does not copy its 00091 // children (decals). 00092 //////////////////////////////////////////////////////////////////// 00093 INLINE void CullableObject:: 00094 operator = (const CullableObject ©) { 00095 nassertv(!_fancy); 00096 _geom = copy._geom; 00097 _munger = copy._munger; 00098 _munged_data = copy._munged_data; 00099 _state = copy._state; 00100 _net_transform = copy._net_transform; 00101 _modelview_transform = copy._modelview_transform; 00102 _internal_transform = copy._internal_transform; 00103 } 00104 00105 //////////////////////////////////////////////////////////////////// 00106 // Function: CullableObject::is_fancy 00107 // Access: Public 00108 // Description: Returns true if the object has something fancy to it: 00109 // decals, maybe, or a draw_callback, that prevents it 00110 // from being rendered inline. 00111 //////////////////////////////////////////////////////////////////// 00112 INLINE bool CullableObject:: 00113 is_fancy() const { 00114 return _fancy; 00115 } 00116 00117 //////////////////////////////////////////////////////////////////// 00118 // Function: CullableObject::has_decals 00119 // Access: Public 00120 // Description: Returns true if the object has decals associated with 00121 // it. 00122 //////////////////////////////////////////////////////////////////// 00123 INLINE bool CullableObject:: 00124 has_decals() const { 00125 return _fancy && (_next != (CullableObject *)NULL); 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: CullableObject::draw 00130 // Access: Public 00131 // Description: Draws the cullable object on the GSG immediately, in 00132 // the GSG's current state. This should only be called 00133 // from the draw thread. 00134 //////////////////////////////////////////////////////////////////// 00135 INLINE void CullableObject:: 00136 draw(GraphicsStateGuardianBase *gsg, bool force, Thread *current_thread) { 00137 if (_fancy) { 00138 draw_fancy(gsg, force, current_thread); 00139 } else { 00140 nassertv(_geom != (Geom *)NULL); 00141 gsg->set_state_and_transform(_state, _internal_transform); 00142 draw_inline(gsg, force, current_thread); 00143 } 00144 } 00145 00146 //////////////////////////////////////////////////////////////////// 00147 // Function: CullableObject::request_resident 00148 // Access: Public 00149 // Description: Returns true if all the data necessary to render this 00150 // object is currently resident in memory. If this 00151 // returns false, the data will be brought back into 00152 // memory shortly; try again later. 00153 //////////////////////////////////////////////////////////////////// 00154 INLINE bool CullableObject:: 00155 request_resident() const { 00156 bool resident = true; 00157 if (!_geom->request_resident()) { 00158 resident = false; 00159 } 00160 if (!_munged_data->request_resident()) { 00161 resident = false; 00162 } 00163 return resident; 00164 } 00165 00166 00167 //////////////////////////////////////////////////////////////////// 00168 // Function: CullableObject::set_draw_callback 00169 // Access: Public 00170 // Description: Specifies a CallbackObject that will be responsible 00171 // for drawing this object. 00172 //////////////////////////////////////////////////////////////////// 00173 INLINE void CullableObject:: 00174 set_draw_callback(CallbackObject *draw_callback) { 00175 make_fancy(); 00176 if (draw_callback != _draw_callback) { 00177 if (_draw_callback != (CallbackObject *)NULL) { 00178 unref_delete(_draw_callback); 00179 } 00180 _draw_callback = draw_callback; 00181 if (_draw_callback != (CallbackObject *)NULL) { 00182 _draw_callback->ref(); 00183 } 00184 } 00185 } 00186 00187 //////////////////////////////////////////////////////////////////// 00188 // Function: CullableObject::set_next 00189 // Access: Public 00190 // Description: Sets the next object in the decal chain. This next 00191 // object will be destructed when this object destructs. 00192 //////////////////////////////////////////////////////////////////// 00193 INLINE void CullableObject:: 00194 set_next(CullableObject *next) { 00195 make_fancy(); 00196 nassertv(_next == (CullableObject *)NULL); 00197 _next = next; 00198 } 00199 00200 //////////////////////////////////////////////////////////////////// 00201 // Function: CullableObject::get_next 00202 // Access: Public 00203 // Description: Returns the next object in the decal chain, or NULL 00204 // for the end of the chain. 00205 //////////////////////////////////////////////////////////////////// 00206 INLINE CullableObject *CullableObject:: 00207 get_next() const { 00208 if (_fancy) { 00209 return _next; 00210 } 00211 return NULL; 00212 } 00213 00214 //////////////////////////////////////////////////////////////////// 00215 // Function: CullableObject::flush_level 00216 // Access: Public, Static 00217 // Description: Flushes the PStatCollectors used during traversal. 00218 //////////////////////////////////////////////////////////////////// 00219 INLINE void CullableObject:: 00220 flush_level() { 00221 _sw_sprites_pcollector.flush_level(); 00222 } 00223 00224 //////////////////////////////////////////////////////////////////// 00225 // Function: CullableObject::make_fancy 00226 // Access: Private 00227 // Description: Elevates this object to "fancy" status. This means 00228 // that the additional pointers, like _next and 00229 // _draw_callback, have meaningful values and should be 00230 // examined. 00231 //////////////////////////////////////////////////////////////////// 00232 INLINE void CullableObject:: 00233 make_fancy() { 00234 if (!_fancy) { 00235 _fancy = true; 00236 _draw_callback = NULL; 00237 _next = NULL; 00238 } 00239 } 00240 00241 //////////////////////////////////////////////////////////////////// 00242 // Function: CullableObject::draw_inline 00243 // Access: Private 00244 // Description: Draws the cullable object on the GSG immediately, in 00245 // the GSG's current state. This should only be called 00246 // from the draw thread. Assumes the GSG has already 00247 // been set to the appropriate state. 00248 //////////////////////////////////////////////////////////////////// 00249 INLINE void CullableObject:: 00250 draw_inline(GraphicsStateGuardianBase *gsg, bool force, Thread *current_thread) { 00251 _geom->draw(gsg, _munger, _munged_data, force, current_thread); 00252 } 00253 00254 //////////////////////////////////////////////////////////////////// 00255 // Function: CullableObject::SortPoints::Constructor 00256 // Access: Public 00257 // Description: 00258 //////////////////////////////////////////////////////////////////// 00259 INLINE CullableObject::SortPoints:: 00260 SortPoints(const CullableObject::PointData *array) : 00261 _array(array) 00262 { 00263 } 00264 00265 //////////////////////////////////////////////////////////////////// 00266 // Function: CullableObject::SortPoints::operator () 00267 // Access: Public 00268 // Description: Orders the points from back-to-front for correct 00269 // transparency sorting in munge_points_to_quads 00270 //////////////////////////////////////////////////////////////////// 00271 INLINE bool CullableObject::SortPoints:: 00272 operator () (unsigned short a, unsigned short b) const { 00273 return _array[a]._dist > _array[b]._dist; 00274 } 00275 00276 //////////////////////////////////////////////////////////////////// 00277 // Function: CullableObject::SourceFormat::operator < 00278 // Access: Public 00279 // Description: 00280 //////////////////////////////////////////////////////////////////// 00281 INLINE bool CullableObject::SourceFormat:: 00282 operator < (const CullableObject::SourceFormat &other) const { 00283 if (_format != other._format) { 00284 return _format < other._format; 00285 } 00286 if (_sprite_texcoord != other._sprite_texcoord) { 00287 return (int)_sprite_texcoord < (int)other._sprite_texcoord; 00288 } 00289 if (_retransform_sprites != other._retransform_sprites) { 00290 return (int)_retransform_sprites < (int)other._retransform_sprites; 00291 } 00292 return false; 00293 }