diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index 5c4883b85..00c6aaea2 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -424,6 +424,10 @@ SOURCE=..\..\src\osg\TexEnvCombine.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osg\TexEnvFilter.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osg\TexGen.cpp # End Source File # Begin Source File @@ -869,6 +873,10 @@ SOURCE=..\..\Include\Osg\TexEnvCombine # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\TexEnvFilter +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\TexGen # End Source File # Begin Source File diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index c2e367f8b..035faa1a0 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -136,6 +136,7 @@ class SG_EXPORT StateAttribute : public Object POLYGONSTIPPLE, SHADEMODEL, TEXENV, + TEXENVFILTER, TEXGEN, TEXMAT, LIGHTMODEL, diff --git a/include/osg/TexEnvFilter b/include/osg/TexEnvFilter new file mode 100644 index 000000000..4db5fee39 --- /dev/null +++ b/include/osg/TexEnvFilter @@ -0,0 +1,70 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSG_TEXENVFILTER +#define OSG_TEXENVFILTER 1 + +#include +#include + +namespace osg { + +#ifndef GL_EXT_texture_lod_bias +#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD +#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 +#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 +#endif + +/** TexEnvFilter - encapsulates the OpenGL glTexEnv (GL_TEXTURE_FILTER_CONTROL) state.*/ +class SG_EXPORT TexEnvFilter : public StateAttribute +{ + public: + TexEnvFilter(float lodBias = 0.0f); + + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ + TexEnvFilter(const TexEnvFilter& texenv,const CopyOp& copyop=CopyOp::SHALLOW_COPY): + StateAttribute(texenv,copyop), + _lodBias(texenv._lodBias) {} + + META_StateAttribute(osg, TexEnvFilter, TEXENVFILTER); + + virtual bool isTextureAttribute() const { return true; } + + /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ + virtual int compare(const StateAttribute& sa) const + { + // check the types are equal and then create the rhs variable + // used by the COMPARE_StateAttribute_Paramter macro's below. + COMPARE_StateAttribute_Types(TexEnvFilter, sa) + + // compare each paramter in turn against the rhs. + COMPARE_StateAttribute_Parameter(_lodBias) + + return 0; // passed all the above comparison macro's, must be equal. + } + + void setLodBias( float lodBias ) { _lodBias = lodBias; } + + float getLodBias() const { return _lodBias; } + + virtual void apply(State& state) const; + + protected: + virtual ~TexEnvFilter(); + + float _lodBias; +}; + +} + +#endif diff --git a/src/osg/GNUmakefile b/src/osg/GNUmakefile index 535e5fa6e..001561158 100644 --- a/src/osg/GNUmakefile +++ b/src/osg/GNUmakefile @@ -85,6 +85,7 @@ CXXFILES =\ Switch.cpp\ TexEnv.cpp\ TexEnvCombine.cpp\ + TexEnvFilter.cpp\ TexGen.cpp\ TexGenNode.cpp\ TexMat.cpp\ diff --git a/src/osg/TexEnvFilter.cpp b/src/osg/TexEnvFilter.cpp new file mode 100644 index 000000000..44003500a --- /dev/null +++ b/src/osg/TexEnvFilter.cpp @@ -0,0 +1,38 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ +#include +#include + +using namespace osg; + +TexEnvFilter::TexEnvFilter(float lodBias) : + _lodBias(lodBias) +{ +} + + +TexEnvFilter::~TexEnvFilter() +{ +} + +void TexEnvFilter::apply(State&) const +{ + // note from RO, need to adapt to do testing per graphics context. + static float glVersion = atof( (const char *)glGetString( GL_VERSION ) ); + static bool s_isTexLodBias = glVersion>=1.4 || isGLExtensionSupported("GL_EXT_texture_lod_bias"); + + if (s_isTexLodBias) + { + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, _lodBias); + } +} diff --git a/src/osgGA/StateSetManipulator.cpp b/src/osgGA/StateSetManipulator.cpp index 91fac11db..2627a0079 100644 --- a/src/osgGA/StateSetManipulator.cpp +++ b/src/osgGA/StateSetManipulator.cpp @@ -7,6 +7,12 @@ #include #include + +// #define COMPILE_TEXENVFILTER_USAGE +#if COMPILE_TEXENVFILTER_USAGE + #include +#endif + using namespace osg; using namespace osgGA; @@ -111,6 +117,21 @@ bool StateSetManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa) } } break; +#if COMPILE_TEXENVFILTER_USAGE + case 'm' : + { + osg::TexEnvFilter* texenvfilter = dynamic_cast(_drawState->getTextureAttribute(0,osg::StateAttribute::TEXENVFILTER)); + if (!texenvfilter) + { + texenvfilter = new osg::TexEnvFilter; + _drawState->setTextureAttribute(0,texenvfilter); + } + + // cycle through the available modes. + texenvfilter->setLodBias(texenvfilter->getLodBias()+0.1); + } + break; +#endif } } return false;