diff --git a/include/osg/Math b/include/osg/Math index 20301ee4a..39e4ba2b3 100644 --- a/include/osg/Math +++ b/include/osg/Math @@ -73,6 +73,12 @@ const double PI_4 = 0.78539816339744830962; template inline T clampTo(T v,T minimum,T maximum) { return vmaximum?maximum:v; } +template +inline T clampAbove(T v,T minimum) { return v +inline T clampBelow(T v,T maximum) { return v>maximum?maximum:v; } + template inline T sign(T v) { return v<0?-1:1; } diff --git a/include/osg/State b/include/osg/State index 426f4a213..880e535f1 100644 --- a/include/osg/State +++ b/include/osg/State @@ -53,20 +53,6 @@ class SG_EXPORT State : public Referenced /** reset the state object to an empty stack.*/ void reset(); - - /** apply an OpenGL mode if required. */ - inline const bool applyMode(const StateAttribute::GLMode mode,const bool enabled) - { - return applyMode(mode,enabled,_modeMap[mode]); - } - - - /** apply an attribute if required. */ - inline const bool applyAttribute(const StateAttribute* attribute) - { - return applyAttribute(attribute,_attributeMap[attribute->getType()]); - } - inline void applyProjectionMatrix(const osg::Matrix* matrix) { if (_projection!=matrix) @@ -117,23 +103,39 @@ class SG_EXPORT State : public Referenced ClippingVolume getClippingVolume() const; - /** apply stateset.*/ + + /** Apply stateset.*/ void apply(const StateSet* dstate); - /** apply the state.*/ + /** Apply the state.*/ void apply(); + + + /** Apply an OpenGL mode if required. */ + inline const bool applyMode(const StateAttribute::GLMode mode,const bool enabled) + { + return applyMode(mode,enabled,_modeMap[mode]); + } + + + /** Apply an attribute if required. */ + inline const bool applyAttribute(const StateAttribute* attribute) + { + return applyAttribute(attribute,_attributeMap[attribute->getType()]); + } + - /** mode has been set externally, update state to reflect this setting.*/ + /** Mode has been set externally, update state to reflect this setting.*/ void haveAppliedMode(const StateAttribute::GLMode mode,const StateAttribute::GLModeValue value); - /** mode has been set externally, therefore dirty the associated mode in osg::State + /** Mode has been set externally, therefore dirty the associated mode in osg::State * so it is applied on next call to osg::State::apply(..)*/ void haveAppliedMode(const StateAttribute::GLMode mode); - /** attribute has been applied externally, update state to reflect this setting.*/ + /** Attribute has been applied externally, update state to reflect this setting.*/ void haveAppliedAttribute(const StateAttribute* attribute); - /** attribute has been applied externally, + /** Attribute has been applied externally, * and therefore this attribute type has been dirtied * and will need to be re-appplied on next osg::State.apply(..). * note, if you have an osg::StateAttribute which you have applied externally @@ -142,6 +144,12 @@ class SG_EXPORT State : public Referenced * that only changed state will be applied.*/ void haveAppliedAttribute(const StateAttribute::Type type); + /** Get whether the current specified mode is enabled (true) or disabled (false).*/ + const bool getCurrentMode(const StateAttribute::GLMode mode) const; + + /** Get the current specified attribute, return NULL is one has not yet been applied.*/ + const StateAttribute* getCurrentAttribute(const StateAttribute::Type type) const; + /** Set the current OpenGL context uniqueID. Note, it is the application developers responsibility to diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 08abb2c57..d1f5566ea 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -563,7 +563,6 @@ void State::haveAppliedAttribute(const StateAttribute::Type type) if (itr!=_attributeMap.end()) { AttributeStack& as = itr->second; - as.last_applied_attribute = 0L; // will need to update this attribute on next apply so set it to changed. @@ -571,6 +570,35 @@ void State::haveAppliedAttribute(const StateAttribute::Type type) } } +const bool State::getCurrentMode(const StateAttribute::GLMode mode) const +{ + ModeMap::const_iterator itr = _modeMap.find(mode); + if (itr!=_modeMap.end()) + { + const ModeStack& ms = itr->second; + return ms.last_applied_value; + } + else + { + return false; + } +} + +const StateAttribute* State::getCurrentAttribute(const StateAttribute::Type type) const +{ + AttributeMap::const_iterator itr = _attributeMap.find(type); + if (itr!=_attributeMap.end()) + { + const AttributeStack& as = itr->second; + return as.last_applied_attribute; + } + else + { + return NULL; + } +} + + ClippingVolume State::getClippingVolume() const { ClippingVolume cv;