| 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(); |
|---|
| 38 | |
|---|
| 39 | virtual Locator* computeMasterLocator(); |
|---|
| 40 | |
|---|
| 41 | virtual osg::Vec3d computeCenterModel(Locator* masterLocator); |
|---|
| 42 | |
|---|
| 43 | virtual void generateGeometry(Locator* masterLocator, const osg::Vec3d& centerModel); |
|---|
| 44 | |
|---|
| 45 | virtual void applyColorLayers(); |
|---|
| 46 | |
|---|
| 47 | virtual void applyTransparency(); |
|---|
| 48 | |
|---|
| 49 | virtual void smoothGeometry(); |
|---|
| 50 | |
|---|
| 51 | virtual void update(osgUtil::UpdateVisitor* nv); |
|---|
| 52 | |
|---|
| 53 | virtual void cull(osgUtil::CullVisitor* nv); |
|---|
| 54 | |
|---|
| 55 | /** Traverse the terain subgraph.*/ |
|---|
| 56 | virtual void traverse(osg::NodeVisitor& nv); |
|---|
| 57 | |
|---|
| 58 | virtual void cleanSceneGraph(); |
|---|
| 59 | |
|---|
| 60 | void setFilterBias(float filterBias); |
|---|
| 61 | float getFilterBias() const { return _filterBias; } |
|---|
| 62 | |
|---|
| 63 | void setFilterWidth(float filterWidth); |
|---|
| 64 | float getFilterWidth() const { return _filterWidth; } |
|---|
| 65 | |
|---|
| 66 | void setFilterMatrix(const osg::Matrix3& matrix); |
|---|
| 67 | osg::Matrix3& getFilterMatrix() { return _filterMatrix; } |
|---|
| 68 | const osg::Matrix3& getFilterMatrix() const { return _filterMatrix; } |
|---|
| 69 | |
|---|
| 70 | enum FilterType |
|---|
| 71 | { |
|---|
| 72 | GAUSSIAN, |
|---|
| 73 | SMOOTH, |
|---|
| 74 | SHARPEN |
|---|
| 75 | }; |
|---|
| 76 | |
|---|
| 77 | void setFilterMatrixAs(FilterType filterType); |
|---|
| 78 | |
|---|
| 79 | /** If State is non-zero, this function releases any associated OpenGL objects for |
|---|
| 80 | * the specified graphics context. Otherwise, releases OpenGL objects |
|---|
| 81 | * for all graphics contexts. */ |
|---|
| 82 | virtual void releaseGLObjects(osg::State* = 0) const; |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | protected: |
|---|
| 86 | |
|---|
| 87 | virtual ~GeometryTechnique(); |
|---|
| 88 | |
|---|
| 89 | struct BufferData |
|---|
| 90 | { |
|---|
| 91 | osg::ref_ptr<osg::MatrixTransform> _transform; |
|---|
| 92 | osg::ref_ptr<osg::Geode> _geode; |
|---|
| 93 | osg::ref_ptr<osg::Geometry> _geometry; |
|---|
| 94 | }; |
|---|
| 95 | |
|---|
| 96 | unsigned int _currentReadOnlyBuffer; |
|---|
| 97 | unsigned int _currentWriteBuffer; |
|---|
| 98 | |
|---|
| 99 | BufferData _bufferData[2]; |
|---|
| 100 | |
|---|
| 101 | void swapBuffers(); |
|---|
| 102 | |
|---|
| 103 | inline BufferData& getReadOnlyBuffer() { return _bufferData[_currentReadOnlyBuffer]; } |
|---|
| 104 | inline BufferData& getWriteBuffer() { return _bufferData[_currentWriteBuffer]; } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | float _filterBias; |
|---|
| 108 | osg::ref_ptr<osg::Uniform> _filterBiasUniform; |
|---|
| 109 | float _filterWidth; |
|---|
| 110 | osg::ref_ptr<osg::Uniform> _filterWidthUniform; |
|---|
| 111 | osg::Matrix3 _filterMatrix; |
|---|
| 112 | osg::ref_ptr<osg::Uniform> _filterMatrixUniform; |
|---|
| 113 | }; |
|---|
| 114 | |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | #endif |
|---|