Added setOverlayClearColor and setTexEnvMode and automatic set up of TexEnv.

This commit is contained in:
Robert Osfield
2005-09-29 10:22:06 +00:00
parent 76058f747c
commit 7ac71b939f
2 changed files with 61 additions and 7 deletions

View File

@@ -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<osg::StateSet> _mainSubgraphStateSet;
// texture to render to, and to read from.
GLenum _texEnvMode;
unsigned int _textureUnit;
unsigned int _textureSizeHint;
osg::ref_ptr<osg::Texture2D> _texture;

View File

@@ -13,6 +13,7 @@
#include <osg/Texture2D>
#include <osg/CoordinateSystemNode>
#include <osg/TexEnv>
#include <osg/io_utils>
#include <osgUtil/CullVisitor>
@@ -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));
}
}