From 1c46e8c4f24c035fa558dc662a77fbc23047d642 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 7 May 2004 12:41:49 +0000 Subject: [PATCH] From Bob Kuehne, addition of support for toggling on and off GL_TEXTURE_1D, 3D, CUBE_MAP and GL_TEXTURE_RECTANGLE (small addition from R.O) --- src/osgGA/StateSetManipulator.cpp | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/osgGA/StateSetManipulator.cpp b/src/osgGA/StateSetManipulator.cpp index c9d7bf87e..994fe9dcb 100644 --- a/src/osgGA/StateSetManipulator.cpp +++ b/src/osgGA/StateSetManipulator.cpp @@ -1,6 +1,10 @@ #include #include +#include +#include +#include +#include using namespace osg; using namespace osgGA; @@ -19,7 +23,13 @@ void StateSetManipulator::setStateSet(StateSet *drawState) if(!_drawState.valid()) return; _backface = (_drawState->getMode(GL_CULL_FACE)&osg::StateAttribute::ON); _lighting =(_drawState->getMode(GL_LIGHTING)&osg::StateAttribute::ON); - _texture =(_drawState->getTextureMode(0,GL_TEXTURE_2D)&osg::StateAttribute::ON); + + unsigned int mode = osg::StateAttribute::INHERIT|osg::StateAttribute::ON; + _texture = (_drawState->getTextureMode(0,GL_TEXTURE_1D)&mode) || + (_drawState->getTextureMode(0,GL_TEXTURE_2D)&mode) || + (_drawState->getTextureMode(0,GL_TEXTURE_3D)&mode) || + (_drawState->getTextureMode(0,GL_TEXTURE_RECTANGLE)&mode) || + (_drawState->getTextureMode(0,GL_TEXTURE_CUBE_MAP)&mode); } StateSet *StateSetManipulator::getStateSet() @@ -59,12 +69,28 @@ bool StateSetManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa) break; case 't' : + { _texture = !_texture; - if (_texture) _drawState->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::INHERIT); - else _drawState->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); + +// osg::ref_ptr< osg::Texture > tex = dynamic_cast +// ( _drawState->getAttribute( osg::StateAttribute::TEXTURE ) ); +// cout << tex->numTextureUnits() << endl; + + unsigned int nunit = 8; // should actually use the _real_ num units here, but how? + unsigned int mode = osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF; + if ( _texture ) mode = osg::StateAttribute::INHERIT|osg::StateAttribute::ON; + for( unsigned int ii=0; iisetTextureMode( ii, GL_TEXTURE_1D, mode ); + _drawState->setTextureMode( ii, GL_TEXTURE_2D, mode ); + _drawState->setTextureMode( ii, GL_TEXTURE_3D, mode ); + _drawState->setTextureMode( ii, GL_TEXTURE_RECTANGLE, mode ); + _drawState->setTextureMode( ii, GL_TEXTURE_CUBE_MAP, mode); + } aa.requestRedraw(); return true; - break; + } + break; case 'w' : {