diff --git a/include/osg/State b/include/osg/State index b5731531c..352895522 100644 --- a/include/osg/State +++ b/include/osg/State @@ -75,10 +75,23 @@ class SG_EXPORT State : public Referenced void apply(); /** mode has been set externally, update state to reflect this setting.*/ - void have_applied(const StateAttribute::GLMode mode,const StateAttribute::GLModeValue value); + void have_applied_mode(const StateAttribute::GLMode mode,const StateAttribute::GLModeValue value); + /** 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 have_applied_mode(const StateAttribute::GLMode mode); + /** attribute has been applied externally, update state to reflect this setting.*/ - void have_applied(const StateAttribute* attribute); + void have_applied_attribute(const StateAttribute* attribute); + + /** 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 + * then use the have_applied(attribute) method as this will the osg::State to + * track the current state more accuratly and enable lazy state updating such + * that only changed state will be applied.*/ + void have_applied_attribute(const StateAttribute::Type type); /** Set the current OpenGL context uniqueID. diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 649d6ec8a..388e129c1 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -512,7 +512,7 @@ void State::apply() } /** mode has been set externally, update state to reflect this setting.*/ -void State::have_applied(const StateAttribute::GLMode mode,const StateAttribute::GLModeValue value) +void State::have_applied_mode(const StateAttribute::GLMode mode,const StateAttribute::GLModeValue value) { ModeStack& ms = _modeMap[mode]; @@ -522,8 +522,21 @@ void State::have_applied(const StateAttribute::GLMode mode,const StateAttribute: ms.changed = true; } +/** mode has been set externally, update state to reflect this setting.*/ +void State::have_applied_mode(const StateAttribute::GLMode mode) +{ + ModeStack& ms = _modeMap[mode]; + + // don't know what last applied value is can't apply it. + // assume that it has changed by toggle the value of last_applied_value. + ms.last_applied_value = !ms.last_applied_value; + + // will need to disable this mode on next apply so set it to changed. + ms.changed = true; +} + /** attribute has been applied externally, update state to reflect this setting.*/ -void State::have_applied(const StateAttribute* attribute) +void State::have_applied_attribute(const StateAttribute* attribute) { if (attribute) { @@ -536,3 +549,17 @@ void State::have_applied(const StateAttribute* attribute) } } +void State::have_applied_attribute(const StateAttribute::Type type) +{ + + AttributeMap::iterator itr = _attributeMap.find(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. + as.changed = true; + } +} diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index dd7116865..b67ab90b5 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -565,7 +565,7 @@ void Texture::copyTexImage2D(State& state, int x, int y, int width, int height ) // cout<<"copyTexImage2D x="<