/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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 OSGVOLUME_MULTIPASSTECHNIQUE #define OSGVOLUME_MULTIPASSTECHNIQUE 1 #include #include namespace osgVolume { class OSGVOLUME_EXPORT MultipassTechnique : public VolumeTechnique { public: MultipassTechnique(); MultipassTechnique(const MultipassTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); META_Object(osgVolume, MultipassTechnique); virtual void init(); virtual void update(osgUtil::UpdateVisitor* nv); virtual void backfaceSubgraphCullTraversal(osgUtil::CullVisitor* cv); virtual void cull(osgUtil::CullVisitor* cv); /** Clean scene graph from any terrain technique specific nodes.*/ virtual void cleanSceneGraph(); /** Traverse the terrain subgraph.*/ virtual void traverse(osg::NodeVisitor& nv); enum RenderingMode { CUBE, HULL, CUBE_AND_HULL }; RenderingMode computeRenderingMode(); /** Container for render to texture objects used when doing multi-pass volume rendering techniques.*/ struct OSGVOLUME_EXPORT MultipassTileData : public TileData { MultipassTileData(osgUtil::CullVisitor* cv, MultipassTechnique* mpt); virtual void update(osgUtil::CullVisitor* cv); void setUp(osg::ref_ptr& camera, osg::ref_ptr& texture2D, int width, int height); osg::observer_ptr multipassTechnique; RenderingMode currentRenderingMode; osg::ref_ptr frontFaceDepthTexture; osg::ref_ptr frontFaceRttCamera; osg::ref_ptr backFaceDepthTexture; osg::ref_ptr backFaceRttCamera; osg::ref_ptr eyeToTileUniform; osg::ref_ptr tileToImageUniform; }; /** Called from VolumeScene to create the TileData container when a multi-pass technique is being used. * The TileData container caches any render to texture objects that are required. */ virtual TileData* createTileData(osgUtil::CullVisitor* cv) { return new MultipassTileData(cv, this); } protected: virtual ~MultipassTechnique(); osg::ref_ptr _transform; typedef std::map ModelViewMatrixMap; OpenThreads::Mutex _mutex; ModelViewMatrixMap _modelViewMatrixMap; osg::ref_ptr _whenMovingStateSet; osg::ref_ptr _volumeRenderStateSet; osg::StateSet* createStateSet(osg::StateSet* statesetPrototype, osg::Program* programPrototype, osg::Shader* shaderToAdd1=0, osg::Shader* shaderToAdd2=0); enum ShaderMask { CUBE_SHADERS = 1, HULL_SHADERS = 2, CUBE_AND_HULL_SHADERS = 4, STANDARD_SHADERS = 8, LIT_SHADERS = 16, ISO_SHADERS = 32, MIP_SHADERS = 64, TF_SHADERS = 128 }; typedef std::map > StateSetMap; StateSetMap _stateSetMap; osg::ref_ptr _frontFaceStateSet; }; } #endif