From 3edb8a3d186733cf3f5775c45f852b80e0e90272 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 12 Jul 2002 10:30:27 +0000 Subject: [PATCH] Added blend color to osg::TexEnv --- include/osg/TexEnv | 17 ++++++++++++++--- src/osg/TexEnv.cpp | 15 +++++---------- src/osgPlugins/osg/TexEnv.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/include/osg/TexEnv b/include/osg/TexEnv index 1e91ae5ff..b98f0e5d7 100644 --- a/include/osg/TexEnv +++ b/include/osg/TexEnv @@ -7,6 +7,7 @@ #include #include +#include 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; }; } diff --git a/src/osg/TexEnv.cpp b/src/osg/TexEnv.cpp index ed079552b..28a1082f4 100644 --- a/src/osg/TexEnv.cpp +++ b/src/osg/TexEnv.cpp @@ -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()); + } } diff --git a/src/osgPlugins/osg/TexEnv.cpp b/src/osgPlugins/osg/TexEnv.cpp index 4eaed2cfc..aa042899b 100644 --- a/src/osgPlugins/osg/TexEnv.cpp +++ b/src/osgPlugins/osg/TexEnv.cpp @@ -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(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; }