From 2268246fa9e32eca7ae738000df8f5df5e130398 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 23 Jul 2002 14:35:38 +0000 Subject: [PATCH] Added mode checking into StateSet to try and catch non texture OpenGL modes which have been applied to the texture modes and visa-versa. --- src/osg/StateSet.cpp | 125 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 8 deletions(-) diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 6c7879240..c68ea929f 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -12,8 +12,48 @@ #include #include +#include + +#include +#include + using namespace osg; +// local class to help porting from OSG0.8.x to 0.9.x +class TextureGLModeSet +{ + + public: + + TextureGLModeSet() + { + + _textureModeSet.insert(GL_TEXTURE_1D); + _textureModeSet.insert(GL_TEXTURE_2D); + _textureModeSet.insert(GL_TEXTURE_3D); + + _textureModeSet.insert(GL_TEXTURE_CUBE_MAP); + + _textureModeSet.insert(GL_TEXTURE_GEN_Q); + _textureModeSet.insert(GL_TEXTURE_GEN_R); + _textureModeSet.insert(GL_TEXTURE_GEN_S); + _textureModeSet.insert(GL_TEXTURE_GEN_T); + } + + bool isTextureMode(StateAttribute::GLMode mode) const + { + return _textureModeSet.find(mode)!=_textureModeSet.end(); + } + + protected: + + std::set _textureModeSet; + +}; + +TextureGLModeSet s_textureGLModeSet; + + StateSet::StateSet() { setDataVariance(osg::StateAttribute::STATIC); @@ -445,17 +485,51 @@ void StateSet::merge(const StateSet& rhs) void StateSet::setMode(const StateAttribute::GLMode mode, const StateAttribute::GLModeValue value) { - setMode(_modeList,mode,value); + if (!s_textureGLModeSet.isTextureMode(mode)) + { + setMode(_modeList,mode,value); + } + else + { + notify(NOTICE)<<"Warning: texture mode '"<className()<<"'passed to setAttribute(attr,value), "<className()<<"' passed to setAttributeAndModes(attr,value), "<=_textureModeList.size()) return; - setModeToInherit(_textureModeList[unit],mode); + if (s_textureGLModeSet.isTextureMode(mode)) + { + if (unit>=_textureModeList.size()) return; + setModeToInherit(_textureModeList[unit],mode); + } + else + { + notify(NOTICE)<<"Warning: non-texture mode '"<=_textureModeList.size()) return StateAttribute::INHERIT; - return getMode(_textureModeList[unit],mode); + if (s_textureGLModeSet.isTextureMode(mode)) + { + if (unit>=_textureModeList.size()) return StateAttribute::INHERIT; + return getMode(_textureModeList[unit],mode); + } + else + { + notify(NOTICE)<<"Warning: non-texture mode '"<