diff --git a/examples/osgterrain/CMakeLists.txt b/examples/osgterrain/CMakeLists.txt index 3e1422f13..a942afd07 100644 --- a/examples/osgterrain/CMakeLists.txt +++ b/examples/osgterrain/CMakeLists.txt @@ -1,9 +1,4 @@ -SET(TARGET_H - ShaderTerrain.h -) - SET(TARGET_SRC - ShaderTerrain.cpp osgterrain.cpp ) diff --git a/examples/osgterrain/ShaderTerrain.cpp b/examples/osgterrain/ShaderTerrain.cpp deleted file mode 100644 index 8211f9848..000000000 --- a/examples/osgterrain/ShaderTerrain.cpp +++ /dev/null @@ -1,145 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "ShaderTerrain.h" - -using namespace osgTerrain; - -#if 0 -#define LOCK(mutex) OpenThreads::ScopedLock lock(mutex); -#else -#define LOCK(mutex) /* OpenThreads::Thread::microSleep(1);*/ -#endif - - - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// ShaderTerrain -// -ShaderTerrain::ShaderTerrain() -{ - // OSG_NOTICE<<"ShaderTerrain::ShaderTerrain()"<1) - { - unsigned int val = _currentTraversalCount; - printf("Has a concurrent traversal %i\n",val); - //throw "have concurrent traversal happening"; - OpenThreads::Thread::YieldCurrentThread(); - } - else - { - printf("Single threaded traversal\n"); - } -#endif - - //OSG_NOTICE<<"ShaderTerrain::init("<getTileSubgraph(_terrainTile); - - // set tile as no longer dirty. - _terrainTile->setDirtyMask(0); - - --_currentTraversalCount; -} - -void ShaderTerrain::update(osgUtil::UpdateVisitor* uv) -{ - LOCK(_transformMutex); - - if (_terrainTile) _terrainTile->osg::Group::traverse(*uv); - - if (_transform.valid()) _transform->accept(*uv); -} - - -void ShaderTerrain::cull(osgUtil::CullVisitor* cv) -{ - LOCK(_transformMutex); - - if (_transform.valid()) _transform->accept(*cv); -} - - -void ShaderTerrain::traverse(osg::NodeVisitor& nv) -{ - if (!_terrainTile) return; - - // if app traversal update the frame count. - if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR) - { - // if (_terrainTile->getDirty()) _terrainTile->init(_terrainTile->getDirtyMask(), false); - - osgUtil::UpdateVisitor* uv = dynamic_cast(&nv); - if (uv) - { - update(uv); - return; - } - } - else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) - { - osgUtil::CullVisitor* cv = dynamic_cast(&nv); - if (cv) - { - cull(cv); - return; - } - } - - { - LOCK(_transformMutex); - if (_transform.valid()) - { - _transform->accept(nv); - } - } -} - - -void ShaderTerrain::cleanSceneGraph() -{ -} - -void ShaderTerrain::releaseGLObjects(osg::State* state) const -{ -// LOCK(_transformMutex); - if (_transform.valid()) - { -// OSG_NOTICE<<"ShaderTerrain::releaseGLObjects()"<releaseGLObjects(state); - } -} diff --git a/examples/osgterrain/ShaderTerrain.h b/examples/osgterrain/ShaderTerrain.h deleted file mode 100644 index fdf831ac2..000000000 --- a/examples/osgterrain/ShaderTerrain.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef OSGTERRAIN_SHADERTERRAIN -#define OSGTERRAIN_SHADERTERRAIN - -#include -#include -#include -#include -#include - -namespace osgTerrain -{ - -class ShaderTerrain : public osgTerrain::TerrainTechnique -{ - public: - - ShaderTerrain(); - - ShaderTerrain(const ShaderTerrain&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - - META_Object(osgTerrain, ShaderTerrain); - - virtual void init(int dirtyMask, bool assumeMultiThreaded); - virtual void update(osgUtil::UpdateVisitor* uv); - virtual void cull(osgUtil::CullVisitor* cv); - virtual void traverse(osg::NodeVisitor& nv); - virtual void cleanSceneGraph(); - virtual void releaseGLObjects(osg::State* state) const; - - protected: - - virtual ~ShaderTerrain(); - - osg::ref_ptr _geometryPool; - - mutable OpenThreads::Mutex _traversalMutex; - - mutable OpenThreads::Mutex _transformMutex; - osg::ref_ptr _transform; - - OpenThreads::Atomic _currentTraversalCount; - -}; - -} - -#endif diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index ca1db5935..625bc269e 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -33,9 +33,9 @@ #include #include #include +#include #include -#include "ShaderTerrain.h" #include @@ -238,8 +238,8 @@ int main(int argc, char** argv) else if (strBlendingPolicy == "ENABLE_BLENDING_WHEN_ALPHA_PRESENT") blendingPolicy = osgTerrain::TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT; } - bool useShaderTerrain = arguments.read("--shader") || arguments.read("-s"); - if (useShaderTerrain) + bool useDisplacementMappingTechnique = arguments.read("--dm"); + if (useDisplacementMappingTechnique) { osgDB::Registry::instance()->setReadFileCallback(new CleanTechniqueReadFileCallback()); } @@ -285,9 +285,9 @@ int main(int argc, char** argv) terrain->setVerticalScale(verticalScale); terrain->setBlendingPolicy(blendingPolicy); - if (useShaderTerrain) + if (useDisplacementMappingTechnique) { - terrain->setTerrainTechniquePrototype(new osgTerrain::ShaderTerrain()); + terrain->setTerrainTechniquePrototype(new osgTerrain::DisplacementMappingTechnique()); } diff --git a/include/osgTerrain/DisplacementMappingTechnique b/include/osgTerrain/DisplacementMappingTechnique new file mode 100644 index 000000000..c78f0e6b5 --- /dev/null +++ b/include/osgTerrain/DisplacementMappingTechnique @@ -0,0 +1,60 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGTERRAIN_DISPLACEMENTMAPPINGTECHNIQUE +#define OSGTERRAIN_DISPLACEMENTMAPPINGTECHNIQUE + +#include +#include +#include +#include +#include + +namespace osgTerrain +{ + +class DisplacementMappingTechnique : public osgTerrain::TerrainTechnique +{ + public: + + DisplacementMappingTechnique(); + + DisplacementMappingTechnique(const DisplacementMappingTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + META_Object(osgTerrain, DisplacementMappingTechnique); + + virtual void init(int dirtyMask, bool assumeMultiThreaded); + virtual void update(osgUtil::UpdateVisitor* uv); + virtual void cull(osgUtil::CullVisitor* cv); + virtual void traverse(osg::NodeVisitor& nv); + virtual void cleanSceneGraph(); + virtual void releaseGLObjects(osg::State* state) const; + + protected: + + virtual ~DisplacementMappingTechnique(); + + osg::ref_ptr _geometryPool; + + mutable OpenThreads::Mutex _traversalMutex; + + mutable OpenThreads::Mutex _transformMutex; + osg::ref_ptr _transform; + + OpenThreads::Atomic _currentTraversalCount; + +}; + +} + +#endif diff --git a/include/osgTerrain/GeometryPool b/include/osgTerrain/GeometryPool index 03b86b41c..ca740fa7c 100644 --- a/include/osgTerrain/GeometryPool +++ b/include/osgTerrain/GeometryPool @@ -1,4 +1,4 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or diff --git a/src/osgTerrain/CMakeLists.txt b/src/osgTerrain/CMakeLists.txt index f627e39d0..a0f12ff4f 100644 --- a/src/osgTerrain/CMakeLists.txt +++ b/src/osgTerrain/CMakeLists.txt @@ -7,6 +7,7 @@ ENDIF() SET(LIB_NAME osgTerrain) SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME}) SET(TARGET_H + ${HEADER_PATH}/DisplacementMappingTechnique ${HEADER_PATH}/Export ${HEADER_PATH}/Locator ${HEADER_PATH}/Layer @@ -21,6 +22,7 @@ SET(TARGET_H # FIXME: For OS X, need flag for Framework or dylib SET(TARGET_SRC + DisplacementMappingTechnique.cpp Layer.cpp Locator.cpp TerrainTile.cpp diff --git a/src/osgTerrain/DisplacementMappingTechnique.cpp b/src/osgTerrain/DisplacementMappingTechnique.cpp new file mode 100644 index 000000000..5ee0bd871 --- /dev/null +++ b/src/osgTerrain/DisplacementMappingTechnique.cpp @@ -0,0 +1,114 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include +#include +#include + + +using namespace osgTerrain; + +///////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// DisplacementMappingTechnique +// +DisplacementMappingTechnique::DisplacementMappingTechnique() +{ + // OSG_NOTICE<<"DisplacementMappingTechnique::DisplacementMappingTechnique()"<getTileSubgraph(_terrainTile); + + // set tile as no longer dirty. + _terrainTile->setDirtyMask(0); +} + +void DisplacementMappingTechnique::update(osgUtil::UpdateVisitor* uv) +{ + if (_terrainTile) _terrainTile->osg::Group::traverse(*uv); + + if (_transform.valid()) _transform->accept(*uv); +} + + +void DisplacementMappingTechnique::cull(osgUtil::CullVisitor* cv) +{ + if (_transform.valid()) _transform->accept(*cv); +} + + +void DisplacementMappingTechnique::traverse(osg::NodeVisitor& nv) +{ + if (!_terrainTile) return; + + // if app traversal update the frame count. + if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR) + { + // if (_terrainTile->getDirty()) _terrainTile->init(_terrainTile->getDirtyMask(), false); + + osgUtil::UpdateVisitor* uv = dynamic_cast(&nv); + if (uv) + { + update(uv); + return; + } + } + else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR) + { + osgUtil::CullVisitor* cv = dynamic_cast(&nv); + if (cv) + { + cull(cv); + return; + } + } + + { + if (_transform.valid()) + { + _transform->accept(nv); + } + } +} + + +void DisplacementMappingTechnique::cleanSceneGraph() +{ +} + +void DisplacementMappingTechnique::releaseGLObjects(osg::State* state) const +{ + if (_transform.valid()) + { +// OSG_NOTICE<<"DisplacementMappingTechnique::releaseGLObjects()"<releaseGLObjects(state); + } +} diff --git a/src/osgTerrain/GeometryPool.cpp b/src/osgTerrain/GeometryPool.cpp index 0e221257e..b4755df0e 100644 --- a/src/osgTerrain/GeometryPool.cpp +++ b/src/osgTerrain/GeometryPool.cpp @@ -1,4 +1,4 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or