Refactored handling of StateAttiribute's that override the StateAttiribute::getMember() so that when they change their Member value they update the StateSet parents that own them to keep the StateSet's maps coherent.

This commit is contained in:
Robert Osfield
2016-06-25 12:24:19 +01:00
parent f74eaae665
commit 949aca196d
13 changed files with 105 additions and 105 deletions

View File

@@ -26,6 +26,15 @@ BlendEquationi::~BlendEquationi()
{
}
void BlendEquationi::setIndex(unsigned int buf)
{
if (_index==buf) return;
ReassignToParents needToReassingToParentsWhenMemberValueChanges(this);
_index = buf;
}
void BlendEquationi::apply(State& state) const
{
const GLExtensions* extensions = state.get<GLExtensions>();

View File

@@ -26,6 +26,15 @@ BlendFunci::~BlendFunci()
{
}
void BlendFunci::setIndex(unsigned int buf)
{
if (_index==buf) return;
ReassignToParents needToReassingToParentsWhenMemberValueChanges(this);
_index = buf;
}
void BlendFunci::apply(State& state) const
{
const GLExtensions* extensions = state.get<GLExtensions>();

View File

@@ -48,6 +48,15 @@ BufferIndexBinding::~BufferIndexBinding()
{
}
void BufferIndexBinding::setIndex(unsigned int index)
{
if (_index==index) return;
ReassignToParents needToReassingToParentsWhenMemberValueChanges(this);
_index = index;
}
void BufferIndexBinding::apply(State& state) const
{
if (_bufferObject.valid())

View File

@@ -31,41 +31,9 @@ void ClipPlane::setClipPlaneNum(unsigned int num)
{
if (_clipPlaneNum==num) return;
if (_parents.empty())
{
_clipPlaneNum = num;
return;
}
ReassignToParents needToReassingToParentsWhenMemberValueChanges(this);
// take a reference to this clip plane to prevent it from going out of scope
// when we remove it temporarily from its parents.
osg::ref_ptr<ClipPlane> clipPlaneRef = this;
// copy the parents as they _parents list will be changed by the subsequent removeAttributes.
ParentList parents = _parents;
// remove this attribute from its parents as its position is being changed
// and would no longer be valid.
ParentList::iterator itr;
for(itr = parents.begin();
itr != parents.end();
++itr)
{
osg::StateSet* stateset = *itr;
stateset->removeAttribute(this);
}
// assign the clip plane number
_clipPlaneNum = num;
// add this attribute back into its original parents with its new position
for(itr = parents.begin();
itr != parents.end();
++itr)
{
osg::StateSet* stateset = *itr;
stateset->setAttribute(this);
}
}
unsigned int ClipPlane::getClipPlaneNum() const

View File

@@ -25,6 +25,15 @@ ColorMaski::~ColorMaski()
{
}
void ColorMaski::setIndex(unsigned int buf)
{
if (_index==buf) return;
ReassignToParents needToReassingToParentsWhenMemberValueChanges(this);
_index = buf;
}
void ColorMaski::apply(State& state) const
{
const GLExtensions* extensions = state.get<GLExtensions>();

View File

@@ -27,40 +27,8 @@ void Hint::setTarget(GLenum target)
{
if (_target==target) return;
if (_parents.empty())
{
_target = target;
return;
}
ReassignToParents needToReassingToParentsWhenMemberValueChanges(this);
// take a reference to this clip plane to prevent it from going out of scope
// when we remove it temporarily from its parents.
osg::ref_ptr<Hint> hintRef = this;
// copy the parents as they _parents list will be changed by the subsequent removeAttributes.
ParentList parents = _parents;
// remove this attribute from its parents as its position is being changed
// and would no longer be valid.
ParentList::iterator itr;
for(itr = parents.begin();
itr != parents.end();
++itr)
{
osg::StateSet* stateset = *itr;
stateset->removeAttribute(this);
}
// assign the hint target
_target = target;
// add this attribute back into its original parents with its new position
for(itr = parents.begin();
itr != parents.end();
++itr)
{
osg::StateSet* stateset = *itr;
stateset->setAttribute(this);
}
}

View File

@@ -62,41 +62,9 @@ void Light::setLightNum(int num)
{
if (_lightnum==num) return;
if (_parents.empty())
{
_lightnum = num;
return;
}
ReassignToParents needToReassingToParentsWhenMemberValueChanges(this);
// take a reference to this clip plane to prevent it from going out of scope
// when we remove it temporarily from its parents.
osg::ref_ptr<Light> lightRef = this;
// copy the parents as they _parents list will be changed by the subsequent removeAttributes.
ParentList parents = _parents;
// remove this attribute from its parents as its position is being changed
// and would no longer be valid.
ParentList::iterator itr;
for(itr = parents.begin();
itr != parents.end();
++itr)
{
osg::StateSet* stateset = *itr;
stateset->removeAttribute(this);
}
// assign the hint target
_lightnum = num;
// add this attribute back into its original parents with its new position
for(itr = parents.begin();
itr != parents.end();
++itr)
{
osg::StateSet* stateset = *itr;
stateset->setAttribute(this);
}
}
void Light::captureLightState()

View File

@@ -91,3 +91,41 @@ void StateAttribute::setEventCallback(StateAttributeCallback* ec)
}
}
}
StateAttribute::ReassignToParents::ReassignToParents(osg::StateAttribute* attr)
{
if (!attr->isTextureAttribute() && !attr->getParents().empty())
{
// take a reference to this clip plane to prevent it from going out of scope
// when we remove it temporarily from its parents.
attribute = attr;
// copy the parents as they _parents list will be changed by the subsequent removeAttributes.
parents = attr->getParents();
// remove this attribute from its parents as its position is being changed
// and would no longer be valid.
for(ParentList::iterator itr = parents.begin();
itr != parents.end();
++itr)
{
osg::StateSet* stateset = *itr;
stateset->removeAttribute(attr);
OSG_NOTICE<<" Removed from parent "<<stateset<<std::endl;
}
}
}
StateAttribute::ReassignToParents::~ReassignToParents()
{
// add attribute back into its original parents with its new position
for(ParentList::iterator itr = parents.begin();
itr != parents.end();
++itr)
{
osg::StateSet* stateset = *itr;
stateset->setAttribute(attribute.get());
OSG_NOTICE<<" Added back to parent "<<stateset<<std::endl;
}
}