Changeset 13041 for OpenSceneGraph/trunk/include/osgUtil/CullVisitor
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osgUtil/CullVisitor (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgUtil/CullVisitor
r12833 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 44 44 * sorted opaque bin. The opaque bin is rendered first, and then the 45 45 * transparent bin is rendered in order from the furthest osg::Drawable 46 * from the eye to the one nearest the eye. 46 * from the eye to the one nearest the eye. 47 47 */ 48 48 class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStack 49 49 { 50 50 public: 51 51 52 52 typedef osg::Matrix::value_type value_type; 53 53 54 54 55 55 CullVisitor(); 56 56 57 57 /// Copy constructor that does a shallow copy. 58 58 CullVisitor(const CullVisitor&); … … 65 65 /** get the prototype singleton used by CullVisitor::create().*/ 66 66 static osg::ref_ptr<CullVisitor>& prototype(); 67 67 68 68 /** create a CullVisitor by cloning CullVisitor::prototype().*/ 69 69 static CullVisitor* create(); … … 131 131 } 132 132 } 133 133 134 134 /** Pop the top state set and hence associated state group. 135 135 * Move the current state group to the parent of the popped … … 157 157 _currentStateGraph = _currentStateGraph->_parent; 158 158 } 159 159 160 160 inline void setStateGraph(StateGraph* rg) 161 161 { … … 207 207 void setCalculatedNearPlane(value_type value) { _computed_znear = value; } 208 208 inline value_type getCalculatedNearPlane() const { return _computed_znear; } 209 209 210 210 void setCalculatedFarPlane(value_type value) { _computed_zfar = value; } 211 211 inline value_type getCalculatedFarPlane() const { return _computed_zfar; } … … 217 217 218 218 bool updateCalculatedNearFar(const osg::Matrix& matrix,const osg::Drawable& drawable, bool isBillboard=false); 219 219 220 220 void updateCalculatedNearFar(const osg::Vec3& pos); 221 221 222 222 /** Add a drawable to current render graph.*/ 223 223 inline void addDrawable(osg::Drawable* drawable,osg::RefMatrix* matrix); … … 234 234 235 235 /** compute near plane based on the polgon intersection of primtives in near plane candidate list of drawables. 236 * Note, you have to set ComputeNearFarMode to COMPUTE_NEAR_FAR_USING_PRIMITIVES to be able to near plane candidate drawables to be recorded by the cull traversal. */ 236 * Note, you have to set ComputeNearFarMode to COMPUTE_NEAR_FAR_USING_PRIMITIVES to be able to near plane candidate drawables to be recorded by the cull traversal. */ 237 237 void computeNearPlane(); 238 238 … … 240 240 * the computed near and far.*/ 241 241 virtual void popProjectionMatrix(); 242 242 243 243 244 244 /** CullVisitor's default clamping of the projection float matrix to computed near and far values. … … 266 266 return true; 267 267 } 268 else 268 else 269 269 return false; 270 270 } … … 287 287 return true; 288 288 } 289 else 289 else 290 290 return false; 291 291 } 292 292 293 293 294 294 void setState(osg::State* state) { _renderInfo.setState(state); } … … 306 306 /** Prevent unwanted copy operator.*/ 307 307 CullVisitor& operator = (const CullVisitor&) { return *this; } 308 308 309 309 inline void handle_cull_callbacks_and_traverse(osg::Node& node) 310 310 { … … 324 324 StateGraph* _currentStateGraph; 325 325 326 osg::ref_ptr<RenderStage> _rootRenderStage; 326 osg::ref_ptr<RenderStage> _rootRenderStage; 327 327 RenderBin* _currentRenderBin; 328 328 std::vector<RenderBin*> _renderBinStack; … … 332 332 value_type _computed_znear; 333 333 value_type _computed_zfar; 334 335 334 335 336 336 typedef std::vector< osg::ref_ptr<RenderLeaf> > RenderLeafList; 337 337 RenderLeafList _reuseRenderLeafList; 338 338 unsigned int _currentReuseRenderLeafIndex; 339 339 340 340 inline RenderLeaf* createOrReuseRenderLeaf(osg::Drawable* drawable,osg::RefMatrix* projection,osg::RefMatrix* matrix, float depth=0.0f); 341 341 342 342 unsigned int _numberOfEncloseOverrideRenderBinDetails; 343 343 … … 351 351 { 352 352 } 353 353 354 354 void set(const osg::Matrix& matrix, const osg::Drawable* drawable, const osg::Polytope& frustum) 355 355 { … … 357 357 _drawable = drawable; 358 358 if (!_planes.empty()) _planes.clear(); 359 359 360 360 // create a new list of planes from the active walls of the frustum. 361 361 osg::Polytope::ClippingMask result_mask = frustum.getResultMask(); … … 366 366 { 367 367 if (result_mask&selector_mask) _planes.push_back(*itr); 368 selector_mask <<= 1; 368 selector_mask <<= 1; 369 369 } 370 370 } 371 371 372 372 MatrixPlanesDrawables(const MatrixPlanesDrawables& mpd): 373 373 _matrix(mpd._matrix), 374 374 _drawable(mpd._drawable), 375 375 _planes(mpd._planes) {} 376 376 377 377 MatrixPlanesDrawables& operator = (const MatrixPlanesDrawables& mpd) 378 378 { … … 382 382 return *this; 383 383 } 384 384 385 385 osg::Matrix _matrix; 386 386 const osg::Drawable* _drawable; 387 387 osg::Polytope::PlaneList _planes; 388 388 }; 389 389 390 390 typedef std::multimap<value_type, MatrixPlanesDrawables> DistanceMatrixDrawableMap; 391 391 DistanceMatrixDrawableMap _nearPlaneCandidateMap; … … 437 437 { 438 438 // Skips any already reused renderleaf. 439 while (_currentReuseRenderLeafIndex<_reuseRenderLeafList.size() && 439 while (_currentReuseRenderLeafIndex<_reuseRenderLeafList.size() && 440 440 _reuseRenderLeafList[_currentReuseRenderLeafIndex]->referenceCount()>1) 441 441 {
