From e41cd46da85d2e45822ccd51e070057122d97bad Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 14 May 2007 20:23:10 +0000 Subject: [PATCH] Set up new view dependent overlay technique control methods --- examples/osgsimulation/osgsimulation.cpp | 8 ++- include/osgSim/OverlayNode | 27 +++++++- src/osgSim/OverlayNode.cpp | 87 +++++++++++++++++++++--- 3 files changed, 110 insertions(+), 12 deletions(-) diff --git a/examples/osgsimulation/osgsimulation.cpp b/examples/osgsimulation/osgsimulation.cpp index 22e8fc7de..901dbe522 100644 --- a/examples/osgsimulation/osgsimulation.cpp +++ b/examples/osgsimulation/osgsimulation.cpp @@ -250,6 +250,12 @@ int main(int argc, char **argv) return 1; } } + + osgSim::OverlayNode::OverlayTechnique technique = osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; + while (arguments.read("--object")) technique = osgSim::OverlayNode::OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; + while (arguments.read("--ortho") || arguments.read("--orthographic")) technique = osgSim::OverlayNode::VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY; + while (arguments.read("--persp") || arguments.read("--perspective")) technique = osgSim::OverlayNode::VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY; + // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) @@ -287,7 +293,7 @@ int main(int argc, char **argv) if (insertOverlayNode) { - overlayNode = new osgSim::OverlayNode; + overlayNode = new osgSim::OverlayNode(technique); // insert the OverlayNode between the coordinate system node and its children. for(unsigned int i=0; igetNumChildren(); ++i) diff --git a/include/osgSim/OverlayNode b/include/osgSim/OverlayNode index 8c70e0008..124de3c6f 100644 --- a/include/osgSim/OverlayNode +++ b/include/osgSim/OverlayNode @@ -28,7 +28,15 @@ namespace osgSim { class OSGSIM_EXPORT OverlayNode : public osg::Group { public : - OverlayNode(); + + enum OverlayTechnique + { + OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY, + VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY, + VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY, + }; + + OverlayNode(OverlayTechnique technique=OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY); OverlayNode(const OverlayNode& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); @@ -36,6 +44,11 @@ class OSGSIM_EXPORT OverlayNode : public osg::Group virtual void traverse(osg::NodeVisitor& nv); + + void setOverlayTechnique(OverlayTechnique technique); + OverlayTechnique getOverlayTechnique() { return _overlayTechnique; } + + /** Set the overlay subgraph which will be rendered to texture.*/ void setOverlaySubgraph(osg::Node* node); @@ -60,7 +73,7 @@ class OSGSIM_EXPORT OverlayNode : public osg::Group void setOverlayClearColor(const osg::Vec4& color); /** Get the clear color to use when rendering the overlay subgraph.*/ - const osg::Vec4& getOverlayClearColor() const; + osg::Vec4 getOverlayClearColor() const; /** Set the TexEnv mode used to combine the overlay texture with the base color/texture of the OverlayNode's decorate subgraph.*/ void setTexEnvMode(GLenum mode); @@ -103,13 +116,23 @@ class OSGSIM_EXPORT OverlayNode : public osg::Group virtual ~OverlayNode() {} void init(); + void init_OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(); + void init_VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(); + void init_VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY(); + void traverse_OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(osg::NodeVisitor& nv); + void traverse_VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(osg::NodeVisitor& nv); + void traverse_VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY(osg::NodeVisitor& nv); + + void updateMainSubgraphStateSet(); typedef osg::buffered_value< int > TextureObjectValidList; mutable TextureObjectValidList _textureObjectValidList; + OverlayTechnique _overlayTechnique; + osg::ref_ptr _camera; // overlay subgraph is render to a texture diff --git a/src/osgSim/OverlayNode.cpp b/src/osgSim/OverlayNode.cpp index 01d649148..15f62b0ed 100644 --- a/src/osgSim/OverlayNode.cpp +++ b/src/osgSim/OverlayNode.cpp @@ -22,7 +22,8 @@ using namespace osgSim; using namespace osg; -OverlayNode::OverlayNode(): +OverlayNode::OverlayNode(OverlayTechnique technique): + _overlayTechnique(technique), _texEnvMode(GL_DECAL), _textureUnit(1), _textureSizeHint(1024), @@ -35,6 +36,7 @@ OverlayNode::OverlayNode(): OverlayNode::OverlayNode(const OverlayNode& copy, const osg::CopyOp& copyop): osg::Group(copy,copyop), + _overlayTechnique(copy._overlayTechnique), _overlaySubgraph(copy._overlaySubgraph), _texEnvMode(copy._texEnvMode), _textureUnit(copy._textureUnit), @@ -78,8 +80,34 @@ void OverlayNode::releaseGLObjects(osg::State* state) const if (_texture.valid()) _texture->releaseGLObjects(state); } +void OverlayNode::setOverlayTechnique(OverlayTechnique technique) +{ + if (_overlayTechnique==technique) return; + + _overlayTechnique = technique; + + init(); +} + void OverlayNode::init() { + switch(_overlayTechnique) + { + case(OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY): + init_OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(); + break; + case(VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY): + init_VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(); + break; + case(VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY): + init_VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY(); + break; + } +} + +void OverlayNode::init_OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY() +{ + osg::notify(osg::NOTICE)<<"OverlayNode::init() - OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY"<removeChildren(0, _camera->getNumChildren()); - _camera->addChild(node); + if (_camera.valid()) + { + _camera->removeChildren(0, _camera->getNumChildren()); + _camera->addChild(node); + } dirtyOverlayTexture(); } @@ -296,12 +363,12 @@ void OverlayNode::dirtyOverlayTexture() void OverlayNode::setOverlayClearColor(const osg::Vec4& color) { - _camera->setClearColor(color); + if (_camera.valid()) _camera->setClearColor(color); } -const osg::Vec4& OverlayNode::getOverlayClearColor() const +osg::Vec4 OverlayNode::getOverlayClearColor() const { - return _camera->getClearColor(); + return _camera.valid() ? _camera->getClearColor() : osg::Vec4(1.0f,1.0f,1.0f,1.0f); } @@ -316,7 +383,7 @@ void OverlayNode::setOverlayTextureUnit(unsigned int unit) { _textureUnit = unit; - _texgenNode->setTextureUnit(_textureUnit); + if (_texgenNode.valid()) _texgenNode->setTextureUnit(_textureUnit); updateMainSubgraphStateSet(); } @@ -327,12 +394,14 @@ void OverlayNode::setOverlayTextureSizeHint(unsigned int size) _textureSizeHint = size; //_texture->dirtyTextureObject(); - _texture->setTextureSize(_textureSizeHint, _textureSizeHint); - _camera->setViewport(0,0,_textureSizeHint,_textureSizeHint); + if (_texture.valid()) _texture->setTextureSize(_textureSizeHint, _textureSizeHint); + if (_camera.valid()) _camera->setViewport(0,0,_textureSizeHint,_textureSizeHint); } void OverlayNode::updateMainSubgraphStateSet() { + if (!_mainSubgraphStateSet) return; + _mainSubgraphStateSet->clear(); _mainSubgraphStateSet->setTextureAttributeAndModes(_textureUnit, _texture.get(), osg::StateAttribute::ON); _mainSubgraphStateSet->setTextureMode(_textureUnit, GL_TEXTURE_GEN_S, osg::StateAttribute::ON);