diff --git a/include/osg/State b/include/osg/State index 6c23bf7b3..b7e87b609 100644 --- a/include/osg/State +++ b/include/osg/State @@ -104,14 +104,6 @@ class SG_EXPORT State : public Referenced /** Get the camera */ inline const Camera* getCamera() const { return _camera.get(); } - - - /** Set the hint to OpenGL routines to do fine grained OpenGL error checking.*/ - void setFineGrainedErrorDetection(const bool flag) { _fineGrainedErrorDetection = flag; } - - /** Get the hint to OpenGL routines to do fine grained OpenGL error checking.*/ - const bool getFineGrainedErrorDetection() const { return _fineGrainedErrorDetection; } - private: unsigned int _contextID; @@ -126,10 +118,12 @@ class SG_EXPORT State : public Referenced { changed = false; last_applied_value = false; + global_default_value = false; } bool changed; bool last_applied_value; + bool global_default_value; ValueVec valueVec; }; @@ -143,11 +137,13 @@ class SG_EXPORT State : public Referenced { changed = false; last_applied_attribute = 0L; + global_default_attribute = 0L; } - + /** apply an attribute if required, passing in attribute and appropriate attribute stack */ bool changed; const StateAttribute* last_applied_attribute; + StateAttribute* global_default_attribute; AttributeVec attributeVec; }; @@ -172,6 +168,8 @@ class SG_EXPORT State : public Referenced { if (as.last_applied_attribute != attribute) { + if (!as.global_default_attribute) as.global_default_attribute = dynamic_cast(attribute->clone()); + as.last_applied_attribute = attribute; attribute->apply(*this); return true; @@ -180,6 +178,18 @@ class SG_EXPORT State : public Referenced return false; } + inline const bool apply_global_default_attribute(AttributeStack& as) + { + if (as.last_applied_attribute != as.global_default_attribute) + { + as.last_applied_attribute = as.global_default_attribute; + if (as.global_default_attribute) as.global_default_attribute->apply(*this); + return true; + } + else + return false; + } + typedef std::map ModeMap; typedef std::map AttributeMap; typedef std::vector > StateSetStack; @@ -189,9 +199,6 @@ class SG_EXPORT State : public Referenced AttributeMap _attributeMap; StateSetStack _drawStateStack; - - bool _fineGrainedErrorDetection; - }; }; diff --git a/src/osg/State.cpp b/src/osg/State.cpp index c401a4866..8535e2cb8 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -8,7 +8,6 @@ using namespace osg; State::State() { _contextID = 0; - _fineGrainedErrorDetection = true; } State::~State() @@ -17,8 +16,34 @@ State::~State() void State::reset() { +/* + for(ModeMap::iterator mitr=_modeMap.begin(); + mitr!=_modeMap.end(); + ++mitr) + { + ModeStack& ms = mitr->second; + ms.valueVec.clear(); + ms.last_applied_value = !ms.global_default_value; + ms.changed = true; + } +*/ + _modeMap.clear(); - _attributeMap.clear(); + _modeMap[GL_DEPTH_TEST].global_default_value = true; + + // go through all active StateAttribute's, applying where appropriate. + for(AttributeMap::iterator aitr=_attributeMap.begin(); + aitr!=_attributeMap.end(); + ++aitr) + { + AttributeStack& as = aitr->second; + as.attributeVec.clear(); + as.last_applied_attribute = NULL; + as.changed = true; + } + +// _attributeMap.clear(); + _drawStateStack.clear(); } @@ -172,7 +197,7 @@ void State::apply(const StateSet* dstate) else { // assume default of disabled. - apply_mode(this_mitr->first,false,ms); + apply_mode(this_mitr->first,ms.global_default_value,ms); } @@ -249,7 +274,7 @@ void State::apply(const StateSet* dstate) else { // assume default of disabled. - apply_mode(this_mitr->first,false,ms); + apply_mode(this_mitr->first,ms.global_default_value,ms); } @@ -297,9 +322,7 @@ void State::apply(const StateSet* dstate) } else { - // this is really an error state, in theory we *should* have a - // global state attribute set for all types. - //notify(WARN)<<" No global StateAttribute set for type"<<(int)aitr->first<first<first,false,ms); + apply_mode(mitr->first,ms.global_default_value,ms); } } @@ -449,9 +470,7 @@ void State::apply() } else { - // this is really an error state, in theory we *should* have a - // global state attribute set for all types. - //notify(WARN)<<" No global StateAttribute set for type"<<(int)aitr->first<setColorMode(Material::AMBIENT_AND_DIFFUSE); + setAttributeAndModes(material,StateAttribute::ON); +/* setMode(GL_LIGHTING,StateAttribute::OFF); setMode(GL_FOG,StateAttribute::OFF); setMode(GL_POINT_SMOOTH,StateAttribute::OFF); @@ -103,8 +111,8 @@ void StateSet::setGlobalDefaults() setAttributeAndModes(new PolygonMode,StateAttribute::OFF); setAttributeAndModes(new Transparency,StateAttribute::OFF); - setAttributeAndModes(new Depth,StateAttribute::ON); +*/ } diff --git a/src/osgGLUT/Viewer.cpp b/src/osgGLUT/Viewer.cpp index 13c061733..28c371844 100644 --- a/src/osgGLUT/Viewer.cpp +++ b/src/osgGLUT/Viewer.cpp @@ -572,10 +572,13 @@ void displaytext(int x, int y, char *s) void Viewer::showStats() { + static GLfloat tmax=100; glViewport(0,0,ww,wh); float vh = wh; + //glPushAttrib (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_STENCIL_BUFFER_BIT); + glDisable( GL_DEPTH_TEST ); // to see the stats always glDisable( GL_ALPHA_TEST ); glDisable( GL_LIGHTING ); @@ -811,6 +814,9 @@ void Viewer::showStats() glMatrixMode( GL_PROJECTION ); glPopMatrix(); + + //glPopAttrib (); + } void Viewer::display()