Added blend color to osg::TexEnv

This commit is contained in:
Robert Osfield 2002-07-12 10:30:27 +00:00
parent 0d84d3ed15
commit 3edb8a3d18
3 changed files with 45 additions and 13 deletions

View File

@ -7,6 +7,7 @@
#include <osg/GL>
#include <osg/StateAttribute>
#include <osg/Vec4>
namespace osg {
@ -20,7 +21,8 @@ class SG_EXPORT TexEnv : public StateAttribute
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
TexEnv(const TexEnv& texenv,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(texenv,copyop),
_mode(texenv._mode) {}
_mode(texenv._mode),
_color(texenv._color) {}
META_StateAttribute(osg, TexEnv, TEXENV);
@ -36,6 +38,7 @@ class SG_EXPORT TexEnv : public StateAttribute
// compare each paramter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_mode)
COMPARE_StateAttribute_Parameter(_color)
return 0; // passed all the above comparison macro's, must be equal.
}
@ -47,17 +50,25 @@ class SG_EXPORT TexEnv : public StateAttribute
REPLACE = GL_REPLACE
};
void setMode( const Mode mode );
void setMode( const Mode mode ) { _mode = mode; }
const Mode getMode() const { return _mode; }
void setColor( const Vec4& color ) { _color = color; }
Vec4& getColor() { return _color; }
const Vec4& getColor() const { return _color; }
virtual void apply(State& state) const;
protected :
virtual ~TexEnv( void );
Mode _mode;
Mode _mode;
osg::Vec4 _color;
};
}

View File

@ -5,6 +5,7 @@ using namespace osg;
TexEnv::TexEnv()
{
_mode = MODULATE;
_color.set(0.0f,0.0f,0.0f,0.0f);
}
@ -12,17 +13,11 @@ TexEnv::~TexEnv()
{
}
void TexEnv::setMode( const Mode mode )
{
_mode = (mode == DECAL ||
mode == MODULATE ||
mode == BLEND ||
mode == REPLACE ) ?
mode : MODULATE;
}
void TexEnv::apply(State&) const
{
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, _mode);
if (_mode==TexEnv::BLEND)
{
glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, _color.ptr());
}
}

View File

@ -38,6 +38,20 @@ bool TexEnv_readLocalData(Object& obj, Input& fr)
iteratorAdvanced = true;
}
if (fr.matchSequence("color %f %f %f %f"))
{
osg::Vec4 color;
fr[1].getFloat(color[0]);
fr[2].getFloat(color[1]);
fr[3].getFloat(color[2]);
fr[4].getFloat(color[3]);
texenv.setColor(color);
fr+=5;
iteratorAdvanced = true;
}
return iteratorAdvanced;
}
@ -46,6 +60,18 @@ bool TexEnv_writeLocalData(const Object& obj, Output& fw)
const TexEnv& texenv = static_cast<const TexEnv&>(obj);
fw.indent() << "mode " << TexEnv_getModeStr(texenv.getMode()) << std::endl;
switch(texenv.getMode())
{
case(TexEnv::DECAL):
case(TexEnv::MODULATE):
case(TexEnv::REPLACE):
break;
case(TexEnv::BLEND):
default:
fw.indent() << "color " << texenv.getColor() << std::endl;
break;
}
return true;
}