osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 00020 #ifndef OSGEARTH_ENGINE_OSGTERRAIN_SINGLE_PASS_TERRAIN_TECHNIQUE 00021 #define OSGEARTH_ENGINE_OSGTERRAIN_SINGLE_PASS_TERRAIN_TECHNIQUE 1 00022 00023 #include "CustomTerrainTechnique" 00024 #include "TransparentLayer" 00025 00026 #include <osg/MatrixTransform> 00027 #include <osg/Geode> 00028 #include <osg/Geometry> 00029 #include <osg/StateSet> 00030 #include <osg/Texture2DArray> 00031 #include <osg/Version> 00032 #include <osg/Uniform> 00033 00034 #include <osgTerrain/Locator> 00035 #include <osgEarth/Export> 00036 #include <osgEarth/Progress> 00037 #include <osgEarth/TextureCompositor> 00038 #include <osgEarth/ThreadingUtils> 00039 #include <osgEarthSymbology/Geometry> 00040 00041 #include <queue> 00042 00043 class Tile; 00044 class TileFrame; 00045 00046 // -------------------------------------------------------------------------- 00047 00063 class SinglePassTerrainTechnique : public CustomTerrainTechnique 00064 { 00065 public: 00066 SinglePassTerrainTechnique( TextureCompositor* compositor =0L ); //osgTerrain::Locator* locator =0L ); 00067 00068 SinglePassTerrainTechnique(const SinglePassTerrainTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 00069 00070 META_Object( osgEarth, SinglePassTerrainTechnique ); 00071 00072 public: /* overrides */ 00073 00074 virtual void init(); 00075 00076 #if 0 00077 #if OSG_MIN_VERSION_REQUIRED(2,9,8) 00078 virtual void init(int dirtyMask, bool assumeMultiThreaded); 00079 #else 00080 virtual void init(); 00081 #endif 00082 #endif 00083 00084 void setParentTile( Tile* tile ) { _parentTile = tile; } 00085 00086 void compile( const TileUpdate& updateSpec, ProgressCallback* progress ); 00087 00088 // returns TRUE if a swap occurred and a new subgraph is now in place. 00089 bool applyTileUpdates(); 00090 00092 virtual void traverse( osg::NodeVisitor& nv ); 00093 00094 public: 00095 00101 void setVerticalScaleOverride( float value ); 00102 00106 float getVerticalScaleOverride() const; 00107 00112 void setOptimizeTriangleOrientation(bool optimizeTriangleOrientation); 00113 bool getOptimizeTriangleOrientation() const; 00114 00118 virtual void releaseGLObjects(osg::State* = 0) const; 00119 00120 osg::StateSet* getActiveStateSet() const; 00121 00122 00123 protected: 00124 00125 void calculateSampling( unsigned int& out_rows, unsigned int& out_cols, double& out_i, double& out_j ); 00126 00127 private: 00128 00129 virtual ~SinglePassTerrainTechnique(); 00130 bool _debug; 00131 00132 OpenThreads::Mutex _compileMutex; 00133 //OpenThreads::Mutex _writeBufferMutex; 00134 osg::ref_ptr<osg::MatrixTransform> _transform; 00135 osg::ref_ptr<osg::Geode> _backGeode; 00136 osg::ref_ptr<osg::Uniform> _imageLayerStampUniform; 00137 osg::Vec3d _centerModel; 00138 float _verticalScaleOverride; 00139 osg::ref_ptr<GeoLocator> _masterLocator; 00140 00141 int _initCount; 00142 bool _pendingFullUpdate; 00143 bool _pendingGeometryUpdate; 00144 00145 struct ImageLayerUpdate { 00146 GeoImage _image; 00147 UID _layerUID; 00148 bool _isRealData; // versus fallback data 00149 }; 00150 typedef std::queue<ImageLayerUpdate> ImageLayerUpdates; 00151 ImageLayerUpdates _pendingImageLayerUpdates; 00152 00153 // associates each texture index with a layer UID. 00154 typedef std::map< UID, int > LayerUIDtoIndexMap; 00155 LayerUIDtoIndexMap _layerUIDtoIndexMap; 00156 00157 // XXX Are these both necessary? 00158 GeoExtent _tileExtent; 00159 TileKey _tileKey; 00160 00161 bool _optimizeTriangleOrientation; 00162 00163 osg::ref_ptr<const TextureCompositor> _texCompositor; 00164 bool _frontGeodeInstalled; 00165 00166 private: 00167 00168 osg::Vec3d computeCenterModel(); 00169 bool createGeoImage( const CustomColorLayer& layer, GeoImage& image ) const; //const osgTerrain::Layer* imageLayer ) const; 00170 osg::Geode* createGeometry( const TileFrame& tilef ); 00171 osg::StateSet* createStateSet( const TileFrame& tilef ); 00172 void prepareImageLayerUpdate( int layerIndex, const TileFrame& tilef ); 00173 //Threading::ReadWriteMutex& getMutex(); 00174 inline osg::Geode* getFrontGeode() const { 00175 if (_transform.valid() && _transform->getNumChildren() > 0) 00176 return static_cast<osg::Geode*>( _transform->getChild(0) ); 00177 return NULL; 00178 } 00179 osg::StateSet* getParentStateSet() const; 00180 //const CustomColorLayer* getLayerByUID( UID uid ) const; 00181 int getIndexOfColorLayerWithUID( UID uid ) const; 00182 00183 00184 osg::observer_ptr<Tile> _parentTile; 00185 }; 00186 00187 #endif // OSGEARTH_ENGINE_OSGTERRAIN_SINGLE_PASS_TERRAIN_TECHNIQUE