Added the ability to set the global stateset, as use this RenderStageLighting

This commit is contained in:
Robert Osfield 2004-08-07 09:42:19 +00:00
parent 2754f46c5d
commit 857d8e2435
2 changed files with 59 additions and 2 deletions

View File

@ -153,6 +153,18 @@ class SG_EXPORT State : public Referenced
void apply();
inline void setGlobalDefaultModeValue(StateAttribute::GLMode mode,bool enabled)
{
ModeStack& ms = _modeMap[mode];
ms.global_default_value = enabled;
}
inline bool getGlobalDefaultModeValue(StateAttribute::GLMode mode)
{
return _modeMap[mode].global_default_value;
}
/** Apply an OpenGL mode if required. */
inline bool applyMode(StateAttribute::GLMode mode,bool enabled)
{
@ -161,6 +173,20 @@ class SG_EXPORT State : public Referenced
return applyMode(mode,enabled,ms);
}
inline void setGlobalDefaultTextureModeValue(unsigned int unit, StateAttribute::GLMode mode,bool enabled)
{
ModeMap& modeMap = getOrCreateTextureModeMap(unit);
ModeStack& ms = modeMap[mode];
ms.global_default_value = enabled;
}
inline bool getGlobalDefaultTextureModeValue(unsigned int unit, StateAttribute::GLMode mode)
{
ModeMap& modeMap = getOrCreateTextureModeMap(unit);
ModeStack& ms = modeMap[mode];
return ms.global_default_value;
}
inline bool applyTextureMode(unsigned int unit, StateAttribute::GLMode mode,bool enabled)
{
if (setActiveTextureUnit(unit))
@ -174,6 +200,18 @@ class SG_EXPORT State : public Referenced
return false;
}
inline void setGlobalDefaultAttribute(const StateAttribute* attribute)
{
AttributeStack& as = _attributeMap[attribute->getType()];
as.global_default_attribute = attribute;
}
inline const StateAttribute* getGlobalDefaultAttribute(StateAttribute::Type type)
{
AttributeStack& as = _attributeMap[type];
return as.global_default_attribute.get();
}
/** Apply an attribute if required. */
inline bool applyAttribute(const StateAttribute* attribute)
{
@ -182,6 +220,21 @@ class SG_EXPORT State : public Referenced
return applyAttribute(attribute,as);
}
inline void setGlobalDefaultTextureAttribute(unsigned int unit, const StateAttribute* attribute)
{
AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
AttributeStack& as = attributeMap[attribute->getType()];
as.global_default_attribute = attribute;
}
inline const StateAttribute* getGlobalDefaultTextureAttribute(unsigned int unit, StateAttribute::Type type)
{
AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
AttributeStack& as = attributeMap[type];
return as.global_default_attribute.get();
}
inline bool applyTextureAttribute(unsigned int unit, const StateAttribute* attribute)
{
if (setActiveTextureUnit(unit))
@ -676,7 +729,7 @@ class SG_EXPORT State : public Referenced
/** apply an attribute if required, passing in attribute and appropriate attribute stack */
bool changed;
const StateAttribute* last_applied_attribute;
ref_ptr<StateAttribute> global_default_attribute;
ref_ptr<const StateAttribute> global_default_attribute;
AttributeVec attributeVec;
};

View File

@ -53,7 +53,9 @@ void RenderStageLighting::draw(osg::State& state,RenderLeaf*& previous)
// tell state about.
state.haveAppliedAttribute(litr->first.get());
// set this state as a global default
state.setGlobalDefaultAttribute(litr->first.get());
}
for(TexUnitAttrMatrixListMap::iterator titr=_texAttrListMap.begin();
@ -76,6 +78,8 @@ void RenderStageLighting::draw(osg::State& state,RenderLeaf*& previous)
// tell state about.
state.haveAppliedTextureAttribute(titr->first, litr->first.get());
// set this state as a global default
state.setGlobalDefaultTextureAttribute(titr->first, litr->first.get());
}
}