| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 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 |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSGTERRAIN_GEOMETRYTECHNIQUE |
|---|
| 15 | #define OSGTERRAIN_GEOMETRYTECHNIQUE 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/MatrixTransform> |
|---|
| 18 | #include <osg/Geode> |
|---|
| 19 | #include <osg/Geometry> |
|---|
| 20 | |
|---|
| 21 | #include <osgTerrain/TerrainTechnique> |
|---|
| 22 | #include <osgTerrain/Locator> |
|---|
| 23 | |
|---|
| 24 | namespace osgTerrain { |
|---|
| 25 | |
|---|
| 26 | class OSGTERRAIN_EXPORT GeometryTechnique : public TerrainTechnique |
|---|
| 27 | { |
|---|
| 28 | public: |
|---|
| 29 | |
|---|
| 30 | GeometryTechnique(); |
|---|
| 31 | |
|---|
| 32 | /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ |
|---|
| 33 | GeometryTechnique(const GeometryTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); |
|---|
| 34 | |
|---|
| 35 | META_Object(osgTerrain, GeometryTechnique); |
|---|
| 36 | |
|---|
| 37 | virtual void init(int dirtyMask, bool assumeMultiThreaded); |
|---|
| 38 | |
|---|
| 39 | virtual Locator* computeMasterLocator(); |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | virtual void update(osgUtil::UpdateVisitor* nv); |
|---|
| 43 | |
|---|
| 44 | virtual void cull(osgUtil::CullVisitor* nv); |
|---|
| 45 | |
|---|
| 46 | /** Traverse the terain subgraph.*/ |
|---|
| 47 | virtual void traverse(osg::NodeVisitor& nv); |
|---|
| 48 | |
|---|
| 49 | virtual void cleanSceneGraph(); |
|---|
| 50 | |
|---|
| 51 | void setFilterBias(float filterBias); |
|---|
| 52 | float getFilterBias() const { return _filterBias; } |
|---|
| 53 | |
|---|
| 54 | void setFilterWidth(float filterWidth); |
|---|
| 55 | float getFilterWidth() const { return _filterWidth; } |
|---|
| 56 | |
|---|
| 57 | void setFilterMatrix(const osg::Matrix3& matrix); |
|---|
| 58 | osg::Matrix3& getFilterMatrix() { return _filterMatrix; } |
|---|
| 59 | const osg::Matrix3& getFilterMatrix() const { return _filterMatrix; } |
|---|
| 60 | |
|---|
| 61 | enum FilterType |
|---|
| 62 | { |
|---|
| 63 | GAUSSIAN, |
|---|
| 64 | SMOOTH, |
|---|
| 65 | SHARPEN |
|---|
| 66 | }; |
|---|
| 67 | |
|---|
| 68 | void setFilterMatrixAs(FilterType filterType); |
|---|
| 69 | |
|---|
| 70 | /** If State is non-zero, this function releases any associated OpenGL objects for |
|---|
| 71 | * the specified graphics context. Otherwise, releases OpenGL objects |
|---|
| 72 | * for all graphics contexts. */ |
|---|
| 73 | virtual void releaseGLObjects(osg::State* = 0) const; |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | protected: |
|---|
| 77 | |
|---|
| 78 | virtual ~GeometryTechnique(); |
|---|
| 79 | |
|---|
| 80 | class BufferData : public osg::Referenced |
|---|
| 81 | { |
|---|
| 82 | public: |
|---|
| 83 | BufferData() {} |
|---|
| 84 | |
|---|
| 85 | osg::ref_ptr<osg::MatrixTransform> _transform; |
|---|
| 86 | osg::ref_ptr<osg::Geode> _geode; |
|---|
| 87 | osg::ref_ptr<osg::Geometry> _geometry; |
|---|
| 88 | |
|---|
| 89 | protected: |
|---|
| 90 | ~BufferData() {} |
|---|
| 91 | }; |
|---|
| 92 | |
|---|
| 93 | virtual osg::Vec3d computeCenterModel(BufferData& buffer, Locator* masterLocator); |
|---|
| 94 | |
|---|
| 95 | virtual void generateGeometry(BufferData& buffer, Locator* masterLocator, const osg::Vec3d& centerModel); |
|---|
| 96 | |
|---|
| 97 | virtual void applyColorLayers(BufferData& buffer); |
|---|
| 98 | |
|---|
| 99 | virtual void applyTransparency(BufferData& buffer); |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | OpenThreads::Mutex _writeBufferMutex; |
|---|
| 103 | osg::ref_ptr<BufferData> _currentBufferData; |
|---|
| 104 | osg::ref_ptr<BufferData> _newBufferData; |
|---|
| 105 | |
|---|
| 106 | float _filterBias; |
|---|
| 107 | osg::ref_ptr<osg::Uniform> _filterBiasUniform; |
|---|
| 108 | float _filterWidth; |
|---|
| 109 | osg::ref_ptr<osg::Uniform> _filterWidthUniform; |
|---|
| 110 | osg::Matrix3 _filterMatrix; |
|---|
| 111 | osg::ref_ptr<osg::Uniform> _filterMatrixUniform; |
|---|
| 112 | }; |
|---|
| 113 | |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | #endif |
|---|