GeometryTechnique 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #ifndef OSGTERRAIN_GEOMETRYTECHNIQUE
  14. #define OSGTERRAIN_GEOMETRYTECHNIQUE 1
  15. #include <osg/MatrixTransform>
  16. #include <osg/Geode>
  17. #include <osg/Geometry>
  18. #include <osgTerrain/TerrainTechnique>
  19. #include <osgTerrain/Locator>
  20. namespace osgTerrain {
  21. class OSGTERRAIN_EXPORT GeometryTechnique : public TerrainTechnique
  22. {
  23. public:
  24. GeometryTechnique();
  25. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  26. GeometryTechnique(const GeometryTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  27. META_Object(osgTerrain, GeometryTechnique);
  28. virtual void init(int dirtyMask, bool assumeMultiThreaded);
  29. virtual Locator* computeMasterLocator();
  30. virtual void update(osgUtil::UpdateVisitor* nv);
  31. virtual void cull(osgUtil::CullVisitor* nv);
  32. /** Traverse the terain subgraph.*/
  33. virtual void traverse(osg::NodeVisitor& nv);
  34. virtual void cleanSceneGraph();
  35. void setFilterBias(float filterBias);
  36. float getFilterBias() const { return _filterBias; }
  37. void setFilterWidth(float filterWidth);
  38. float getFilterWidth() const { return _filterWidth; }
  39. void setFilterMatrix(const osg::Matrix3& matrix);
  40. osg::Matrix3& getFilterMatrix() { return _filterMatrix; }
  41. const osg::Matrix3& getFilterMatrix() const { return _filterMatrix; }
  42. enum FilterType
  43. {
  44. GAUSSIAN,
  45. SMOOTH,
  46. SHARPEN
  47. };
  48. void setFilterMatrixAs(FilterType filterType);
  49. /** If State is non-zero, this function releases any associated OpenGL objects for
  50. * the specified graphics context. Otherwise, releases OpenGL objects
  51. * for all graphics contexts. */
  52. virtual void releaseGLObjects(osg::State* = 0) const;
  53. protected:
  54. virtual ~GeometryTechnique();
  55. class BufferData : public osg::Referenced
  56. {
  57. public:
  58. BufferData() {}
  59. osg::ref_ptr<osg::MatrixTransform> _transform;
  60. osg::ref_ptr<osg::Geode> _geode;
  61. osg::ref_ptr<osg::Geometry> _geometry;
  62. protected:
  63. ~BufferData() {}
  64. };
  65. virtual osg::Vec3d computeCenterModel(BufferData& buffer, Locator* masterLocator);
  66. virtual void generateGeometry(BufferData& buffer, Locator* masterLocator, const osg::Vec3d& centerModel);
  67. virtual void applyColorLayers(BufferData& buffer);
  68. virtual void applyTransparency(BufferData& buffer);
  69. OpenThreads::Mutex _writeBufferMutex;
  70. osg::ref_ptr<BufferData> _currentBufferData;
  71. osg::ref_ptr<BufferData> _newBufferData;
  72. float _filterBias;
  73. osg::ref_ptr<osg::Uniform> _filterBiasUniform;
  74. float _filterWidth;
  75. osg::ref_ptr<osg::Uniform> _filterWidthUniform;
  76. osg::Matrix3 _filterMatrix;
  77. osg::ref_ptr<osg::Uniform> _filterMatrixUniform;
  78. };
  79. }
  80. #endif