1 /* -*-c++-*- */ 2 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 3 * Copyright 2008-2013 Pelican Mapping 4 * http://osgearth.org 5 * 6 * osgEarth is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/> 18 */ 19 #include "TerrainNode" 20 #include "QuickReleaseGLObjects" 21 22 #include <osgEarth/Registry> 23 #include <osgEarth/Map> 24 #include <osgEarth/NodeUtils> 25 #include <osgEarth/ThreadingUtils> 26 27 #include <osg/NodeCallback> 28 #include <osg/NodeVisitor> 29 #include <osg/Node> 30 #include <osgGA/EventVisitor> 31 32 using namespace osgEarth_engine_quadtree; 33 using namespace osgEarth; 34 using namespace OpenThreads; 35 36 #define LC "[TerrainNode] " 37 38 //---------------------------------------------------------------------------- 39 TerrainNode(TileNodeRegistry * removedTiles)40TerrainNode::TerrainNode(TileNodeRegistry* removedTiles ) : 41 _tilesToQuickRelease ( removedTiles ), 42 _quickReleaseCallbackInstalled ( false ) 43 { 44 // tick the update count to install the quick release callback: 45 if ( _tilesToQuickRelease.valid() ) 46 { 47 ADJUST_UPDATE_TRAV_COUNT( this, 1 ); 48 } 49 } 50 51 52 void traverse(osg::NodeVisitor & nv)53TerrainNode::traverse( osg::NodeVisitor &nv ) 54 { 55 if ( nv.getVisitorType() == nv.UPDATE_VISITOR ) 56 { 57 // if the terrain engine requested "quick release", install the quick release 58 // draw callback now. 59 if ( !_quickReleaseCallbackInstalled && _tilesToQuickRelease.valid() ) 60 { 61 osg::Camera* cam = findFirstParentOfType<osg::Camera>( this ); 62 if ( cam ) 63 { 64 cam->setPostDrawCallback( new QuickReleaseGLObjects( 65 _tilesToQuickRelease.get(), 66 cam->getPostDrawCallback() ) ); 67 68 _quickReleaseCallbackInstalled = true; 69 OE_INFO << LC << "Quick release enabled" << std::endl; 70 71 // knock down the trav count set in the constructor. 72 ADJUST_UPDATE_TRAV_COUNT( this, -1 ); 73 } 74 } 75 } 76 77 osg::Group::traverse( nv ); 78 } 79