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_DROAM_ENGINE_AMR_GEOMETRY_H 00020 #define OSGEARTH_DROAM_ENGINE_AMR_GEOMETRY_H 1 00021 00022 #include <osgEarth/Revisioning> 00023 #include <osg/Geometry> 00024 #include <osg/StateSet> 00025 #include <osg/Program> 00026 00027 class MeshNode 00028 { 00029 public: 00030 osg::Vec3d _manifoldCoord; // source coordinate (in manifold srs) 00031 osg::Vec3d _geodeticCoord; // source coordinate (in lon/lat/alt) 00032 osg::Vec3f _vertex; // world space vertex 00033 osg::Vec3f _normal; // world space normal 00034 00035 osg::Quat _geodeticRot; // geodetic rotation (lat/long rotation matrix as quat) 00036 }; 00037 00038 class AMRTriangle : public osg::Referenced 00039 { 00040 public: 00041 AMRTriangle(); 00042 00043 AMRTriangle( 00044 const MeshNode& node0, const osg::Vec2& t0, 00045 const MeshNode& node1, const osg::Vec2& t1, 00046 const MeshNode& node2, const osg::Vec2& t2 ); 00047 00048 void expand( osg::BoundingBox& box ); 00049 00050 public: 00051 osg::ref_ptr<osg::StateSet> _stateSet; 00052 MeshNode _node0, _node1, _node2; 00053 }; 00054 00055 typedef std::vector< osg::ref_ptr<AMRTriangle> > AMRTriangleList; 00056 00057 00058 class AMRDrawable : public osg::Referenced 00059 { 00060 public: 00061 AMRDrawable(); 00062 void add( AMRTriangle* triangle ) { _triangles.push_back( triangle ); } 00063 00064 osg::ref_ptr<osg::StateSet> _stateSet; 00065 AMRTriangleList _triangles; 00066 }; 00067 00068 typedef std::vector< osg::ref_ptr<AMRDrawable> > AMRDrawableList; 00069 00070 00078 class AMRGeometry : public osg::Drawable //osg::Geometry 00079 { 00080 public: 00081 AMRGeometry(); 00082 AMRGeometry( const AMRGeometry& rhs, const osg::CopyOp& op =osg::CopyOp::DEEP_COPY_ALL ); 00083 META_Object( osgEarth, AMRGeometry ); 00084 00085 virtual osg::BoundingBox computeBound() const; 00086 00087 public: 00089 void clearDrawList(); 00090 00092 void setDrawList( const AMRDrawableList& drawList ); 00093 00094 protected: 00096 virtual void drawImplementation( osg::RenderInfo& renderInfo ) const; 00097 00098 private: 00099 // list of manifold tris to render 00100 AMRDrawableList _drawList; 00101 00102 // the adaptive refinement pattern that is permanently stores in the VBO. 00103 // in the future we may support more than one pattern (for LOD matching, e.g.) 00104 typedef std::vector< osg::ref_ptr<osg::DrawElements> > Pattern; 00105 Pattern _pattern; 00106 int _numPatternVerts; 00107 int _numPatternElements; 00108 int _numPatternStrips; 00109 int _numPatternTriangles; 00110 00111 osg::ref_ptr<osg::Vec3Array> _verts; 00112 osg::ref_ptr<osg::Vec2Array> _texCoords; 00113 osg::ref_ptr<osg::VertexBufferObject> _patternVBO; 00114 osg::ref_ptr<osg::ElementBufferObject> _patternEBO; 00115 00116 public: // temp 00117 // shader program that draws the virtual geometry 00118 osg::ref_ptr<osg::Program> _program; 00119 00120 private: 00121 00122 void initShaders(); 00123 void initPatterns(); 00124 }; 00125 00126 #endif // OSGEARTH_DROAM_ENGINE_AMR_GEOMETRY_H