From 7ac71b939f5023cea0bf4832e7787847b878b5e7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 29 Sep 2005 10:22:06 +0000 Subject: [PATCH] Added setOverlayClearColor and setTexEnvMode and automatic set up of TexEnv. --- include/osgSim/OverlayNode | 24 +++++++++++++++++++++ src/osgSim/OverlayNode.cpp | 44 ++++++++++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/include/osgSim/OverlayNode b/include/osgSim/OverlayNode index 3e452e047..c6c1fab8b 100644 --- a/include/osgSim/OverlayNode +++ b/include/osgSim/OverlayNode @@ -45,6 +45,7 @@ class OSGSIM_EXPORT OverlayNode : public osg::Group /** Get the const overlay subgraph which will be render to texture.*/ const osg::Node* getOverlaySubgraph() const { return _overlaySubgraph.get(); } + /** Inform the OverlayNode that the overlay texture needs to be updated.*/ void dirtyOverlayTexture(); @@ -54,6 +55,19 @@ class OSGSIM_EXPORT OverlayNode : public osg::Group /** Get whether the OverlayNode should update the overlay texture on every frame.*/ bool getContinousUpdate() const { return _continousUpdate; } + + /** Set the clear color to use when rendering the overlay subgraph.*/ + void setOverlayClearColor(const osg::Vec4& color); + + /** Get the clear color to use when rendering the overlay subgraph.*/ + 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); + + /** Get the TexEnv mode used to combine the overlay texture with the base color/texture of the OverlayNode's decorate subgraph.*/ + GLenum getTexEnvMode() { return _texEnvMode; } + /** Set the texture unit that the texture should be assigned to.*/ void setOverlayTextureUnit(unsigned int unit); @@ -66,11 +80,20 @@ class OSGSIM_EXPORT OverlayNode : public osg::Group /** Get the texture size hint.*/ unsigned int getOverlayTextureSizeHint() const { return _textureSizeHint; } + + /** Get the camera used to implement the render to texture of the overlay subgraph.*/ + osg::CameraNode* getCamera() { return _camera.get(); } + + /** Get the const camera used to implement the render to texture of the overlay subgraph.*/ + const osg::CameraNode* getCamera() const { return _camera.get(); } + protected : virtual ~OverlayNode() {} void init(); + + void updateMainSubgraphStateSet(); typedef osg::buffered_value< int > TextureObjectValidList; @@ -88,6 +111,7 @@ class OSGSIM_EXPORT OverlayNode : public osg::Group osg::ref_ptr _mainSubgraphStateSet; // texture to render to, and to read from. + GLenum _texEnvMode; unsigned int _textureUnit; unsigned int _textureSizeHint; osg::ref_ptr _texture; diff --git a/src/osgSim/OverlayNode.cpp b/src/osgSim/OverlayNode.cpp index f40f1eb24..929677cd7 100644 --- a/src/osgSim/OverlayNode.cpp +++ b/src/osgSim/OverlayNode.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -21,6 +22,7 @@ using namespace osgSim; OverlayNode::OverlayNode(): + _texEnvMode(GL_DECAL), _textureUnit(1), _textureSizeHint(1024), _continousUpdate(false) @@ -31,6 +33,7 @@ OverlayNode::OverlayNode(): OverlayNode::OverlayNode(const OverlayNode& copy, const osg::CopyOp& copyop): Group(copy,copyop), _overlaySubgraph(copy._overlaySubgraph), + _texEnvMode(copy._texEnvMode), _textureUnit(copy._textureUnit), _textureSizeHint(copy._textureSizeHint), _continousUpdate(copy._continousUpdate) @@ -61,7 +64,7 @@ void OverlayNode::init() if (!_camera) { // create the camera - _camera = new osg::CameraNode; + _camera = new osg::CameraNode; _camera->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,0.0f)); @@ -248,18 +251,31 @@ void OverlayNode::dirtyOverlayTexture() _textureObjectValidList.setAllElementsTo(0); } +void OverlayNode::setOverlayClearColor(const osg::Vec4& color) +{ + _camera->setClearColor(color); +} + +const osg::Vec4& OverlayNode::getOverlayClearColor() const +{ + return _camera->getClearColor(); +} + + +void OverlayNode::setTexEnvMode(GLenum mode) +{ + _texEnvMode = mode; + updateMainSubgraphStateSet(); +} + + void OverlayNode::setOverlayTextureUnit(unsigned int unit) { _textureUnit = unit; _texgenNode->setTextureUnit(_textureUnit); - _mainSubgraphStateSet->clear(); - _mainSubgraphStateSet->setTextureAttributeAndModes(_textureUnit, _texture.get(), osg::StateAttribute::ON); - _mainSubgraphStateSet->setTextureMode(_textureUnit, GL_TEXTURE_GEN_S, osg::StateAttribute::ON); - _mainSubgraphStateSet->setTextureMode(_textureUnit, GL_TEXTURE_GEN_T, osg::StateAttribute::ON); - _mainSubgraphStateSet->setTextureMode(_textureUnit, GL_TEXTURE_GEN_R, osg::StateAttribute::ON); - _mainSubgraphStateSet->setTextureMode(_textureUnit, GL_TEXTURE_GEN_Q, osg::StateAttribute::ON); + updateMainSubgraphStateSet(); } void OverlayNode::setOverlayTextureSizeHint(unsigned int size) @@ -272,3 +288,17 @@ void OverlayNode::setOverlayTextureSizeHint(unsigned int size) _camera->setViewport(0,0,_textureSizeHint,_textureSizeHint); } +void OverlayNode::updateMainSubgraphStateSet() +{ + _mainSubgraphStateSet->clear(); + _mainSubgraphStateSet->setTextureAttributeAndModes(_textureUnit, _texture.get(), osg::StateAttribute::ON); + _mainSubgraphStateSet->setTextureMode(_textureUnit, GL_TEXTURE_GEN_S, osg::StateAttribute::ON); + _mainSubgraphStateSet->setTextureMode(_textureUnit, GL_TEXTURE_GEN_T, osg::StateAttribute::ON); + _mainSubgraphStateSet->setTextureMode(_textureUnit, GL_TEXTURE_GEN_R, osg::StateAttribute::ON); + _mainSubgraphStateSet->setTextureMode(_textureUnit, GL_TEXTURE_GEN_Q, osg::StateAttribute::ON); + + if (_texEnvMode!=GL_NONE) + { + _mainSubgraphStateSet->setTextureAttribute(_textureUnit, new osg::TexEnv((osg::TexEnv::Mode)_texEnvMode)); + } +}