Added support for automatic creation of global StateAttributes to osg::State,
these global attributes are created by cloning any attributes which are applied during rendering, the clone in a shallow copy, which will set up default valus for that attribute. This should prevent attribute bleed from one stateset to the next when the global StateSet doesn't contain an attribute used within the scene graph.
This commit is contained in:
parent
f27c006e28
commit
59077fed15
@ -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<StateAttribute*>(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<StateAttribute::GLMode,ModeStack> ModeMap;
|
||||
typedef std::map<StateAttribute::Type,AttributeStack> AttributeMap;
|
||||
typedef std::vector<ref_ptr<const StateSet> > StateSetStack;
|
||||
@ -189,9 +199,6 @@ class SG_EXPORT State : public Referenced
|
||||
AttributeMap _attributeMap;
|
||||
StateSetStack _drawStateStack;
|
||||
|
||||
|
||||
bool _fineGrainedErrorDetection;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -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<<endl;
|
||||
apply_global_default_attribute(as);
|
||||
}
|
||||
}
|
||||
|
||||
@ -372,9 +395,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<<endl;
|
||||
apply_global_default_attribute(as);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -427,7 +448,7 @@ void State::apply()
|
||||
else
|
||||
{
|
||||
// assume default of disabled.
|
||||
apply_mode(mitr->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<<endl;
|
||||
apply_global_default_attribute(as);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -82,6 +82,14 @@ void StateSet::setGlobalDefaults()
|
||||
|
||||
setRendingBinToInherit();
|
||||
|
||||
|
||||
setAttributeAndModes(new AlphaFunc,StateAttribute::OFF);
|
||||
setAttributeAndModes(new Transparency,StateAttribute::OFF);
|
||||
|
||||
Material *material = new Material;
|
||||
material->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);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user