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 #ifndef OSGEARTH_MAP_ENGINE_NODE_H 00020 #define OSGEARTH_MAP_ENGINE_NODE_H 1 00021 00022 #include <osgEarth/Map> 00023 #include <osgEarth/ShaderUtils> 00024 #include <osg/CoordinateSystemNode> 00025 #include <osg/Geode> 00026 #include <osg/NodeCallback> 00027 00028 namespace osgEarth 00029 { 00030 class TextureCompositor; 00031 00038 class OSGEARTH_EXPORT TerrainEngineNode : public osg::CoordinateSystemNode 00039 { 00040 public: 00042 const Map* getMap() const { return _map.get(); } 00043 00045 virtual const TerrainOptions& getTerrainOptions() const =0; 00046 00048 TextureCompositor* getTextureCompositor() const { return _texCompositor.get(); } 00049 00050 public: // Runtime properties 00051 00053 void setVerticalScale( float value ); 00054 00056 float getVerticalScale() const { return _verticalScale; } 00057 00059 void setElevationSamplingRatio( float value ); 00060 00062 float getElevationSamplingRatio() const { return _elevationSamplingRatio; } 00063 00064 protected: 00065 TerrainEngineNode(); 00066 00067 TerrainEngineNode( const TerrainEngineNode& rhs, const osg::CopyOp& op =osg::CopyOp::DEEP_COPY_ALL ); 00068 00069 virtual ~TerrainEngineNode(); 00070 00071 public: // osg::Node overrides 00072 virtual osg::BoundingSphere computeBound() const; 00073 virtual void traverse( osg::NodeVisitor& ); 00074 00075 protected: // implementation events 00076 virtual void onVerticalScaleChanged() { } 00077 virtual void onElevationSamplingRatioChanged() { } 00078 00079 protected: 00080 friend class TerrainEngineNodeFactory; 00081 00082 virtual void validateTerrainOptions( TerrainOptions& options ); 00083 00084 private: 00085 friend struct TerrainEngineNodeCallbackProxy; 00086 00087 void onMapInfoEstablished( const MapInfo& mapInfo ); // not virtual! 00088 //void onMapProfileEstablished( const Profile* profile ); 00089 void onMapModelChanged( const MapModelChange& change ); 00090 00091 protected: 00093 virtual void preInitialize( const Map* map, const TerrainOptions& options ); 00094 virtual void postInitialize( const Map* map, const TerrainOptions& options ); 00095 friend class MapNode; 00096 00097 // allow subclasses direct access for convenience. 00098 osg::ref_ptr<TextureCompositor> _texCompositor; 00099 00100 private: 00101 friend struct MapNodeMapLayerController; 00102 00103 virtual void updateImageUniforms(); 00104 00105 private: 00106 UpdateLightingUniformsHelper _updateLightingUniformsHelper; 00107 float _verticalScale; 00108 float _elevationSamplingRatio; 00109 00110 struct ImageLayerController : public ImageLayerCallback 00111 { 00112 ImageLayerController( const Map* map ); 00113 00114 void onEnabledChanged( TerrainLayer* layer ); 00115 void onOpacityChanged( ImageLayer* layer ); 00116 00117 ArrayUniform _layerOpacityUniform; 00118 ArrayUniform _layerEnabledUniform; 00119 ArrayUniform _layerRangeUniform; 00120 00122 //osg::ref_ptr< ArrayUniform > _layerOpacityUniform; 00124 00126 //osg::ref_ptr< ArrayUniform > _layerEnabledUniform; 00128 00130 //osg::ref_ptr< ArrayUniform > _layerRangeUniform; 00132 00133 private: 00134 MapFrame _mapf; 00135 }; 00136 00137 osg::ref_ptr<ImageLayerController> _imageLayerController; 00138 osg::ref_ptr<const Map> _map; 00139 osg::ref_ptr<osg::Uniform> _startFrameTimeUniform; 00140 osg::ref_ptr<osg::Uniform> _cameraElevationUniform; 00141 00142 enum InitStage { 00143 INIT_NONE, 00144 INIT_PREINIT_COMPLETE, 00145 INIT_POSTINIT_COMPLETE 00146 }; 00147 InitStage _initStage; 00148 }; 00149 00153 class TerrainEngineNodeFactory 00154 { 00155 public: 00156 static TerrainEngineNode* create( Map* map, const TerrainOptions& options ); 00157 }; 00158 00162 class TerrainDecorator : public osg::Group 00163 { 00164 public: 00165 virtual void onInstall( TerrainEngineNode* engine ) { } 00166 virtual void onUninstall( TerrainEngineNode* engine ) { } 00167 }; 00168 00169 } // namespace osgEarth 00170 00171 #endif // OSGEARTH_ENGINE_OSGTERRAIN_ENGINE_NODE_H